0
Create Document
One script reply has been approved by the moderators Verified
Created by adam186 584 days ago Viewed 9189 times
0
Submitted by adam186 Deno
Verified 584 days ago
1
import {
2
  Client,
3
  Databases,
4
  ID,
5
} from "https://deno.land/x/appwrite@7.0.0/mod.ts";
6

7
/**
8
 * @param document_id ID of the document to be created. Leave blank to generate a unique ID.
9
 */
10
type Appwrite = {
11
  endpoint: string;
12
  project: string;
13
  key: string;
14
  self_signed: boolean;
15
};
16
export async function main(
17
  auth: Appwrite,
18
  database_id: string,
19
  collection_id: string,
20
  document_data: Record<string | number, any>,
21
  document_id?: string,
22
  document_permissions?: string[],
23
) {
24
  const client = new Client()
25
    .setEndpoint(auth.endpoint)
26
    .setProject(auth.project)
27
    .setKey(auth.key);
28
  const db = new Databases(client);
29

30
  return await db.createDocument(
31
    database_id,
32
    collection_id,
33
    document_id || ID.unique(),
34
    document_data,
35
    document_permissions,
36
  );
37
}
38