Skip to content

Commit 280df95

Browse files
Merge pull request #2737 from appwrite/cli-generate-command
Appwrite Generate documentation and announcement
2 parents 2421101 + bc364d4 commit 280df95

File tree

6 files changed

+246
-0
lines changed

6 files changed

+246
-0
lines changed

.optimize-cache.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
"images/blog/appwrite-decoded-khushboo/khushboo-tech-interviews.png": "c54715b658aa52f4c7139e7a1398b9a0e0cb55bcc3aa3dd9101f6164e0bd3379",
222222
"images/blog/appwrite-decoded-khushboo/khushboo-with-eldad.png": "b358b6a53d2c5de662b7ddf66aeeb6886478d98c5585a5e2f7068422986cba60",
223223
"images/blog/appwrite-decoded/cover-sara.png": "03ef95d81d475dde4caae31c0b442271c8ae904f8655013a2dfe2f8878b97e44",
224+
"images/blog/appwrite-generate/cover.png": "01770d4d6124b317a5103ced1d69b791ef0ce1f1e3a47e4b5072a5fd33c4953d",
224225
"images/blog/appwrite-homepage-redesign/cover-image.png": "bc09d91c421f5967c8986eeaae6f7f001380bee686cd3371fd63a8392484647e",
225226
"images/blog/appwrite-homepage-redesign/iterations-top-part.png": "713613e719366db8d271ab58815ce5f6db476c0b6a764ce53b4884ddd483f66c",
226227
"images/blog/appwrite-homepage-redesign/new-homepage.png": "e58cdf775e1f23ab71e205e0a9d1f6a8573d6e55d673b1a6190be6a79e4e43f0",
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
layout: post
3+
title: "Introducing generate command in the Appwrite CLI: Create a type-safe SDK from your schema"
4+
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.
5+
date: 2026-02-09
6+
cover: /images/blog/appwrite-generate/cover.png
7+
timeToRead: 5
8+
author: chirag-aggarwal
9+
category: announcement
10+
featured: false
11+
callToAction: true
12+
draft: false
13+
---
14+
15+
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.
16+
17+
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.
18+
19+
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**.
20+
21+
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.
22+
23+
# One command. A project-aware SDK.
24+
25+
Run the following command in your project directory:
26+
27+
```sh
28+
appwrite generate
29+
```
30+
31+
The CLI automatically detects your project's language and generates your SDK into a `generated/appwrite/` directory.
32+
33+
# Built for teams that ship fast
34+
35+
The `appwrite generate` command is designed to keep your codebase and your schema in lockstep:
36+
37+
- **Less boilerplate:** Stop hand-writing wrappers and types for every table.
38+
- **Fewer runtime surprises:** Schema changes show up as type errors instead of production bugs.
39+
- **Faster onboarding:** New teammates can discover what's available straight from the SDK.
40+
- **Confident refactors:** Regenerate after schema updates and let the compiler tell you what needs attention.
41+
42+
# Usage
43+
44+
After generating the SDK, import it into your project and configure constants:
45+
46+
```ts
47+
import { databases } from "./generated/appwrite";
48+
```
49+
50+
Configure your SDK constants by setting the values in `./generated/appwrite/constants.ts`.
51+
52+
Then use the generated helpers to interact with your tables:
53+
54+
```ts
55+
const mydb = databases.use("test-db");
56+
const customers = mydb.use("customers");
57+
58+
// Create a row
59+
await customers.create({
60+
name: "Walter O' Brian",
61+
email: "walter@example.com",
62+
plan: "enterprise"
63+
});
64+
```
65+
66+
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.
67+
68+
# Available now
69+
70+
The `appwrite generate` command is available today in the Appwrite CLI.
71+
72+
To get started, head over to the [documentation](/docs/tooling/command-line/generate) and try it out in your next project.
73+
74+
As always, we'd love to see what you build with it.

src/routes/docs/tooling/command-line/+layout.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
{
2323
label: 'Non interactive',
2424
href: '/docs/tooling/command-line/non-interactive'
25+
},
26+
{
27+
label: 'Generate SDK',
28+
href: '/docs/tooling/command-line/generate'
2529
}
2630
]
2731
},

src/routes/docs/tooling/command-line/commands/+page.markdoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ Below is a list of the available commands in the Appwrite CLI. You can get more
3939
* `types [options] <output-directory>`
4040
* The types command generates type definitions based on your Appwrite database schema. Learn more about [type generation](/docs/products/databases/type-generation).
4141
---
42+
* `generate`
43+
* The generate command creates a type-safe SDK tailored to your project. It detects your project's language and generates typed helpers based on your database schema. Learn more about [SDK generation](/docs/tooling/command-line/generate).
44+
---
4245
{% /table %}
4346

4447
## Account commands {% #account-commands %}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
---
2+
layout: article
3+
title: Generate SDK
4+
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.
5+
---
6+
7+
{% partial file="cli-disclaimer.md" /%}
8+
9+
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.
10+
11+
# Generate SDK {% #generate-sdk %}
12+
13+
Run the following command in your project directory:
14+
15+
```sh
16+
appwrite generate
17+
```
18+
19+
The CLI automatically detects your project's language and generates the SDK to a `generated/appwrite/` directory.
20+
21+
# Options {% #options %}
22+
23+
{% table %}
24+
* Option
25+
* Description
26+
---
27+
* `-o, --output <directory>`
28+
* Output directory for generated files (default: `"generated"`)
29+
---
30+
* `-l, --language <language>`
31+
* Target language for SDK generation (supported: `typescript`)
32+
---
33+
* `--server <mode>`
34+
* Override server-side generation (`auto`|`true`|`false`) (default: `"auto"`)
35+
---
36+
* `-h, --help`
37+
* Display help for command
38+
---
39+
{% /table %}
40+
41+
# Generated files {% #generated-files %}
42+
43+
The generated SDK includes the following files:
44+
45+
{% table %}
46+
* File
47+
* Description
48+
---
49+
* `types.ts`
50+
* Type definitions based on your database schema.
51+
---
52+
* `databases.ts`
53+
* Typed database helpers for querying and mutating rows.
54+
---
55+
* `index.ts`
56+
* Entry point that exports all generated helpers.
57+
---
58+
* `constants.ts`
59+
* Configuration constants such as your project endpoint and project ID. Update these values before using the SDK.
60+
---
61+
{% /table %}
62+
63+
# Usage {% #usage %}
64+
65+
After generating the SDK, import it into your project:
66+
67+
```ts
68+
import { databases } from "./generated/appwrite";
69+
```
70+
71+
Configure your SDK constants by setting the values in `./generated/appwrite/constants.ts`.
72+
73+
Use the generated helpers to interact with your tables:
74+
75+
```ts
76+
const customers = databases.use("main").use("customers");
77+
78+
const customer = await customers.create({
79+
name: "Walter O' Brian",
80+
email: "walter@example.com"
81+
});
82+
```
83+
84+
The generated helpers provide auto-completion and type checking based on your database schema, reducing errors and improving developer experience.
85+
86+
# Examples {% #examples %}
87+
88+
The generated SDK supports all common database operations. Below are examples across different use cases.
89+
90+
## Get a row {% #get-row %}
91+
92+
```ts
93+
const customer = await customers.get("customer-id-123");
94+
```
95+
96+
## List rows with queries {% #list-rows %}
97+
98+
The `list` method accepts a typed query builder that provides auto-completion for your table's columns.
99+
100+
```ts
101+
const results = await customers.list({
102+
queries: (q) => [
103+
q.equal("name", "Walter O' Brian"),
104+
q.orderDesc("$createdAt"),
105+
q.limit(10)
106+
]
107+
});
108+
```
109+
110+
## Update a row {% #update-row %}
111+
112+
```ts
113+
await customers.update("customer-id-123", {
114+
email: "walter@scorpion.com"
115+
});
116+
```
117+
118+
## Delete a row {% #delete-row %}
119+
120+
```ts
121+
await customers.delete("customer-id-123");
122+
```
123+
124+
## Bulk operations {% #bulk-operations %}
125+
126+
Create, update, or delete multiple rows at once.
127+
128+
```ts
129+
await customers.createMany([
130+
{ name: "Walter O' Brian", email: "walter@example.com" },
131+
{ name: "Paige Dineen", email: "paige@example.com" }
132+
]);
133+
```
134+
135+
```ts
136+
await customers.updateMany(
137+
{ email: "updated@example.com" },
138+
{
139+
queries: (q) => [q.equal("name", "Walter O' Brian")]
140+
}
141+
);
142+
```
143+
144+
```ts
145+
await customers.deleteMany({
146+
queries: (q) => [q.equal("name", "Paige Dineen")]
147+
});
148+
```
149+
150+
## Permissions {% #permissions %}
151+
152+
Set row-level permissions when creating or updating rows.
153+
154+
```ts
155+
await customers.create(
156+
{ name: "Walter O' Brian", email: "walter@example.com" },
157+
{
158+
permissions: (permission, role) => [
159+
permission.read(role.any()),
160+
permission.write(role.user("user-id-123"))
161+
]
162+
}
163+
);
164+
```
111 KB
Loading

0 commit comments

Comments
 (0)