0
Create Collection
One script reply has been approved by the moderators Verified
Created by adam186 584 days ago Viewed 9043 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 collection_id ID of the collection 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_name: string,
20
  collection_id?: string,
21
  collection_permissions?: string[],
22
  collection_document_security?: boolean,
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.createCollection(
31
    database_id,
32
    collection_id || ID.unique(),
33
    collection_name,
34
    collection_permissions,
35
    collection_document_security,
36
  );
37
}
38