Quick Start
UQL is a type-safe TypeScript ORM whose queries are plain JSON, so the same query works on the server, in the browser, micro-services, and over the network.
1. Install
Section titled “1. Install”Install the core and your preferred driver:
npm install uql-orm pg # or mysql2, better-sqlite3, mongodb, etc.bun add uql-orm# Bun has native SQL drivers built-in via `bun:sql`, no external drivers requiredpnpm add uql-orm pg # or mysql2, better-sqlite3, mongodb, etc.2. Complete Example
Section titled “2. Complete Example”Here is a complete example of defining an entity, setting up a pool, and running a query.
import { v7 as uuidv7 } from 'uuid';import { Entity, Id, Field } from 'uql-orm';
@Entity()export class User { @Id({ type: 'uuid', onInsert: uuidv7 }) id?: string;
@Field({ type: String, unique: true }) email?: string;
@Field({ type: String }) name?: string;}
// uql.config.tsimport type { Config } from 'uql-orm';import { PgQuerierPool } from 'uql-orm/postgres';import { User } from './entities.js';
const pool = new PgQuerierPool({ host: 'localhost', user: 'postgres', password: 'password', database: 'uql_app'});
export default { pool, entities: [User] } satisfies Config;export { pool };
// app.tsimport { pool } from './uql.config.js';import { User } from './entities.js';
// A single operation goes straight on the pool: it acquires a connection, runs, and releases it.await pool.insertMany(User, [ { email: 'ada@uql-orm.dev', name: 'Ada' }, { email: 'alan@uql-orm.dev', name: 'Alan' }, { email: 'grace@example.com', name: 'Grace' },]);
// Same for reads.const users = await pool.findMany(User, { $select: { id: true, name: true }, $where: { email: { $endsWith: '@uql-orm.dev' } }, $limit: 10,});
console.log(users); // -> Ada and Alan; Grace's email doesn't matchEvery operation lives on both the pool and the querier. A pool call is one unit of work on its own connection; pool.withQuerier (or pool.transaction when it must be all-or-nothing) pins one connection across several. See pool vs. querier.
Next Steps
Section titled “Next Steps”- Define Entities: Explore all decorators and type abstractions.
- Define Relations: One-to-one, one-to-many, and many-to-many mappings.
- Querying: Deep selection, filtering, and sorting.
- Transactions: Automatic and manual transaction patterns.
- Migrations: Schema evolution with the CLI and Drift Detection.