model add
Define a typed entity and its repo. Requires db init first.
vsceasy model add --name user --fields "id:string!,name:string,email?:string@,active:boolean"Flags
| Flag | Type | Notes |
|---|---|---|
--name | text | Required. Model name (singular, e.g. user). |
--fields | spec | Compact field spec. Omit to use the interactive loop. |
--plural | text | Repo handle. Defaults to <Name>s. |
--collection | text | On-disk collection name. Defaults to the lowercased plural. |
Field spec
Comma-separated name:type entries with flags:
| Flag | Position | Meaning |
|---|---|---|
! | after type | primary key |
@ | after type | indexed |
? | after name | optional |
id:string! primary keyname:string requiredemail?:string@ optional + indexedrole:"admin"|"user" literal unionscore:number!@ primary key + indexedIf no ! is set, id (or the first field) becomes the primary key.
Examples
# one-shot specvsceasy model add --name user --fields "id:string!,name:string,email?:string@"
# interactive — type one field per line, blank to finishvsceasy model add --name postimport { defineEntity, db } from '../helpers/db';
export interface User { id: string; name: string; email?: string;}
export const Users = defineEntity<User>('users', { primaryKey: 'id', indexes: ['email'],});
export const UsersRepo = () => db()(Users);Use the repo anywhere after initDb ran:
await UsersRepo().insert({ id: 'u1', name: 'Jane' });const u = await UsersRepo().findById('u1');