Rat docs

Databases

A > database block declares a connection. The first unnamed block is the project's primary database, exposed at runtime as main_db. Named blocks (> database [analytics]) become their own globals: analytics_db. Providers are sqlite, postgres, and (planned) sqlserver.

SQLite (default)

settings.rat

The simplest config — zero-deploy database in a file. Set auto_migrate: true and pending migrations apply on first connection, so a fresh checkout runs without any setup ritual.

# settings.rat
> database
provider: 'sqlite'
url: 'file:./dev.db'
auto_migrate: true

Postgres

Drop-in same shape

Switch providers by changing one line. URL format is whatever Go's pgx understands — connection strings, env-var refs, all the usual shapes.

> database
provider: 'postgres'
url: 'postgres://user:pw@localhost/myapp'

Multiple databases

Name the secondary ones

An unnamed block is the default. Named blocks live alongside it — useful for splitting writes (operational) and reads (analytics, OLAP). The runtime exposes each as <name>_db.

# settings.rat
> database
provider: 'sqlite'
url: 'file:./main.db'

> database [analytics]
provider: 'postgres'
url: 'postgres://...'

# in code:
# main_db.user.add(...)
# analytics_db.event.add(...)

Next: Queries — calling main_db.<model>.<method>(...) from pages and services.