Skip to main content
Version: 1.x

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

NameDescriptionDefault
pathProject pathcurrent folder

Options

NameDescriptionDefault
--prismalocation of Prisma schema file to bootstrap from<project path>/prisma/schema.prisma
-p, --package-managerpackage manager to use: "npm", "yarn", or "pnpm"auto detect
--no-version-checkdo not check for new versions of ZenStackfalse

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

NameDescriptionDefault
pathProject pathcurrent folder

Options

NameDescriptionDefault
--schemaschema file (with extension .zmodel)./schema.zmodel
-o, --output <path>default output directory for TS/JS files generated by built-in pluginsnode_modules/.zenstack
--no-default-pluginsdo not automatically run built-in pluginsfalse
--no-compiledo not compile the output of built-in pluginsfalse
--no-version-checkdo not check for new versions of ZenStackfalse

You can also specify the ZModel schema location in the "package.json" file of your project like the following:

package.json
{
"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

NameDescriptionDefault
--debugEnable debug output. Can be toggled on the fly in the repl session with the ".debug" command.false
--tableEnable table format. Can be toggled on the fly in the repl session with the ".table" command.false
--prisma-clientPath 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

NameDescriptionDefault
--schemaschema 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:

package.json
{
"zenstack": {
"schema": "./db/schema.zmodel"
}
}

info

Get information of installed ZenStack and related packages.

zenstack info [options] [path]

Arguments

NameDescriptionDefault
pathProject pathcurrent folder
Comments
Feel free to ask questions, give feedback, or report issues.

Don't Spam


You can edit/delete your comments by going directly to the discussion, clicking on the 'comments' link below