# JavaScript query builder libraries

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

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [Drizzle ORM](#drizzle-orm) | 182.3M | 36.3K | Oct 2026 | Apache-2.0 |
| [postgres](#postgres) | 145.4M | 8.8K | Nov 2026 | Unlicense |
| [kysely](#kysely) | 113.4M | 14.4K | Nov 2026 | MIT |
| [Prisma Client](#prisma-client) | 95.8M | 47.7K | Oct 2026 | Apache-2.0 |
| [@neondatabase/serverless](#neondatabase-serverless) | 28.6M | 557 | Nov 2026 | MIT |
| [knex](#knex) | 27.1M | 20.3K | Jun 2026 | MIT |
| [typeorm](#typeorm) | 26.9M | 36.7K | Nov 2026 | MIT |
| [Sequelize](#sequelize) | 15.8M | 30.4K | Mar 2026 | MIT |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[Drizzle ORM](#drizzle-orm) has the most monthly downloads in this comparison, at 182.3M.

## Capabilities

| Library | MySQL dialect | Fluent SELECT/WHERE |
| --- | --- | --- |
| [Drizzle ORM](#drizzle-orm) | Yes | Yes |
| [postgres](#postgres) | No | No |
| [kysely](#kysely) | Yes | Yes |
| [Prisma Client](#prisma-client) | Yes | No |
| [@neondatabase/serverless](#neondatabase-serverless) | No | No |
| [knex](#knex) | Yes | Yes |
| [typeorm](#typeorm) | Yes | Yes |
| [Sequelize](#sequelize) | Yes | No |

## Libraries

### Drizzle ORM

[GitHub](https://github.com/drizzle-team/drizzle-orm) · [npm](https://www.npmjs.com/package/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
- Capabilities: [From the Drizzle ORM docs](https://github.com/drizzle-team/drizzle-orm)

```sh
npm install drizzle-orm
```

**Quickstart**

```javascript
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);

```

From [README.md](https://orm.drizzle.team/docs/goodies) · [Find projects using Drizzle ORM →](https://dashboard.exa.ai/playground/search?q=drizzle-orm%20GitHub%20projects)

### postgres

[GitHub](https://github.com/porsager/postgres) · [npm](https://www.npmjs.com/package/postgres)

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
- Capabilities: [From the postgres docs](https://github.com/porsager/postgres)

```sh
npm install postgres
```

**drizzle-team/drizzle-orm** (36.3K stars)

[drizzle-team/drizzle-orm](https://github.com/drizzle-team/drizzle-orm) 

```javascript
queryObjects<T extends Row>(
		query: string,
		params: unknown[],
	): Promise<RowList<T[]>> {
		return this.client.unsafe(query, params as any[]);
	}

```

[drizzle-orm/src/postgres-js/session.ts](https://github.com/drizzle-team/drizzle-orm/blob/3bcb6a27ec1f4f1602aeeb0af2f5aec61010d72d/drizzle-orm/src/postgres-js/session.ts#L168-L173) · [More projects using postgres →](https://dashboard.exa.ai/playground/search?q=postgres%20GitHub%20projects)

**Quickstart**

```javascript
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();

```

From [README.md](https://registry.npmjs.org/postgres/4.1.1)

### kysely

[GitHub](https://github.com/kysely-org/kysely) · [npm](https://www.npmjs.com/package/kysely)

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
- Capabilities: [From the kysely docs](https://github.com/kysely-org/kysely)

**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.

**Watch out for**

- **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.

```sh
npm install kysely pg
```

**miantiao-me/Sink** (7.3K stars)

[miantiao-me/Sink](https://github.com/miantiao-me/Sink) 

```typescript
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
}

```

[server/utils/analytics-sql.ts](https://github.com/miantiao-me/Sink/blob/6718f0a5eeaddd9b0347cd18b4ff9f2de48e6fea/server/utils/analytics-sql.ts#L68-L74) · [More projects using kysely →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20applications%20using%20kysely%20for%20SQL%20query%20construction%20parameters%20and%20database%20transactions&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```typescript
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();

```

From [intro.md](https://kysely.dev/docs/intro)

### Prisma Client

[GitHub](https://github.com/prisma/orm) · [npm](https://www.npmjs.com/package/@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
- Capabilities: [From the Prisma Client docs](https://github.com/prisma/orm)

```sh
npm install @prisma/client@7.10.1
```

**Quickstart**

```typescript
import { Prisma } from "./generated/prisma/client";

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

```

From [index.ts](https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/raw-queries) · [Find projects using Prisma Client →](https://dashboard.exa.ai/playground/search?q=%40prisma/client%20GitHub%20projects)

### @neondatabase/serverless

[GitHub](https://github.com/neondatabase/serverless) · [npm](https://www.npmjs.com/package/@neondatabase/serverless)

Adapts node-postgres for serverless environments.

- Downloads / mo: 28.6M
- Stars: 557
- Last release: 1.2.1
- License: MIT
- Capabilities: [From the @neondatabase/serverless docs](https://github.com/neondatabase/serverless)

```sh
npm install @neondatabase/serverless
```

**drizzle-team/drizzle-orm** (36.3K stars)

[drizzle-team/drizzle-orm](https://github.com/drizzle-team/drizzle-orm) 

```javascript
async queryObjects(
		query: string,
		params: unknown[],
	): Promise<FullQueryResults<false>> {
		return this.clientQuery(query, params, { arrayMode: false, fullResults: true });
	}

```

[drizzle-orm/src/neon-http/session.ts](https://github.com/drizzle-team/drizzle-orm/blob/3bcb6a27ec1f4f1602aeeb0af2f5aec61010d72d/drizzle-orm/src/neon-http/session.ts#L229-L234) · [More projects using @neondatabase/serverless →](https://dashboard.exa.ai/playground/search?q=%40neondatabase/serverless%20GitHub%20projects)

**Quickstart**

```javascript
import { neon } from "@neondatabase/serverless";

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

```

From [README.md](https://registry.npmjs.org/@neondatabase%2Fserverless/1.2.1)

### knex

[GitHub](https://github.com/knex/knex) · [npm](https://www.npmjs.com/package/knex)

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
- Capabilities: [From the knex docs](https://github.com/knex/knex)

**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.

**Watch out for**

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

```sh
npm install knex
```

**Unleash/unleash** (14.3K stars)

[Unleash/unleash](https://github.com/Unleash/unleash) 

```typescript
async getFeatureTypeCounts({
        projectId,
        archived,
    }: IFeatureProjectUserParams): Promise<IFeatureTypeCount[]> {
        const query = this.db<FeaturesTable>(TABLE)
            .select('type')
            .count('type')
            .groupBy('type');

        query
            .where({
                project: projectId,
            })
            .modify(FeatureToggleStore.filterByArchived, archived);

        const result = await query;
        return result.map((row) => ({
            type: row.type!,
            count: Number(row.count),
        }));
    }

```

[src/lib/features/feature-toggle/feature-toggle-store.ts](https://github.com/Unleash/unleash/blob/63624105864a9b85a62abdbd32d25a8e0d2ac0e8/src/lib/features/feature-toggle/feature-toggle-store.ts#L265-L285) · [More projects using knex →](https://dashboard.exa.ai/playground/search?q=JavaScript%20TypeScript%20applications%20using%20knex%20for%20SQL%20query%20construction%20parameters%20and%20database%20transactions&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```typescript
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();

```

From [README.md](https://knexjs.org/guide/query-builder.html)

### typeorm

[GitHub](https://github.com/typeorm/typeorm) · [npm](https://www.npmjs.com/package/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
- Capabilities: [From the typeorm docs](https://github.com/typeorm/typeorm)

```sh
npm install typeorm pg
```

**Quickstart**

```javascript
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);

```

From [README.md](https://typeorm.io/docs/query-builder/select-query-builder) · [Find projects using typeorm →](https://dashboard.exa.ai/playground/search?q=typeorm%20GitHub%20projects)

### Sequelize

[GitHub](https://github.com/sequelize/sequelize) · [npm](https://www.npmjs.com/package/sequelize)

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
- Capabilities: [From the Sequelize docs](https://github.com/sequelize/sequelize)

```sh
npm install sequelize
```

**Chocobozzz/PeerTube** (15.4K stars)

[Chocobozzz/PeerTube](https://github.com/Chocobozzz/PeerTube) 

```javascript
function createSimilarityAttribute (col: string, value: string): Fn {
  return Sequelize.fn(
    'similarity',
    searchTrigramNormalizeCol(col),
    searchTrigramNormalizeValue(value)
  )
}

```

[server/core/models/shared/query.ts](https://github.com/Chocobozzz/PeerTube/blob/53928dd6242afb8f0d5cdd48ac20b3608342ab24/server/core/models/shared/query.ts#L27-L33) · [More projects using Sequelize →](https://dashboard.exa.ai/playground/search?q=sequelize%20GitHub%20projects)

**Quickstart**

```javascript
import { Sequelize } from "sequelize";

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

```

From [README.md](https://sequelize.org/docs/v6/core-concepts/model-querying-basics/)

## FAQ

### Which JavaScript query builder library should I use?

[Kysely](#kysely) suits TypeScript projects that want a typed fluent SQL builder without an ORM. [Knex](#knex) suits projects that need one builder across several database dialects. [Drizzle ORM](#drizzle-orm) suits projects that want typed SQL clauses with an ORM layer.

### Drizzle vs Prisma: which should I use?

[Drizzle ORM](#drizzle-orm) writes queries as typed SQL clauses against handwritten table descriptors. [Prisma Client](#prisma-client) generates a model client from a schema and keeps raw SQL to composable helpers.

### What is Knex?

[Knex](#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.

### What is TypeORM?

[TypeORM](#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 vs Drizzle: which should I use?

[Kysely](#kysely) is a typed query builder and compiler with no model layer. [Drizzle ORM](#drizzle-orm) pairs a typed query builder with ORM features such as table descriptors.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript query builder libraries Knex Kysely Slonik ts-sql-query code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
