RatMinimal web framework

Queries

Every declared model gets a CRUD surface on its database global. The shape is uniform: main_db.user.add({...}), main_db.user.find({...}), main_db.user.first({...}), main_db.user.all(), main_db.user.update({...}, {...}), main_db.user.remove({...}), and main_db.user.verify(field, candidate, {...}). The same calls work from pages, services, API handlers, and Tail wrappers.

Read in > server

Resolves before the page renders

Query calls in > server run during the snapshot pass, so the result lands as a regular value in scope. Pair it with a loop to render lists with no handler wiring.

> server
users: main_db.user.all()

> page
<ul>
    [u] in users
        <li> [u.name] - [u.email]

Write from a handler

Round-trip through __ratCall

Mutations inside event handlers fire over the call endpoint, run server-side, and patch the reactive spans. Pass a literal object whose field names match the model's fields.

> page
draft_name: ''

<input value[draft_name] on_input[draft_name << event.target.value]>
<button on_click[main_db.user.add({name: draft_name})]> add user

Single-record fetch

first(where) returns null if missing

Use first(where) for single-row lookups. A miss returns null, so guard with (user is not null) before reading fields off it.

# pages/users/[id].rat
> server
user: main_db.user.first({id: args.id})

> page
(user is not null)
    <h1> [user.name]
(else)
    <h1> Not found

See also Models · Databases · API files