ZenStack CLI Reference
Usage
zenstack [options] [command]
ζ ZenStack is a Prisma power pack for building full-stack apps.
Documentation: https://zenstack.dev.
Options:
-v --version display CLI version
-h, --help display help for command
Commands:
info [path] Get information of installed ZenStack and related packages.
init [options] [path] Initialize an existing project for ZenStack.
generate [options] Generates RESTful API and Typescript client for your data model.
repl [options] Start a REPL session.
format [options] Format a ZenStack schema file.
help [command] Display help for a command.
Sub Commands
init
Initializes an existing project to use ZenStack.
zenstack init [options] [path]
Arguments
Name | Description | Default |
---|---|---|
path | Project path | current folder |
Options
Name | Description | Default |
---|---|---|
--prisma | location of Prisma schema file to bootstrap from | <project path>/prisma/schema.prisma |
-p, --package-manager | package manager to use: "npm", "yarn", or "pnpm" | auto detect |
--no-version-check | do not check for new versions of ZenStack | false |
Examples
Initialize current folder with default settings.
npx zenstack init
Initialize "myapp" folder with custom package manager and schema location.
npx zenstack init -p pnpm --prisma prisma/my.schema myapp
generate
Generates Prisma schema and other artifacts as specified by "plugin"s in ZModel.
zenstack generate [options]
Arguments
Name | Description | Default |
---|---|---|
path | Project path | current folder |
Options
Name | Description | Default |
---|---|---|
--schema | schema file (with extension .zmodel) | ./schema.zmodel |
-o, --output <path> | default output directory for TS/JS files generated by built-in plugins | node_modules/.zenstack |
--no-default-plugins | do not automatically run built-in plugins | false |
--no-compile | do not compile the output of built-in plugins | false |
--no-version-check | do not check for new versions of ZenStack | false |
You can also specify the ZModel schema location in the "package.json" file of your project like the following:
{
"zenstack": {
"schema": "./db/schema.zmodel"
}
}
Examples
Generate with default settings.
npx zenstack generate
Generate with custom schema location.
npx zenstack generate --schema src/my.zmodel
repl
Starts a REPL session. You should run the command inside the package where you ran zenstack generate
.
npx zenstack repl
You can call PrismaClient methods interactively in the REPL session. The following variables are available in the REPL session.
-
prisma
The original PrismaClient instance (without ZenStack enhancement).
-
db
The ZenStack enhanced PrismaClient instance.
You don't need to await
the Prisma method call result. The REPL session will automatically await and print the result.
Options
Name | Description | Default |
---|---|---|
--debug | Enable debug output. Can be toggled on the fly in the repl session with the ".debug" command. | false |
--table | Enable table format. Can be toggled on the fly in the repl session with the ".table" command. | false |
--prisma-client | Path to load PrismaClient module. | "./node_modules/.prisma/client" |
Repl Commands
You can use the following commands in the REPL session.
-
.debug [on|off]
Toggle debug output.
-
.table [on|off]
Toggle table format.
-
.auth [user object]
Set current user. E.g.:
.auth { id: 1 }
. Run the command without argument to reset to anonymous user.
Examples
Start the session:
npx zenstack repl
Inside the session:
> prisma.user.findMany()
[
{
id: '7aa301d2-7a29-4e1e-a041-822913a3ea78',
createdAt: 2023-09-05T04:04:43.793Z,
updatedAt: 2023-09-05T04:04:43.793Z,
email: 'yiming@whimslab.io',
...
}
]
> .auth { id: '7aa301d2-7a29-4e1e-a041-822913a3ea78' }
Auth user: { id: '7aa301d2-7a29-4e1e-a041-822913a3ea78' }. Use ".auth" to switch to anonymous.
> .table
Table output: true
> db.list.findMany({select: { title: true, private: true}})
┌─────────┬────────────────────────────────────────────────────┬─────────┐
│ (index) │ title │ private │
├─────────┼────────────────────────────────────────────────────┼─────────┤
│ 0 │ 'L1' │ false │
│ 1 │ 'Wonderful new world' │ false │
│ 2 │ 'Model for a space in which users can collaborate' │ false │
└─────────┴────────────────────────────────────────────────────┴─────────┘
format
Format a ZenStack schema file.
zenstack format [options]
Options
Name | Description | Default |
---|---|---|
--schema | schema file (with extension .zmodel) | ./schema.zmodel |
You can also specify the ZModel schema location in the "package.json" file of your project like the following:
{
"zenstack": {
"schema": "./db/schema.zmodel"
}
}
info
Get information of installed ZenStack and related packages.
zenstack info [options] [path]
Arguments
Name | Description | Default |
---|---|---|
path | Project path | current folder |