Skip to content

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.


Install the core and your preferred driver:

Terminal window
npm install uql-orm pg # or mysql2, better-sqlite3, mongodb, etc.

Here is a complete example of defining an entity, setting up a pool, and running a query.

entities.ts
import { Entity, Id, Field } from 'uql-orm';
@Entity()
export class User {
@Id({ type: 'uuid' })
id?: string;
@Field({ unique: true })
email?: string;
@Field()
name?: string;
}
// uql.config.ts
import 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.ts
import { pool } from './uql.config.js';
import { User } from './entities.js';
const users = await pool.transaction(async (querier) => {
return await querier.findMany(User, {
$select: { id: true, name: true },
$where: { email: { $endsWith: '@uql-orm.dev' } },
$limit: 10,
});
});
console.log(users);