Generators
Generator commands scaffold boilerplate files so you can focus on implementation rather than file structure. All generators are prefixed with make:.
make:migration
Generate a new migration file with up() and down() stubs.
bunx d1-eloquent make:migration <name>Output: src/database/migrations/<timestamp>_<name>.ts
Example:
bunx d1-eloquent make:migration create_posts_tableGenerated file (src/database/migrations/20240115_000000_create_posts_table.ts):
import type { TMigration } from '@orphnet/d1-eloquent/cli'
import { Schema } from '@orphnet/d1-eloquent/cli'
const migration: TMigration = {
name: '20240115_000000_create_posts_table',
// description: 'Purpose of this migration',
up: (schema: Schema) => {
// schema.createTable('posts', (t) => {
// t.id()
// t.timestamps()
// })
},
down: (schema: Schema) => {
// schema.dropTable('posts')
},
}
export default migrationmake:model
Generate a model class that extends BaseModel with a typed attributes interface.
bunx d1-eloquent make:model <Name>Output: src/app/models/<Name>.ts
Example:
bunx d1-eloquent make:model PostGenerated file (src/app/models/Post.ts):
import { BaseModel } from '@orphnet/d1-eloquent'
export type TPostAttrs = {
id: string
// add fields
created_at: string
updated_at: string
}
export class Post extends BaseModel<TPostAttrs> {
public static table = 'posts'
public static primaryKey = 'id'
public static softDeletes = false
// public static revisions = { enabled: true, mode: 'diff+after', includeRequestId: true }
}make:seeder
Generate a seeder class with a run(db) method stub.
bunx d1-eloquent make:seeder <Name>Output: src/database/seeders/<Name>.ts
Example:
bunx d1-eloquent make:seeder PostSeederGenerated file (src/database/seeders/PostSeeder.ts):
import type { TSeeder, TSeederOpts } from '@orphnet/d1-eloquent/cli'
// import { PostFactory } from '../factories/PostFactory'
const seeder: TSeeder = {
name: 'PostSeeder',
// description: 'Purpose of this seeder',
run: async (opts: TSeederOpts): Promise<void> => {
// const factory = new PostFactory()
// await factory.createMany(opts, 10)
},
}
export default seederFor usage patterns — including combining seeders with factories — see Seeders & Factories.
make:factory
Generate a factory class with a definition() method that returns partial model attributes.
bunx d1-eloquent make:factory <Name>Output: src/database/factories/<Name>.ts
Example:
bunx d1-eloquent make:factory PostFactoryGenerated file (src/database/factories/PostFactory.ts):
import { Factory } from '@orphnet/d1-eloquent'
export type TPostAttrs = {
id: string
// add fields
created_at: string
updated_at: string
}
export class PostFactory extends Factory<TPostAttrs> {
public readonly table = 'posts'
public definition(): TPostAttrs {
const ts = new Date().toISOString()
return {
id: crypto.randomUUID(),
// define defaults
created_at: ts,
updated_at: ts,
}
}
}For usage patterns — including overrides and bulk creation — see Seeders & Factories.
make:resource
Generate a model, migration, factory, and seeder in a single command.
bunx d1-eloquent make:resource <Name>Example:
bunx d1-eloquent make:resource PostExample output:
Created src/database/migrations/20240115_000000_create_posts_table.ts
Created src/app/models/Post.ts
Created src/database/factories/PostFactory.ts
Created src/database/seeders/PostSeeder.tsThis is equivalent to running make:migration create_posts_table, make:model Post, make:factory PostFactory, and make:seeder PostSeeder separately.
make:pivot
Generate a pivot table migration for a many-to-many relationship. No model or seeder is created — pivot tables are typically managed directly through the join table.
bunx d1-eloquent make:pivot <pivot_table>Output: src/database/migrations/<timestamp>_<pivot_table>.ts
The table name is used to derive foreign key column names: each underscore-separated segment is singularized to produce the FK name. For example, user_roles produces user_id and role_id.
Example:
bunx d1-eloquent make:pivot user_rolesGenerated file (src/database/migrations/20240115_000000_user_roles.ts):
import type { TMigration } from '@orphnet/d1-eloquent/cli'
import { Schema } from '@orphnet/d1-eloquent/cli'
const migration: TMigration = {
name: '20240115_000000_create_user_roles',
up: (schema: Schema) => {
schema.createTable('user_roles', (t) => {
t.text('user_id', { nullable: false })
t.text('role_id', { nullable: false })
t.primary('user_id, role_id')
t.index('user_id')
t.index('role_id')
})
},
down: (schema: Schema) => {
schema.dropTable('user_roles')
},
}
export default migrationFor usage patterns after generating, see the Seeders & Factories guide.
make:dto
Generate a typed attributes interface for a single model. Reads the model source and its corresponding migration to produce TModelAttrs (all fields) and TModelCreateAttrs (omitting auto-generated fields like id, created_at, updated_at, deleted_at).
bunx d1-eloquent make:dto <model> [--out-dir=path] [--force]Output: src/types/generated/<Model>Attrs.ts (default, override with --out-dir)
| Option | Description |
|---|---|
--out-dir=path | Output directory (default: src/types/generated) |
--force | Overwrite without prompting |
Example:
bunx d1-eloquent make:dto UserGenerated file (src/types/generated/UserAttrs.ts):
// Auto-generated by d1-eloquent make:dto
// Source model: User
export type TUserAttrs = {
id: string;
name: string;
email: string;
created_at: string;
updated_at: string;
};
export type TUserCreateAttrs = {
name: string;
email: string;
};If the file already exists, the CLI will prompt for confirmation before overwriting. Pass --force to skip the prompt.
make:types
Generate typed attributes for all models in the project, plus a barrel index.ts that re-exports everything.
bunx d1-eloquent make:types [--out-dir=path] [--force] [--json]Output: Individual <Model>Attrs.ts files + index.ts barrel in src/types/generated/ (default)
| Option | Description |
|---|---|
--out-dir=path | Output directory (default: src/types/generated) |
--force | Overwrite all without prompting |
--json | Machine-readable output |
Example:
bunx d1-eloquent make:typesExample output:
Generating types for 3 model(s)...
Created DTO: src/types/generated/UserAttrs.ts
Created DTO: src/types/generated/PostAttrs.ts
Created DTO: src/types/generated/CommentAttrs.ts
Created barrel: src/types/generated/index.ts
Done: 3 generated, 0 skippedModels that cannot be parsed are skipped with a warning. Use --json for CI integration.