Import the full power of PostgreSQL as a TypeScript library.
# Install Typegres
npm install typegres
import { typegres, Text, Int4, values, Bool } from "typegres";
const db = typegres({ type: "pglite" });
const users = values(
{ name: Text.new("Alice"), age: Int4.new(25), isActive: Bool.new(true) },
{ name: Text.new("Bob"), age: Int4.new(30), isActive: Bool.new(false) },
{ name: Text.new("Charlie"), age: Int4.new(17), isActive: Bool.new(true) }
);
const rows = await users
.select((u) => ({ upper: u.name.upper(), isAdult: u.age[">"](18) }))
.where((u) => u.isActive)
.execute(db);
console.log(rows);
// Output: [{ upper: 'ALICE', isAdult: true }, { upper: 'CHARLIE', isAdult: false }]
See the quickstart guide for more details: https://typegres.com/docs/quickstart/
✅ Autocomplete for every PG function, 100% compile-time types
Developer Preview (alpha): expect rough edges and breaking changes.
While traditional ORMs and query builders abstract over multiple SQL dialects, Typegres goes all-in on PostgreSQL to provide the most powerful and type-safe experience possible. In a single import, you can access the full power of Postgres with complete TypeScript type safety.
Focus on learning Postgres itself — Typegres just gives you autocomplete, type-checking, and all other benefits of TypeScript.
const result = await users
.select((u) => ({
firstName: u.name.regexpSubstr("[A-Z][a-z]+").upper(),
lastName: u.name.regexpSubstr("[a-z]+$").lower(),
isAdult: u.age[">"](18),
}))
.where((u) => u.isActive)
.execute(db);
// result type: Array<{ firstName: string; lastName: string; isAdult: boolean }>
UPDATE
/ INSERT
IS NULL
, AND
, OR
)src/
- Main library source codesrc/gen/
- Auto-generated PostgreSQL types and functionssite/
- Documentation website and interactive playgroundRequirements:
nix
package managerdirenv
for automatic environment setupTo contribute, clone the repository (run nix develop
if you don't have direnv
set up) and run:
# Install dependencies
npm install
# Start custom PostgreSQL instance:
./start_postgres.sh
# Run the codegen script to generate types and functions
npm run codegen
# Run tests
npm test
# Type check the code
npm run typecheck
# Build the library
npm run build
MIT © Ryan Rasti