Create Collection

Script appwrite Verified

by adam186 ยท 4/17/2023

The script

Submitted by hugo989 Bun
Verified 1 day ago
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

Other submissions
  • Submitted by adam186 Deno
    Created 393 days ago
    1
    import {
    2
      Client,
    3
      Databases,
    4
      ID,
    5
    } from "https://deno.land/x/[email protected]/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