CLI

Better Query comes with a built-in CLI to help you manage the database schemas, initialize your project, generate resource schemas, and gather diagnostic information about your setup.

Generate

The generate command creates the schema required by Better Query based on your resource definitions. If you're using a database adapter like Prisma or Drizzle, this command will generate the right schema for your ORM. If you're using the built-in Kysely adapter, it will generate an SQL file you can run directly on your database.

Terminal
npx better-query generate

Options

  • --output - Where to save the generated schema. For Prisma, it will be saved in prisma/schema.prisma. For Drizzle, it goes to schema.ts in your project root. For Kysely, it's an SQL file saved as schema.sql in your project root.
  • --config - The path to your Better Query config file. By default, the CLI will search for a query.ts file in ./, ./utils, ./lib, or any of these directories under the src directory.
  • --yes - Skip the confirmation prompt and generate the schema directly.

Migrate

The migrate command applies the Better Query schema directly to your database. This is available if you're using the built-in Kysely adapter. For other adapters, you'll need to apply the schema using your ORM's migration tool.

Terminal
npx better-query migrate

Options

  • --config - The path to your Better Query config file. By default, the CLI will search for a query.ts file in ./, ./utils, ./lib, or any of these directories under the src directory.
  • --yes - Skip the confirmation prompt and apply the schema directly.

Init

The init command allows you to initialize Better Query in your project.

Terminal
npx better-query init

Options

  • --name - The name of your application. (defaults to the name property in your package.json).
  • --framework - The framework your codebase is using. Currently supported frameworks include Next.js and more.
  • --plugins - The plugins you want to use. You can specify multiple plugins by separating them with a comma.
  • --database - The database you want to use. Supported databases include SQLite, PostgreSQL, and MySQL.
  • --package-manager - The package manager you want to use. Supported package managers are npm, pnpm, yarn, bun (defaults to the manager you used to initialize the CLI).
  • --with-auth - Initialize with Better Auth integration for authentication and authorization.

Info

The info command provides diagnostic information about your Better Query setup and environment. Useful for debugging and sharing when seeking support.

Terminal
npx better-query info

Output

The command displays:

  • System: OS, CPU, memory, Node.js version
  • Package Manager: Detected manager and version
  • Better Query: Version and configuration (sensitive data auto-redacted)
  • Resources: Defined resources and their schemas
  • Frameworks: Detected frameworks (Next.js, React, etc.)
  • Databases: Database clients and ORMs (Prisma, Drizzle, etc.)

Examples

# Basic usage
npx better-query info

On this page