Search documentation

Find a page in the Andurel docs.

model

andurel generate model creates or updates a model API from SQL migration history. It constructs the plural model type, entity and data structs, annotated query SQL, Fx module wiring, and an optional factory.

When to use

  • Create models/NAME.go from an existing table migration.
  • Pass --update after a migration changes columns.
  • Do not invent columns by hand; write a migration first.

Usage

1andurel generate model NAME [flags]

Flags

Flag What it does
--mode Operation mode: crud (default), read-only, or create-only
--update Update an existing model from migration changes
--yes Apply changes without prompting for confirmation
--primary-key Specify the primary key column (skips interactive detection)
--table-name Override the default table name
--skip-factory Skip generating or updating the matching factory
--dry-run / --diff Preview without writing; see generate

CRUD modes require a supported primary key. Model generation updates models.Module so Fx can supply the new plural model API.

Examples

1andurel generate model Product --dry-run --json
2andurel generate model Product
3andurel generate model Product --mode read-only
4andurel generate model Product --update --yes
5andurel generate model Product --table-name catalog_products --primary-key id

Next

1andurel sync factory Product --check --json
2andurel sync factory Product --sync --json
3andurel inspect models --json

For HTTP layers on top of an existing model, use controller or scaffold. Factory sync details live under Factories and sync.