Skip to main content
Version: 3.x

Using the CLI

ZenStack CLI is a command-line tool that takes the ZModel schema as input and complete different tasks for you. It's included in the "@zenstackhq/cli" package, and can be invoked with either zen or zenstack command (they are equivalent).

In the context of ORM, the CLI compiles ZModel into a TypeScript representation, which can in turn be used to create a type-safe ORM client.

You can try running the npx zen generate command in the following playground and inspect the TypeScript code generated inside the "zenstack" folder.

Open in StackBlitz
zenstack/schema.zmodel
// This is a sample model to get you started.

datasource db {
provider = 'sqlite'
url = "file:./dev.db"
}

/// User model
model User {
id Int @id @default(autoincrement())
email String @unique
posts Post[]
}

/// Post model
model Post {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
}

The generate command generates several TypeScript files from the ZModel schema that support both development-time typing and runtime access to the schema. For more details of the generated code, please refer to the @core/typescript plugin documentation.

info

The CLI's code generation is extensible via plugins. Please refer to the Plugin Development documentation for a comprehensive guide.

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