Models and fields
Generate a SQL table, Rust model and five CRUD endpoints from a model definition.
▶ Watch the demoOn this page
Create a model
- Press a and name the model, for example
User. - Name a field, choose its type and toggle options with Space.
- Add fields or a relationship from Model fields.
- Select Finish and generate, confirm the collection path, then Generate.
id is added automatically. Use field names such as first_name. Escape cancels before generation.
miblo add User name:string email:string:unique --yes
miblo add Product title:string price:float active:bool --yes--path /members changes the collection path. Without fields or --yes, the CLI starts its wizard.
Field types
| Type | Rust | SQLite | MySQL |
|---|---|---|---|
| string | String | TEXT | VARCHAR(255) |
| text | String | TEXT | TEXT |
| int | i64 | INTEGER | BIGINT |
| float | f64 | REAL | DOUBLE |
| bool | bool | INTEGER | BOOLEAN |
Optional fields use Option<T>. Syntax: name:type?:option, for example description:text?.
Options and private fields
| Option | Example | Behavior |
|---|---|---|
| Optional | nickname:string? | Accepts NULL. |
| Unique | email:string:unique | Adds a unique constraint. Use string, rather than text, for unique text. |
| Private | token:string:private | Accepts writes; omits the value from CRUD responses. |
Common sensitive names (password, password_hash, secret, token, api_key) become private through the CLI. This filtering does not encrypt data or add authentication.
Generated CRUD
| Method | User path | Result |
|---|---|---|
| GET | /users | Paginated list: limit and offset, at most 100 rows per page. |
| POST | /users | Create: 201. |
| GET | /users/{id} | Row or 404. |
| PATCH | /users/{id} | Update supplied fields; omitted fields remain unchanged. |
| DELETE | /users/{id} | Delete: 204; missing row: 404. |
Unknown fields and invalid types are rejected. Unique conflicts return 409. Empty PATCH requests, changing id and NULL for required fields are rejected.
Keep existing project changes
Adding a model writes its files and migration without regenerating existing resources. Registries, miblo.yaml and .miblo/state.json are updated.
--dry-run previews the plan. File collisions or managed registry conflicts stop the operation. Use miblo edit or m to add a field.