@active-record-ts/arel
v1.1.0
Published
ArelTS is a TypeScript library for building SQL queries in a programmatic way. Heavily based on Rails's Arel library.
Readme
@active-record-ts/arel
Relational-algebra query builder for TypeScript. A port of Rails' Arel.
Arel builds SQL ASTs and emits dialect-specific strings (Postgres, MySQL, SQLite). It does not connect to a database, validate column names, or care about schema — it produces syntactically correct SQL, nothing more.
You usually don't use it directly — @active-record-ts/active-record does. Reach for arel when you need to compose SQL that the high-level API doesn't cover.
Usage
import { Arel } from '@active-record-ts/arel';
const users = new Arel.Table('users');
const mgr = users.project(users.column('id'), users.column('name'))
.where(users.column('age').gt(18))
.order(users.column('name'));
mgr.toSql();
// SELECT "users"."id", "users"."name" FROM "users"
// WHERE "users"."age" > 18 ORDER BY "users"."name"Dialect-specific output:
import { Arel, Visitors } from '@active-record-ts/arel';
mgr.toSql(new Visitors.MySQL()); // backtick-quoted
mgr.toSql(new Visitors.PostgreSQL()); // double-quote-quoted
mgr.toSql(new Visitors.SQLite());Managers
SelectManager—SELECTqueries (viaTable#project, etc.)InsertManager—INSERTUpdateManager—UPDATEDeleteManager—DELETE
Test
bun run test:arel