1 | import { Client, Databases, ID } from "[email protected]"; |
2 |
|
3 | |
4 | * @param collection_id ID of the collection to be created. Leave blank to generate a unique ID. |
5 | */ |
6 | type Appwrite = { |
7 | endpoint: string; |
8 | project: string; |
9 | key: string; |
10 | self_signed: boolean; |
11 | }; |
12 | export async function main( |
13 | auth: Appwrite, |
14 | database_id: string, |
15 | collection_name: string, |
16 | collection_id?: string, |
17 | collection_permissions?: string[], |
18 | collection_document_security?: boolean, |
19 | ) { |
20 | const client = new Client() |
21 | .setEndpoint(auth.endpoint) |
22 | .setProject(auth.project) |
23 | .setKey(auth.key); |
24 | const db = new Databases(client); |
25 |
|
26 | return await db.createCollection( |
27 | database_id, |
28 | collection_id || ID.unique(), |
29 | collection_name, |
30 | collection_permissions, |
31 | collection_document_security, |
32 | ); |
33 | } |
34 |
|