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.
-
prismaThe original PrismaClient instance (without ZenStack enhancement).
-
dbThe 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 |