generate-model

Option Description
--fields Ask interactively for the fields
--sqlx Implement the queries with sqlx
--migration Create the SQL migration of the table
--foreign-keys Ask which table and column each field references
--unique Ask whether each field is unique
--timestamps Add created_at, updated_at, deleted_at, with soft delete
--sqlite, --postgres, --mysql Required. The target database
--openapi, --graphql Document the routes / serve the model with GraphQL
--table The table name, the snake_case model name by default
--schema <name> With --postgres, the schema of the table: the queries and the migration use app.project, the migration creates the schema if missing
--primary-key <column> The primary key column, id by default
--id-type <type> The type of the primary key, the Id of the model: i64 (by default), i32, u64 (MySQL and SQLite) or uuid (uuid::Uuid, generated by Uuid::new_v4 on insert, which needs the uuid crate and the uuid feature of sqlx)
--assigned-id The creation payload gives the primary key, which the database does not generate
--output The folder of the file (--output=src/models)
--force Overwrite an existing file
# a table keyed by a version the client gives, as `_sqlx_migrations`
octopux generate-model --name Release --fields --sqlx --primary-key version --assigned-id --postgres

# UUID ids generated on insert
octopux generate-model --name Token --fields --sqlx --migration --id-type uuid --postgres

With --sqlx, list is paginated by offset and limit, and sorted by sort and order (?sort=-created_at,title&order=asc, also the arguments of the GraphQL list query): sort accepts the primary key, the fields and the timestamps but deleted_at, the vectors, geometries and JSON values left out. add-field adds the new fields to these columns. See Filtering and sorting.

With --sqlx --postgres, a pgvector::Vector field can be computed from the text fields of the model with fastembed, and searched by meaning: see the semantic search.

Entering fields

When asked for the fields, type name:type (e.g. title:String, or stars:2 to pick from the menu). A trailing ? makes the field optional (stars:i32?), - removes the last one, and an empty name ends the input:

$ octopux generate-model --name Project --fields --sqlite
? Field 1 name › title:String
  ✔ title: String
? Field 2 name › stars:i32?
  ✔ stars: Option<i32> (nullable)
? Field 3 name ›