pqb is a TypeScript-first query builder for PostgreSQL, part of the Orchid ORM ecosystem. Current stable version is 0.66.6. It focuses on providing full type safety for queries and results, with support for dynamic queries, joins, subqueries, and transactions. Compared to knex or kysely, pqb integrates tightly with Orchid ORM but can also be used standalone. The package ships its own TypeScript types and is actively maintained with weekly releases.
npm install pqbNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Connects to a PostgreSQL database, defines a 'users' table with columns, inserts a row, queries it, and uses raw SQL to get a count.
Update to `createDb({ connectionString: '...' })`.Wrap table definitions with `db(tableName, columns)`.
Replace `raw('SELECT * FROM users')` with `sql<...>'SELECT * FROM users'`.Always provide a type parameter to `sql` when used for queries: `sql<{ count: number }>`SHOW count(*) FROM users`.Update code expecting a number to handle an array of rows.
Install one: `npm install pg` or `npm install postgres`.
Run `npm install pg` to install the PostgreSQL client.
Switch to import syntax: `import { createDb } from 'pqb'`. If you must use CommonJS, upgrade to Node 22+ with `--experimental-require-module`.Await the query: `const result = await users.find(1);` then access `result.id`.
Define table via `const users = db('users', ...);` then use `users.select(...)`.