Update Document

Script appwrite Verified

by adam186 ยท 4/18/2023

The script

Submitted by hugo989 Bun
Verified 1 day ago
1
import { Client, Databases, ID } from "[email protected]";
2

3
type Appwrite = {
4
  endpoint: string;
5
  project: string;
6
  key: string;
7
  self_signed: boolean;
8
};
9
export async function main(
10
  auth: Appwrite,
11
  database_id: string,
12
  collection_id: string,
13
  document_id: string,
14
  document_data?: Record<string | number, any>,
15
  document_permissions?: string[],
16
) {
17
  const client = new Client()
18
    .setEndpoint(auth.endpoint)
19
    .setProject(auth.project)
20
    .setKey(auth.key);
21
  const db = new Databases(client);
22

23
  return await db.updateDocument(
24
    database_id,
25
    collection_id,
26
    document_id,
27
    document_data,
28
    document_permissions,
29
  );
30
}
31

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
    type Appwrite = {
    8
      endpoint: string;
    9
      project: string;
    10
      key: string;
    11
      self_signed: boolean;
    12
    };
    13
    export async function main(
    14
      auth: Appwrite,
    15
      database_id: string,
    16
      collection_id: string,
    17
      document_id: string,
    18
      document_data?: Record<string | number, any>,
    19
      document_permissions?: string[],
    20
    ) {
    21
      const client = new Client()
    22
        .setEndpoint(auth.endpoint)
    23
        .setProject(auth.project)
    24
        .setKey(auth.key);
    25
      const db = new Databases(client);
    26
    
    
    27
      return await db.updateDocument(
    28
        database_id,
    29
        collection_id,
    30
        document_id,
    31
        document_data,
    32
        document_permissions,
    33
      );
    34
    }
    35