Rado documentation
Welcome. Rado is a fully typed, lightweight TypeScript query builder for
SQLite, PostgreSQL and MySQL. These docs walk you through everything from your
first select to recursive CTEs and auto-migrations.
If you're in a hurry, start with Getting started. If you're coming from Drizzle ORM, jump straight to Coming from Drizzle. Most query-building patterns carry over.
Table of contents
Start here
- Getting started: install, connect, define, query
- Drivers: connecting every supported database client
Defining your schema
- Tables:
table, column modifiers, defaults, references, aliases - SQLite column types
- PostgreSQL column types
- MySQL column types
- Universal column types: columns that work on every dialect
- Indexes & constraints: primary keys, unique, foreign keys, indexes
- Views: views and materialized views
- PostgreSQL schemas & enums:
pgSchema,pgEnum - Custom column types: map your own types
Querying
- Select: selections,
where, ordering, grouping, pagination, locking - Joins: every join flavor, including lateral
- Insert: values, bulk inserts, upserts, insert-from-select
- Update:
set,where,returning - Delete: removing rows
- Filter operators:
eq,and,or,inArrayand the rest - Aggregates:
count,sum,avg,min,max - Include: nested results without an ORM
- JSON: typed JSON columns
- Set operations:
union,intersect,except - Subqueries & CTEs:
.as(),$with, recursion - The sql tag: raw SQL, safely interpolated
Running queries
- Transactions & batch: atomicity, rollbacks, batching
- Prepared statements: placeholders,
prepare,toSQL - Migrations:
db.create,db.drop,db.migrate - Universal queries: one query, any database
Background
- Coming from Drizzle: comparison, compatibility helpers, migration notes
Conventions used in these docs
Unless noted otherwise, examples assume a connected database instance named
db and tables defined like this:
import {table} from 'rado'
import {boolean, id, integer, text} from 'rado/universal'
const User = table('user', {
id: id(),
name: text().notNull(),
email: text()
})
const Post = table('post', {
id: id(),
authorId: integer().notNull(),
title: text().notNull(),
published: boolean().default(false)
})
Most examples run identically on SQLite, PostgreSQL and MySQL. Where a feature
is dialect-specific (say, ilike or materialized views) the page says so.