-
Notifications
You must be signed in to change notification settings - Fork 303
Appwrite Generate documentation and announcement #2737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9373758
add docs for generate command
atharvadeosthale c843878
generate command docs and announcement
atharvadeosthale c58254f
add cli options
atharvadeosthale 471e638
Merge branch 'main' into cli-generate-command
adityaoberai 778da58
address comments + cover
atharvadeosthale e96d8f0
update date
atharvadeosthale bc364d4
imports and langs
atharvadeosthale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| layout: post | ||
| title: "Introducing generate command in the Appwrite CLI: Create a type-safe SDK from your schema" | ||
| description: Generate a type-safe SDK for your Appwrite project with the new generate command in the Appwrite CLI. It reads your database schema and creates typed helpers for querying and mutating rows with autocomplete. | ||
| date: 2026-02-09 | ||
| cover: /images/blog/appwrite-generate/cover.png | ||
| timeToRead: 5 | ||
| author: chirag-aggarwal | ||
| category: announcement | ||
| featured: false | ||
| callToAction: true | ||
| draft: false | ||
| --- | ||
|
|
||
| Every database-driven app eventually ends up with the same glue code: types, table wrappers, and helper functions that make your schema feel safe to use in the editor. | ||
|
|
||
| It starts small. Then your schema changes. A column gets renamed, a new required field appears, and suddenly the "simple" query you wrote last week is a runtime bug waiting to happen. | ||
|
|
||
| To eliminate that drift, we're introducing the new `appwrite generate` command in the **Appwrite CLI**, which 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 with type checking built in. | ||
|
|
||
| # One command. A project-aware SDK. | ||
|
|
||
| Run the following command in your project directory: | ||
|
|
||
| ```sh | ||
| appwrite generate | ||
| ``` | ||
|
|
||
| The CLI automatically detects your project's language and generates your SDK into a `generated/appwrite/` directory. | ||
|
|
||
| # Built for teams that ship fast | ||
|
|
||
| The `appwrite generate` command is designed to keep your codebase and your schema in lockstep: | ||
|
|
||
| - **Less boilerplate:** Stop hand-writing wrappers and types for every table. | ||
| - **Fewer runtime surprises:** Schema changes show up as type errors instead of production bugs. | ||
| - **Faster onboarding:** New teammates can discover what's available straight from the SDK. | ||
| - **Confident refactors:** Regenerate after schema updates and let the compiler tell you what needs attention. | ||
|
|
||
| # Usage | ||
|
|
||
| After generating the SDK, import it into your project and configure constants: | ||
|
|
||
| ```ts | ||
| import { databases } from "./generated/appwrite"; | ||
| ``` | ||
|
|
||
| Configure your SDK constants by setting the values in `./generated/appwrite/constants.ts`. | ||
|
|
||
| Then use the generated helpers to interact with your tables: | ||
|
|
||
| ```ts | ||
| const mydb = databases.use("test-db"); | ||
| const customers = mydb.use("customers"); | ||
|
|
||
| // Create a row | ||
| await customers.create({ | ||
| name: "Walter O' Brian", | ||
| email: "walter@example.com", | ||
| plan: "enterprise" | ||
| }); | ||
| ``` | ||
|
|
||
| Instead of juggling stringly-typed shapes, your editor can now guide you with autocomplete and validation based on the actual schema in your Appwrite project. | ||
|
|
||
| # Available now | ||
|
|
||
| The `appwrite generate` command is available today in the Appwrite CLI. | ||
|
|
||
| To get started, head over to the [documentation](/docs/tooling/command-line/generate) and try it out in your next project. | ||
|
|
||
| As always, we'd love to see what you build with it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
src/routes/docs/tooling/command-line/generate/+page.markdoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| --- | ||
| layout: article | ||
| title: Generate SDK | ||
| description: Generate a type-safe SDK for your Appwrite project using the Command-Line Tool (CLI). Automatically create typed helpers based on your database schema. | ||
| --- | ||
|
|
||
| {% partial file="cli-disclaimer.md" /%} | ||
|
|
||
| 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 {% #generate-sdk %} | ||
|
|
||
| Run the following command in your project directory: | ||
|
|
||
| ```sh | ||
| appwrite generate | ||
| ``` | ||
|
|
||
| The CLI automatically detects your project's language and generates the SDK to a `generated/appwrite/` directory. | ||
|
|
||
| # Options {% #options %} | ||
|
|
||
| {% table %} | ||
| * Option | ||
| * Description | ||
| --- | ||
| * `-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 | ||
| --- | ||
| {% /table %} | ||
|
|
||
| # Generated files {% #generated-files %} | ||
|
|
||
| The generated SDK includes the following files: | ||
|
|
||
| {% table %} | ||
| * File | ||
| * Description | ||
| --- | ||
| * `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. | ||
| --- | ||
| {% /table %} | ||
|
|
||
| # Usage {% #usage %} | ||
|
|
||
| After generating the SDK, import it into your project: | ||
|
|
||
| ```ts | ||
| 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: | ||
|
|
||
| ```ts | ||
| 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 {% #examples %} | ||
|
|
||
| The generated SDK supports all common database operations. Below are examples across different use cases. | ||
|
|
||
| ## Get a row {% #get-row %} | ||
|
|
||
| ```ts | ||
| const customer = await customers.get("customer-id-123"); | ||
| ``` | ||
|
|
||
| ## List rows with queries {% #list-rows %} | ||
|
|
||
| The `list` method accepts a typed query builder that provides auto-completion for your table's columns. | ||
|
|
||
| ```ts | ||
| const results = await customers.list({ | ||
| queries: (q) => [ | ||
| q.equal("name", "Walter O' Brian"), | ||
| q.orderDesc("$createdAt"), | ||
| q.limit(10) | ||
| ] | ||
| }); | ||
| ``` | ||
|
|
||
| ## Update a row {% #update-row %} | ||
|
|
||
| ```ts | ||
| await customers.update("customer-id-123", { | ||
| email: "walter@scorpion.com" | ||
| }); | ||
| ``` | ||
|
|
||
| ## Delete a row {% #delete-row %} | ||
|
|
||
| ```ts | ||
| await customers.delete("customer-id-123"); | ||
| ``` | ||
|
|
||
| ## Bulk operations {% #bulk-operations %} | ||
|
|
||
| Create, update, or delete multiple rows at once. | ||
|
|
||
| ```ts | ||
| await customers.createMany([ | ||
| { name: "Walter O' Brian", email: "walter@example.com" }, | ||
| { name: "Paige Dineen", email: "paige@example.com" } | ||
| ]); | ||
| ``` | ||
|
|
||
| ```ts | ||
| await customers.updateMany( | ||
| { email: "updated@example.com" }, | ||
| { | ||
| queries: (q) => [q.equal("name", "Walter O' Brian")] | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ```ts | ||
| await customers.deleteMany({ | ||
| queries: (q) => [q.equal("name", "Paige Dineen")] | ||
| }); | ||
| ``` | ||
|
|
||
| ## Permissions {% #permissions %} | ||
|
|
||
| Set row-level permissions when creating or updating rows. | ||
|
|
||
| ```ts | ||
| 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")) | ||
| ] | ||
| } | ||
| ); | ||
| ``` | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.