Skip to content

Generate SDK

Before proceeding

Ensure you install the CLI, log in to your Appwrite account, and initialize your Appwrite project.

The generate command creates a type-safe SDK tailored to your Appwrite project. It reads your database schema and generates typed helpers, so you can interact with your tables using auto-completed methods, resulting in a better developer experience.

Generate SDK

Run the following command in your project directory:

Shell
appwrite generate

The CLI automatically detects your project's language and generates the SDK to a generated/appwrite/ directory.

Options

OptionDescription
-o, --output <directory>
Output directory for generated files (default: "generated")
-l, --language <language>
Target language for SDK generation (supported: typescript)
--server <mode>
Override server-side generation (auto|true|false) (default: "auto")
-h, --help
Display help for command

Generated files

The generated SDK includes the following files:

FileDescription
types.ts
Type definitions based on your database schema.
databases.ts
Typed database helpers for querying and mutating rows.
index.ts
Entry point that exports all generated helpers.
constants.ts
Configuration constants such as your project endpoint and project ID. Update these values before using the SDK.

Usage

After generating the SDK, import it into your project:

TypeScript
import { databases } from "./generated/appwrite";

Configure your SDK constants by setting the values in ./generated/appwrite/constants.ts.

Use the generated helpers to interact with your tables:

TypeScript
const customers = databases.use("main").use("customers");

const customer = await customers.create({
    name: "Walter O' Brian",
    email: "walter@example.com"
});

The generated helpers provide auto-completion and type checking based on your database schema, reducing errors and improving developer experience.

Examples

The generated SDK supports all common database operations. Below are examples across different use cases.

Get a row

TypeScript
const customer = await customers.get("customer-id-123");

List rows with queries

The list method accepts a typed query builder that provides auto-completion for your table's columns.

TypeScript
const results = await customers.list({
    queries: (q) => [
        q.equal("name", "Walter O' Brian"),
        q.orderDesc("$createdAt"),
        q.limit(10)
    ]
});

Update a row

TypeScript
await customers.update("customer-id-123", {
    email: "walter@scorpion.com"
});

Delete a row

TypeScript
await customers.delete("customer-id-123");

Bulk operations

Create, update, or delete multiple rows at once.

TypeScript
await customers.createMany([
    { name: "Walter O' Brian", email: "walter@example.com" },
    { name: "Paige Dineen", email: "paige@example.com" }
]);
TypeScript
await customers.updateMany(
    { email: "updated@example.com" },
    {
        queries: (q) => [q.equal("name", "Walter O' Brian")]
    }
);
TypeScript
await customers.deleteMany({
    queries: (q) => [q.equal("name", "Paige Dineen")]
});

Permissions

Set row-level permissions when creating or updating rows.

TypeScript
await customers.create(
    { name: "Walter O' Brian", email: "walter@example.com" },
    {
        permissions: (permission, role) => [
            permission.read(role.any()),
            permission.write(role.user("user-id-123"))
        ]
    }
);