Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/community-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ sidebar_label: Community Packages

ZenStack plugins built by our awesome community members :heart:.

- [zenstack-encrypt](https://github.com/genu/zenstack-encryption)

Transparent field-level encryption and decryption using the `@encrypted` attribute. Made by [@genu](https://github.com/genu).

- [zenstack-cache](https://github.com/visualbravo/zenstack-cache)

Reduce response times and database load with query-level caching integrated with the ZenStack ORM. Made by [@sanny-io](https://github.com/sanny-io).
Expand Down
2 changes: 1 addition & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sidebar_position: 100

## What databases are supported?

Currently only SQLite (with [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) or [sql.js](https://github.com/sql-js/sql.js) driver) and PostgreSQL (with [node-postgres](https://github.com/brianc/node-postgres) driver) are supported. MySQL will be added in the future. There's no plan to support other relational databases or NoSQL databases.
SQLite (with [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) or [sql.js](https://github.com/sql-js/sql.js) driver), PostgreSQL (with [node-postgres](https://github.com/brianc/node-postgres) driver or [@neondatabase/serverless](https://github.com/neondatabase/serverless)), and MySQL (with [mysql2](https://github.com/sidorares/node-mysql2) driver) are supported. There's no plan to support other relational databases or NoSQL databases.

## What JavaScript runtimes are supported?

Expand Down
28 changes: 24 additions & 4 deletions docs/migrate-prisma.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This guide will help you migrate an existing Prisma project to ZenStack v3. The
In the following sections, we'll cover various aspects of the migration process where care needs to be taken.

:::warning
ZenStack v3 currently only supports PostgreSQL and SQLite databases.
ZenStack v3 only supports PostgreSQL, MySQL, and SQLite databases.
:::

## Migration Steps
Expand All @@ -39,16 +39,19 @@ ZenStack v3 doesn't depend on Prisma at runtime. Its CLI has a peer dependency o
ZenStack doesn't bundle database drivers. Install the appropriate driver for your database:

<Tabs>

<TabItem value="postgres" label="PostgreSQL">

<PackageInstall dependencies={['pg']} devDependencies={['@types/pg']} />
</TabItem>

<TabItem value="mysql" label="MySQL">
<PackageInstall dependencies={['mysql2']} />
</TabItem>
<TabItem value="sqlite" label="SQLite">

<TabItem value="sqlite" label="SQLite">
<PackageInstall dependencies={['better-sqlite3']} devDependencies={['@types/better-sqlite3']} />

</TabItem>

</Tabs>


Expand Down Expand Up @@ -102,6 +105,23 @@ export const db = new ZenStackClient(schema, {
```
</TabItem>

<TabItem value="mysql" label={`MySQL`}>

```ts title='db.ts'
import { ZenStackClient } from '@zenstackhq/orm';
import { MysqlDialect } from '@zenstackhq/orm/dialects/mysql';
import { schema } from './zenstack/schema';
import { createPool } from 'mysql2';

export const db = new ZenStackClient(schema, {
dialect: new MysqlDialect({
pool: createPool(process.env.DATABASE_URL),
}),
});
```

</TabItem>

<TabItem value="sqlite" label={`SQLite`}>

```ts title='db.ts'
Expand Down
4 changes: 1 addition & 3 deletions docs/migrate-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ Here are a few essential items to verify before preparing your migration:

- Database support

V3 currently only supports PostgreSQL and SQLite databases. MySQL will be added later.

For PostgreSQL, only the traditional TCP-based connection is supported. Newer HTTP-based protocols, such as those supported by providers like Neon and Prisma PG, are not yet supported, but will be in the future.
V3 only supports PostgreSQL, MySQL and SQLite databases.

- Prisma feature gaps

Expand Down
2 changes: 1 addition & 1 deletion docs/modeling/datasource.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ datasource db {

</Tabs>

Currently, only PostgreSQL and SQLite are supported. MySQL will be supported in a future release. There's no plan for other relational database types or NoSQL databases.
PostgreSQL, MySQL and SQLite are supported. There's no plan for other relational database types or NoSQL databases.

<ZModelVsPSL>
ZenStack's ORM runtime doesn't rely on the `url` information to connect to the database. Instead, you provide the information when constructing an ORM client — more on this in the [ORM](../orm/) part.
Expand Down
2 changes: 1 addition & 1 deletion docs/orm/api/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ List fields allow extra filter operators to filter on the list content:
- `isEmpty`: checks if the list is empty.

:::info
List type is not supported by SQLite.
List type is only supported by PostgreSQL.
:::

```zmodel
Expand Down
2 changes: 1 addition & 1 deletion docs/orm/api/find.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ You can use the following fields to control what fields are returned in the resu

## Finding distinct rows

You can use the `distinct` field to find distinct rows based on specific fields. One row for each unique combination of the specified fields will be returned. The implementation relies on SQL `DISTINCT ON`, so it's not available for SQLite provider.
You can use the `distinct` field to find distinct rows based on specific fields. One row for each unique combination of the specified fields will be returned. The implementation relies on SQL `DISTINCT ON`, so it's not available for SQLite and MySQL provider.

```ts
// returns one Post for each unique authorId
Expand Down
18 changes: 18 additions & 0 deletions docs/orm/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ export const db = new ZenStackClient(schema, {
```
</TabItem>

<TabItem value="mysql" label={`MySQL`}>

<PackageInstall dependencies={["mysql2"]} />

```ts title='db.ts'
import { ZenStackClient } from '@zenstackhq/orm';
import { MysqlDialect } from '@zenstackhq/orm/dialects/mysql';
import { schema } from './zenstack/schema';
import { createPool } from 'mysql2';

export const db = new ZenStackClient(schema, {
dialect: new MysqlDialect({
pool: createPool(process.env.DATABASE_URL),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

process.env.DATABASE_URL is string | undefined — TypeScript will reject this.

mysql2's createPool signature is createPool(config: string | PoolOptions): Pool — it does not accept undefined. Unlike the PostgreSQL example where connectionString accepts string | undefined, passing process.env.DATABASE_URL directly here will produce a compile error for anyone copying this snippet.

✏️ Suggested fix
-        pool: createPool(process.env.DATABASE_URL),
+        pool: createPool(process.env.DATABASE_URL!),

or more defensively:

-        pool: createPool(process.env.DATABASE_URL),
+        pool: createPool(process.env.DATABASE_URL as string),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pool: createPool(process.env.DATABASE_URL),
pool: createPool(process.env.DATABASE_URL!),
Suggested change
pool: createPool(process.env.DATABASE_URL),
pool: createPool(process.env.DATABASE_URL as string),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/orm/client.md` at line 73, The snippet passes process.env.DATABASE_URL
(type string | undefined) directly to mysql2.createPool which rejects undefined;
update the code around createPool so it guarantees a string before calling
createPool — e.g., check or assert that process.env.DATABASE_URL is defined
(throw a clear error if missing) and then pass that validated string to
createPool, or provide a safe default connection string; reference the
process.env.DATABASE_URL symbol and the createPool call when making this change.

}),
});
```
</TabItem>

</Tabs>

The created `db` object has the full ORM API inferred from the type of the `schema` parameter. When necessary, you can also explicitly get the inferred client type like:
Expand Down
17 changes: 17 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,23 @@ Options:
-h, --help display help for command
```

### proxy

Start the ZenStack proxy server. This command is aliased as `studio` too.

```bash
Usage: zen proxy [options]

Options:
--schema <file> schema file (with extension .zmodel). Defaults to "zenstack/schema.zmodel" unless specified in package.json.
-p, --port <port> port to run the proxy server on (default: 2311)
-o, --output <path> output directory for `zen generate` command
-d, --databaseUrl <url> database connection URL
-l, --logLevel <level...> Query log levels (e.g., query, error)
--no-version-check do not check for new version
-h, --help Show this help message
```

## Overriding Default Options

### Default Schema Location
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/zmodel/datasource.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ datasource NAME {

- sqlite
- postgresql
- mysql

- **`url`**:

Optional. Database connection string. Either a plain string or an invocation of `env` function to fetch from an environment variable. For SQLite provider, the URL should be a file protocol, like `file:./dev.db`. For PostgreSQL provider, it should be a postgres connection string, like `postgresql://user:password@localhost:5432/dbname`.
Optional. Database connection string. Either a plain string or an invocation of `env` function to fetch from an environment variable. For SQLite provider, the URL should be a file protocol, like `file:./dev.db`. For PostgreSQL and MySQL provider, it should be a valid connection string URL, like `postgresql://user:password@localhost:5432/dbname`.

The `url` option is only used by the migration engine to connect to the database. The ORM runtime doesn't rely on it. Instead, you provide the connection information when constructing an ORM client.

Expand Down