Rat docs

Models

A model is a declarative table definition: name, fields, types, attrs. Drop the file under data/ and the loader picks it up. From there, the migration generator produces SQL and the runtime exposes a CRUD surface as main_db.<name>.<method>(...).

Declare a model

data/user.rat

Each line in the body is field_name type with optional bracketed attrs. Types map to SQL: text, number, date, bool. Attrs like [pk], [unique], [length: 256] annotate constraints.

> model [user]
    id          text [pk]
    email       text [unique]
    name        text [length: 128]
    created_at  date

Cross-file constraints

data/user_extras.rat

A > contraint [user] block (the canonical typo — both spellings work) layers extra attrs onto a model declared elsewhere. Useful when one team owns the schema and another owns indexing concerns.

# data/user_extras.rat
> contraint [user]
    email: [encrypted]
    name:  [index]

Inspect what got picked up

rat db status

The CLI lists every model the loader discovered along with its fields and attrs. Run it after edits to confirm what the loader sees — saves a round-trip through migrations to debug a typo.

rat db status

Next: Databases — declaring connections in settings.rat and what providers are supported.