A type-safe PostgreSQL client for Node.js
Install @postgresql-typed/core
npm install --save @postgresql-typed/core
This package is build on top of drizzle-orm, which is a type-safe ORM for Node.js.
For more information on how to use this package, please refer to the drizzle-orm documentation.
Differences between drizzle-orm and @postgresql-typed/core are listed below.
import { Client, pgt, table } from "@postgresql-typed/core";
import {
defineCharacterVarying,
defineInt2,
defineUUID
} from "@postgresql-typed/core/definers";
import { eq } from "@postgresql-typed/core/operators";
const db = pgt(new Client({
connectionString: "postgres://user:pass@localhost:5432/dbname"
}));
await db.connect();
const users = table("users", {
id: defineUUID("user_id").primaryKey(),
name: defineCharacterVarying("user_name", {
length: 255
}).notNull(),
age: defineInt2("user_age").notNull()
});
await db.select().from(users).where(eq(users.age, 18));
There is no need to install pg, nor drizzle-orm as they are both dependencies of this package.
However, you will need to install @postgresql-typed/cli if you want to use the CLI to generate the table definitions.
This package is part of the PostgreSQL-Typed ecosystem.