JSPM

@marcelkloubert/appwrite-sdk

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 12
  • Score
    100M100P100Q34733F
  • License MIT

An (unofficial) enhancement for official SDK of Appwrite.

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@marcelkloubert/appwrite-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    @marcelkloubert/appwrite-sdk

    An (unofficial) enhancement for official SDK of Appwrite which runs on Node.js 18+ or later.

    Install

    Execute the following command from your project folder, where your package.json file is stored:

    npm i @marcelkloubert/appwrite-sdk

    Usage

    import { Query } from "node-appwrite";
    import { AppwriteProject } from "@marcelkloubert/appwrite-sdk";
    
    interface BarCollection {
      buzz: number;
    }
    
    // set environment variables `APPWRITE_API_KEY` and `APPWRITE_PROJECT_ID`
    // with correct values
    const project = new AppwriteProject();
    
    // initialize project and make it available
    // as a singleton instance if possible
    await project.init({ withDatabase: true });
    
    for (const database of project.databases) {
      console.log("Database:", database.name);
    
      // `database` is an iterator of collections
      for (const collection of database) {
        console.log("\tCollection:", collection.name);
    
        // `collection` is an iterator of attributes
        for (const attribute of collection) {
          console.log("\tAttribute:", attribute.name);
        }
      }
    }
    
    // get existing database `foo`
    const foo = project.databases.getDatabase("foo");
    
    // get existing collection `bar` inside `foo`
    const bar = foo.getCollection("bar").wrap<BarCollection>();
    
    // insert a new document
    const newDoc = await bar.insertOne({ buzz: 42 });
    
    // update an existing document
    const updatedDoc = await bar.updateOne(newDoc, { buzz: 666 });
    
    // remove a document
    await bar.deleteOne(updatedDoc);
    
    // query multiple documents
    const asyncCursor = bar.query({
      queries: [Query.greaterThan("$createdAt", new Date().toISOString())],
    });
    for await (const document of asyncCursor) {
      console.log("Document:", document.$id);
    }
    
    // query a single document
    const maybeExistingDoc = await bar.queryOne({
      queries: [Query.equal("buzz", 667)],
    });
    if (maybeExistingDoc) {
      console.log("Document with buzz=667 exists as:", maybeExistingDoc.$id);
    } else {
      console.log("Document with buzz=667 does not exist");
    }

    Currently supported

    The project is currently under heavy development.

    Currently the following features running have a "quite stable" beta status:

    Documentation

    The API documentation can be found here.

    License

    MIT © Marcel Joachim Kloubert

    Support and contribute

    PayPal donate button Patreon donate button Buy Me A Coffee donate button

    Contribution guidelines