# UQL > A TypeScript ORM whose queries are plain JSON values: typed to the leaf, no codegen, and one API across Postgres, CockroachDB, MySQL, SQLite, MongoDB, and the edge. Instructions for AI agents: - To know how UQL ORM works, read the skill `uql-orm` ships: https://uql-orm.dev/.well-known/agent-skills/uql-orm/SKILL.md. In a project that installed `uql-orm`, the same file is at `node_modules/uql-orm/skills/uql-orm/SKILL.md` and matches that version. - Every page below is Markdown at the URL listed. A page's HTML URL answers with the same Markdown when the request prefers `text/markdown`. - The same docs are an MCP server at https://uql-orm.dev/mcp: `search_docs`, `get_doc` and `read_skill`. - Setting up UQL and a coding agent for it in a project: the prompt in https://uql-orm.dev/ai-agents.md ## Overview - [JSON-native TypeScript ORM for Bun and Node](https://uql-orm.dev/index.md): A TypeScript ORM whose queries are plain JSON values, typed down to every field, with no codegen and one API across every SQL database, MongoDB and runtime. - [Quick Start](https://uql-orm.dev/getting-started.md): Install UQL, define an entity, and run your first query. - [Switching to UQL](https://uql-orm.dev/switching-to-uql.md): Scaffold entities from the database you already run, translate the queries you already write, and move a production system over in phases. - [Upgrade guide](https://uql-orm.dev/upgrade-guide.md): What each release asks of you, newest first, with the version and date it landed. - [Codemod](https://uql-orm.dev/codemod.md): One command that rewrites your code across the UQL breaking changes that can be made mechanically. - [AI & RAG](https://uql-orm.dev/ai-semantic-search.md): Build the retrieval step of a RAG feature with UQL, from storing embeddings to picking the context for a model. - [AI Coding Agents](https://uql-orm.dev/ai-agents.md): One prompt sets UQL up in your project for any coding agent, with the UQL skill and the docs MCP server, so it writes UQL for the version you installed. - [FAQ](https://uql-orm.dev/faq.md): Short answers to common questions about UQL, from setup to troubleshooting. ## Comparison - [Drizzle vs MikroORM vs Prisma vs TypeORM vs UQL](https://uql-orm.dev/comparison.md): Drizzle vs MikroORM vs Prisma vs TypeORM vs UQL, the same queries, relations and migrations side by side, with a feature matrix and database support. - [TypeScript ORM Benchmark](https://uql-orm.dev/benchmark.md): What Drizzle, MikroORM, Prisma, Sequelize, TypeORM and UQL each cost per request against a real PostgreSQL, and which mistakes their types catch. - [ORM Type Safety Comparison](https://uql-orm.dev/type-safety.md): Ordinary mistakes written in six TypeScript ORMs, compiled live: Drizzle vs MikroORM vs Prisma vs Sequelize vs TypeORM vs UQL. - [What survives a rename? Six TypeScript ORMs](https://uql-orm.dev/rename-safety.md): Six ORMs renamed the way your editor renames, and compiled live: which mentions follow, which the compiler catches, and which break silently. ## Entities - [Decorators](https://uql-orm.dev/entities/basic.md): Define entities with the @Entity and @Field decorators, and choose column types with the f builders. - [defineEntity](https://uql-orm.dev/entities/define-entity.md): Declare an entity as data with defineEntity, its row type derived from the fields, with no decorators. - [Runtime Entities](https://uql-orm.dev/entities/runtime.md): Define entities from data, such as a CMS content type an admin creates, and apply them to the database while the process is running. - [Relations](https://uql-orm.dev/entities/relations.md): Define one-to-one, one-to-many and many-to-many relations between UQL entities. - [Computed Fields](https://uql-orm.dev/entities/computed-fields.md): Fields the database computes, either recomputed in each query or stored as a real column. - [Soft Delete](https://uql-orm.dev/entities/soft-delete.md): Soft delete marks rows deleted instead of removing them. In UQL one field keeps them out of every query by default and lets you restore them later. - [Optimistic Locking](https://uql-orm.dev/entities/optimistic-locking.md): Guard an update with a version column, so a write against a row someone else changed throws instead of overwriting it. - [Lifecycle Hooks](https://uql-orm.dev/entities/lifecycle-hooks.md): Run your own code before and after inserts, updates, upserts, deletes and loads, per entity or for every entity. - [Triggers](https://uql-orm.dev/entities/triggers.md): Declare database triggers in the entity's triggers option, rendered for every SQL engine and kept in sync by migrations. - [Indexes](https://uql-orm.dev/entities/indexes.md): Declare single-column, composite, partial, JSON, full-text and vector indexes on your entities. - [Enum + Checks](https://uql-orm.dev/entities/enum-checks.md): Enum fields and table-level CHECK constraints, so the database enforces what the entity declares. - [Inheritance](https://uql-orm.dev/entities/inheritance.md): Declare shared fields once in a base class and inherit them in every entity. ## Queries - [Example Entities](https://uql-orm.dev/querying/models.md): The entities every query example in this section imports. - [Querier](https://uql-orm.dev/querying/querier.md): Run queries on the pool or on a querier, and get rows typed by what you selected. - [Methods Reference](https://uql-orm.dev/querying/methods.md): Every querier and pool method, what each write returns, and how upserts work. - [Deep Relations](https://uql-orm.dev/querying/relations.md): Load related entities with $populate, and filter, sort and count across relations. - [Counting](https://uql-orm.dev/querying/counting.md): Count matching rows, test existence, page with a total, and count or rank by a relation's size, on every SQL dialect and MongoDB. - [Sorting](https://uql-orm.dev/querying/sorting.md): Order rows with $sort, and choose where nulls land so the order is the same on every engine. - [Comparison Operators](https://uql-orm.dev/querying/comparison-operators.md): Filter by equality, ranges, text patterns, lists and arrays with UQL comparison operators. - [Logical Operators](https://uql-orm.dev/querying/logical-operators.md): Combine conditions with $and, $or, $not and $nor in UQL queries. - [Sub-Queries](https://uql-orm.dev/querying/sub-queries.md): Add raw SQL conditions and correlated sub-queries to $where with the sql() helper. - [Raw SQL](https://uql-orm.dev/querying/raw-sql.md): Run your own SQL with all() and run(), values bound and rows typed. - [Aggregate Queries](https://uql-orm.dev/querying/aggregate.md): Group rows and compute COUNT, SUM, AVG, MIN and MAX with HAVING, on every SQL engine and MongoDB. - [JSON / JSONB](https://uql-orm.dev/querying/json.md): Filter, update and sort by paths inside JSON columns, type-checked, on every SQL engine and MongoDB. - [Full-Text Search](https://uql-orm.dev/querying/full-text.md): Search and rank text with $text on PostgreSQL, CockroachDB, MySQL, MariaDB, SQLite and MongoDB, with one index declaration and per-column weights. - [Semantic Search](https://uql-orm.dev/querying/semantic-search.md): Reference for vector search with $vector, $near and $candidates: entity setup, operators, metrics, indexes and recall per engine. - [Transactions](https://uql-orm.dev/querying/transactions.md): Run several writes all-or-nothing, nest them as savepoints, and pick an isolation level. - [Error Handling](https://uql-orm.dev/querying/errors.md): Tell a duplicate, a missing parent or a deadlock apart with one function, on every engine. - [Row Locking](https://uql-orm.dev/querying/locking.md): Lock rows with $lock so a read-modify-write cannot lose an update, and build a work queue with SKIP LOCKED. - [Cursor Pagination](https://uql-orm.dev/querying/pagination.md): Page through rows past a cursor instead of an offset, as fast on page 10,000 as on page one, on every engine. - [Cursor Streaming](https://uql-orm.dev/querying/streaming.md): Process millions of rows in flat memory with findManyStream and the driver's own cursor. - [Query Filters](https://uql-orm.dev/querying/filters.md): Named $where fragments applied to every query of an entity, for soft-delete, multi-tenancy and row-level security. ## Advanced - [Pool](https://uql-orm.dev/pool.md): Build the connection pool every query runs on, size it, and close it. - [Migrations](https://uql-orm.dev/migrations.md): Keep your entities and your database schema in sync with the uql-migrate CLI. - [Migration builder](https://uql-orm.dev/migrations/builder.md): Write hand-made migrations once, as tables and columns, and run them on every engine. - [Multi-tenancy](https://uql-orm.dev/multi-tenancy.md): Scope every query and write to the current tenant with a security filter and a per-request context. - [Multiple Schemas](https://uql-orm.dev/multiple-schemas.md): Put entities in different schemas, or give each tenant a schema of its own, with the same entity classes. - [Serverless](https://uql-orm.dev/serverless.md): Run UQL in functions that freeze and thaw: pool placement, connection limits, and per-platform setup. - [Logging & Monitoring](https://uql-orm.dev/logging.md): Log queries, catch slow ones, and send UQL's logs to your own logger. - [Naming Strategy](https://uql-orm.dev/naming-strategy.md): Map camelCase class and property names to the table and column names your database uses. ## Databases - [Bun Native SQL](https://uql-orm.dev/bun-sql.md): Drive Bun's built-in SQL client with UQL, one pool for Postgres, MySQL, MariaDB and CockroachDB. - [Cloudflare D1](https://uql-orm.dev/cloudflare-d1.md): Run UQL on Cloudflare Workers with D1, including its limits and the transactions it does not have. - [CockroachDB](https://uql-orm.dev/cockroachdb.md): Run UQL on CockroachDB over the Postgres wire protocol, and what differs from PostgreSQL. - [MongoDB](https://uql-orm.dev/mongodb.md): Run UQL on MongoDB with the same entities and queries you use on SQL, and where the two differ. - [Microsoft SQL Server](https://uql-orm.dev/mssql.md): Run UQL on SQL Server 2017 and up with the mssql driver, and what behaves differently there. - [MySQL & MariaDB](https://uql-orm.dev/mysql.md): Run UQL on MySQL with mysql2 or on MariaDB with its own driver, and the differences between them. - [PGlite](https://uql-orm.dev/pglite.md): Run UQL on PGlite, Postgres compiled to WASM and running inside your process. - [PostgreSQL](https://uql-orm.dev/postgres.md): Run UQL on PostgreSQL with node-postgres, including RLS, streaming and Cloudflare Hyperdrive. - [SQLite](https://uql-orm.dev/sqlite.md): Run UQL on SQLite with Node's built-in node:sqlite, better-sqlite3, or bun:sqlite. - [Supabase](https://uql-orm.dev/supabase.md): Run UQL on Supabase Postgres, pick the right connection endpoint, and layer UQL security filters over RLS. - [Turso & LibSQL](https://uql-orm.dev/turso.md): Run UQL on Turso Cloud from edge runtimes, on the embedded Turso engine, or on libSQL. ## Frameworks - [HTTP (any framework)](https://uql-orm.dev/http.md): Serve your entities to a client from any framework, over HTTP, tRPC or oRPC, with one API. - [Express](https://uql-orm.dev/express.md): Query UQL from your Express routes, and optionally serve entity CRUD with one router. - [Fastify](https://uql-orm.dev/fastify.md): Query UQL from your Fastify routes, and optionally serve entity CRUD through one catch-all route. - [Hono](https://uql-orm.dev/hono.md): Query UQL from your Hono routes, and optionally mount entity CRUD with one API. - [Elysia](https://uql-orm.dev/elysia.md): Query UQL from your Elysia routes, and optionally mount entity CRUD with one API. - [NestJS](https://uql-orm.dev/nestjs.md): Use UQL in NestJS with UqlModule, an injectable querier pool, request-scoped tenant context and optional CRUD routes. - [Next.js](https://uql-orm.dev/nextjs.md): Query UQL from Next.js App Router server components, route handlers and server actions. - [React Router](https://uql-orm.dev/react-router.md): Query UQL from React Router framework mode loaders, actions, resource routes and middleware. - [Astro](https://uql-orm.dev/astro.md): Query UQL from Astro pages, server islands, actions and a catch-all API endpoint. - [TanStack Start](https://uql-orm.dev/tanstack-start.md): Query UQL from TanStack Start server functions, and optionally serve entity CRUD from a catch-all server route. - [tRPC](https://uql-orm.dev/trpc.md): Query UQL from tRPC procedures with validated inputs, scoped by tenant in one middleware. - [oRPC](https://uql-orm.dev/orpc.md): Query UQL from oRPC procedures with validated inputs, scoped by tenant in one middleware. - [Browser](https://uql-orm.dev/browser.md): Query from the browser with the same typed queries, through your API with createClientQuerier or against Postgres in the tab with PGlite. - [TanStack Query](https://uql-orm.dev/react-query.md): Use UQL queries as TanStack Query cache keys, with query options, pagination, mutations, optimistic updates and server rendering. ## Optional - [Every page](https://uql-orm.dev/llms-full.txt): the whole site in one file, comparisons and blog posts included - [In search of the fastest TypeScript ORM](https://uql-orm.dev/blog/in-search-of-the-fastest-typescript-orm.md): A SQL-generation speed benchmark across six TypeScript ORMs: Drizzle, Knex, MikroORM, Sequelize, TypeORM and UQL. Reproducible and open source. - [In search of the perfect TypeScript ORM](https://uql-orm.dev/blog/in-search-of-the-perfect-orm.md): Five things a TypeScript ORM should get right, and where Prisma, Drizzle, MikroORM and TypeORM each fall short of them. - [In search of the type-safest ORM](https://uql-orm.dev/blog/in-search-of-the-type-safest-orm.md): Reading a column your query never selected is undefined at runtime and silent at compile time. Why I resisted fixing it, and what changed my mind. - [How much memory does an ORM cost per request?](https://uql-orm.dev/blog/measuring-orm-memory.md): Weighing the heap around a query looked like an afternoon of work. First I got zero bytes on Bun, then a 19% skew from forcing a collection. - [From Mongoose to SQL: migrating MongoDB to PostgreSQL](https://uql-orm.dev/blog/mongodb-to-postgresql.md): MongoDB to PostgreSQL without a big-bang rewrite: port your Mongoose queries to UQL while still on MongoDB, then switch databases without touching them. - [Semantic search: native vector similarity in a multi-dialect ORM](https://uql-orm.dev/blog/semantic-search.md): Native vector similarity search on PostgreSQL, MariaDB, SQLite and MongoDB Atlas through one type-safe query API, with automatic index migration. - [The SQL tag: a function called without parentheses](https://uql-orm.dev/blog/sql-tag.md): How a tagged template splits SQL from its values, why that is plain JavaScript, what TypeScript adds on top, and what else changed in UQL 0.100.0. - [Standard decorators: props & cons](https://uql-orm.dev/blog/standard-decorators.md): uql-orm 0.23 moved from legacy TypeScript decorators to the TC39 standard spec: no compiler flags, no reflect-metadata, and what it cost to get there. - [Type-safe triggers in an ORM. What?](https://uql-orm.dev/blog/type-safe-triggers.md): UQL declares database triggers on the entity, checks their bodies against your entities, and renders them for PostgreSQL, MySQL, SQLite and SQL Server. Why it matters, how it works, and where it stops. - [UQL 0.105: entities as data with no classes, and columns as builders](https://uql-orm.dev/blog/uql-0-105.md): UQL 0.105 lets you declare an entity as plain data, turns every column into a builder, and types more of what a query returns. What changed, with an example for each, and how to upgrade. - [What a rename breaks: six TypeScript ORMs](https://uql-orm.dev/blog/what-a-rename-breaks.md): Renaming a field, a foreign key and a relation in Drizzle, MikroORM, Prisma, Sequelize, TypeORM and UQL. Four of the six let a stale name compile. - [What does an ORM really cost you?](https://uql-orm.dev/blog/what-orms-really-cost.md): A full PostgreSQL round trip through six TypeScript ORMs, and what each adds over hand-written driver code. The totals hide where the time goes. - [Zero dependencies: what we deleted](https://uql-orm.dev/blog/zero-dependencies.md): uql-orm installs one package, 288 kB on the wire, no runtime dependencies, every dialect included. Here is what came out to get there.