JavaScript query builder libraries

Updated Nov 2026

JavaScript SQL query builder libraries compose SQL statements from method calls or tagged templates instead of string concatenation. A builder compiles each query into SQL text with its values passed as separate parameters. These libraries let apps and backend services build dynamic filters and joins with TypeScript types that catch a wrong column before the query runs.

Popularity

Drizzle ORM has the most monthly downloads in this comparison, at 182.3M.

LibraryMonthly downloadsStarsLast releaseLicense
Drizzle ORM
182.3M
36.3KOct 2026Apache-2.0
postgres
145.4M
8.8KNov 2026Unlicense
kysely
113.4M
14.4KNov 2026MIT
Prisma Client
95.8M
47.7KOct 2026Apache-2.0
@neondatabase/serverless
28.6M
557Nov 2026MIT
knex
27.1M
20.3KJun 2026MIT
typeorm
26.9M
36.7KNov 2026MIT
Sequelize
15.8M
30.4KMar 2026MIT
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Drizzle ORM

Provides the Drizzle ORM package for SQL databases.

Downloads / mo
182.3M
Stars
36.3K
Last release
0.45.4
License
Apache-2.0

Quickstart

From README.md
$ npm install drizzle-orm
import { QueryBuilder, pgTable, integer } from "drizzle-orm/pg-core";

const users = pgTable("users", { id: integer("id") });
const builder = new QueryBuilder();
const query = builder.select().from(users).toSQL();
console.log(query.sql, query.params);

Provides a full-featured PostgreSQL client for Node.js, Bun, and Cloudflare Workers.

Downloads / mo
145.4M
Stars
8.8K
Last release
4.1.1
License
Unlicense

Quickstart

From README.md
$ npm install postgres
import postgres from "postgres";

const sql = postgres(process.env.DATABASE_URL);
const rows = await sql`select ${1} as value`;
console.log(rows);
await sql.end();

postgres examples

From open-source projects on GitHub
queryObjects<T extends Row>(
		query: string,
		params: unknown[],
	): Promise<RowList<T[]>> {
		return this.client.unsafe(query, params as any[]);
	}

Builds SQL with TypeScript checks for visible tables, columns, and selected result types.

Downloads / mo
113.4M
Stars
14.4K
Last release
0.29.9
License
MIT

Strengths

  • Checks selected columns and types. Catch references to tables or columns outside the query scope.
  • Builds queries without database drivers. Use DummyDriver to compile SQL separately from database execution.

Limitations

  • Drivers decide runtime value types. The database interface must declare types that match the values the driver returns.
  • Conditional selections need typed branching. Use $if when selected fields depend on runtime conditions.

Quickstart

From intro.md
$ npm install kysely pg
import { Kysely, PostgresDialect } from "kysely";
import pg from "pg";

const db = new Kysely({
  dialect: new PostgresDialect({ pool: new pg.Pool() }),
});
const query = db.selectFrom("users").select("id").compile();
console.log(query.sql, query.parameters);
await db.destroy();

kysely examples

From open-source projects on GitHub
export function compileAnalyticsQuery(query: Compilable): string {
  const compiled = query.compile()
  if (compiled.parameters.length !== 0)
    throw new Error('Analytics SQL queries must not contain parameters')

  return compiled.sql
}

Prisma Client

Provides an auto-generated, type-safe ORM client for Node.js.

Downloads / mo
95.8M
Stars
47.7K
Last release
7.10.1
License
Apache-2.0

Quickstart

From index.ts
$ npm install @prisma/client@7.10.1
import { Prisma } from "./generated/prisma/client";

const query = Prisma.sql`SELECT ${1} AS value`;
console.log(query.text, query.values);

@neondatabase/serverless

Adapts node-postgres for serverless environments.

Downloads / mo
28.6M
Stars
557
Last release
1.2.1
License
MIT

Quickstart

From README.md
$ npm install @neondatabase/serverless
import { neon } from "@neondatabase/serverless";

const sql = neon(process.env.DATABASE_URL);
const rows = await sql`SELECT ${1} AS value`;
console.log(rows);

@neondatabase/serverless examples

From open-source projects on GitHub
async queryObjects(
		query: string,
		params: unknown[],
	): Promise<FullQueryResults<false>> {
		return this.clientQuery(query, params, { arrayMode: false, fullResults: true });
	}

Builds SQL queries through a composable JavaScript API across several database dialects.

Downloads / mo
27.1M
Stars
20.3K
Last release
3.3.0
License
MIT

Strengths

  • Targets several SQL dialects. Use PostgreSQL, MySQL, SQLite, or another supported backend.
  • Rolls back failed transactions. Throw from the transaction handler to roll back its queries.

Limitations

  • Mutable chains can confuse inference. Keep type-changing selections in a chain when precise result types matter.

Quickstart

From README.md
$ npm install knex
import knex from "knex";

const db = knex({ client: "pg" });
const query = db("users").select("id").where("id", 1).toSQL();
console.log(query.sql, query.bindings);
await db.destroy();

knex examples

From open-source projects on GitHub

typeorm

Maps data with a data-mapper ORM for TypeScript across MySQL, PostgreSQL, SQL Server, and other databases.

Downloads / mo
26.9M
Stars
36.7K
Last release
1.1.3
License
MIT

Quickstart

From README.md
$ npm install typeorm pg
import { DataSource } from "typeorm";

const source = new DataSource({ type: "postgres" });
const query = source.createQueryBuilder().select("u.id").from("users", "u")
  .where("u.id = :id", { id: 1 }).getQueryAndParameters();
console.log(query);

Provides a promise-based Node.js ORM for PostgreSQL, MySQL, MariaDB, SQLite, and SQL Server.

Downloads / mo
15.8M
Stars
30.4K
Last release
6.37.8
License
MIT

Quickstart

From README.md
$ npm install sequelize
import { Sequelize } from "sequelize";

const expression = Sequelize.fn("LOWER", Sequelize.col("name"));
console.log(expression);

Sequelize examples

From open-source projects on GitHub
function createSimilarityAttribute (col: string, value: string): Fn {
  return Sequelize.fn(
    'similarity',
    searchTrigramNormalizeCol(col),
    searchTrigramNormalizeValue(value)
  )
}

FAQ

Kysely suits TypeScript projects that want a typed fluent SQL builder without an ORM. Knex suits projects that need one builder across several database dialects. Drizzle ORM suits projects that want typed SQL clauses with an ORM layer.

Drizzle ORM writes queries as typed SQL clauses against handwritten table descriptors. Prisma Client generates a model client from a schema and keeps raw SQL to composable helpers.

Knex is a SQL query and schema builder for PostgreSQL, MySQL, and other databases. It compiles fluent method chains to SQL and manages connection pools.

TypeORM is a data-mapper ORM for TypeScript that supports MySQL, PostgreSQL, and other databases. Its repositories expose a query builder for SELECT statements.

Kysely is a typed query builder and compiler with no model layer. Drizzle ORM pairs a typed query builder with ORM features such as table descriptors.

For coding agents

Found your query builder library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official