CLI Reference

nanoka generate

Generates a Drizzle schema file from your Nanoka model definitions and optionally runs the full migration pipeline.

npx nanoka generate [options]

Options:

Option Argument Default Description
--config path ./nanoka.config.ts Path to nanoka.config.ts
--output path (from config) Override output file path
--no-migrate Generate schema only, skip migration steps
--apply Run drizzle-kit generate + wrangler d1 migrations apply
--db name (from config) D1 database name
--remote Apply migrations to remote D1 (passes --remote to wrangler)
--package-manager pm npx Package manager: npx / pnpm / npm / yarn / bun

Examples

# Generate Drizzle schema and run drizzle-kit generate
npx nanoka generate

# Use a custom config file path
npx nanoka generate --config ./custom/nanoka.config.ts

# Generate schema only, skip drizzle-kit and wrangler
npx nanoka generate --no-migrate

# Full pipeline: generate schema, run drizzle-kit, apply to local D1
npx nanoka generate --apply --db my-database

# Full pipeline with remote deploy using pnpm
npx nanoka generate --apply --db my-database --remote --package-manager pnpm

nanoka.config.ts

The config file is read by nanoka generate to discover models and configure the migration pipeline.

Options:

Option Type Default Description
output string ./drizzle/schema.ts Drizzle schema output file path
models Model[] required Array of Nanoka model definitions
migrate.drizzleConfig string ./drizzle.config.ts Path to drizzle.config.ts
migrate.database string D1 database name for wrangler
migrate.packageManager string npx Package manager for CLI commands
import { defineConfig } from '@nanokajs/core/config'
import { User } from './src/models/user'
import { Post } from './src/models/post'

export default defineConfig({
  output: './drizzle/schema.ts',
  models: [User, Post],
  migrate: {
    drizzleConfig: './drizzle.config.ts',
    database: 'my-database',
    packageManager: 'pnpm',
  },
})

create-nanoka-app

Scaffold a new Nanoka project with a default template.

pnpm create nanoka-app <dir>
npx create-nanoka-app <dir>

Options:

Option Argument Description
--template default Use the default template
--force Overwrite existing directory
--help Show help
--version Show version

Generated Files

Path Description
package.json Project dependencies and scripts
wrangler.jsonc Wrangler configuration with D1 binding
tsconfig.json TypeScript configuration
drizzle.config.ts Drizzle-kit configuration
nanoka.config.ts Nanoka model and migration configuration
.gitignore Standard gitignore for Node/Wrangler projects
README.md Quickstart instructions
src/index.ts Worker entry point with example routes
src/models/posts.ts Post model as a starting example

The src/models/posts.ts file defines a Post model with id, title, body, published, and createdAt fields. Edit or replace it with your own models.

Next Steps

After scaffolding, run the following commands to get your project running:

# 1. Install dependencies
pnpm install

# 2. Generate the Drizzle schema from model definitions
pnpm exec nanoka generate

# 3. Generate SQL migration files
pnpm exec drizzle-kit generate

# 4. Create the D1 database if needed
npx wrangler d1 create my-database

# 5. Apply migrations to local D1
pnpm exec wrangler d1 migrations apply my-database --local

# 6. Start the local dev server
pnpm dev