
.live() re-queries when the underlying data changes — pushed directly to clients.Developer preview — surface is settled, edges still being filed. Not yet recommended for production.
npm install typegres pg
import { typegres, Int8, Text, expose } from "typegres";
const db = await typegres({
type: "pg",
connectionString: process.env.DATABASE_URL!,
});
class Users extends db.Table("users") {
@expose() id = (Int8<1>).column({ nonNull: true, generated: true });
@expose() first_name = (Text<1>).column({ nonNull: true });
@expose() last_name = (Text<1>).column({ nonNull: true });
// Derived column — composes back into your typed query API.
@expose() fullName() {
return this.first_name["||"](" ")["||"](this.last_name);
}
}
// `fullName()` works anywhere a column does — select, where, orderBy:
const rows = await Users.from()
.select(({ users }) => ({
id: users.id,
name: users.fullName(),
}))
.execute(db);
console.log(rows);
await db.close();
For a complete scaffold with migrations + codegen, see
examples/basic. Or try it interactively at
typegres.com/play.
@expose methods — columns, relations, scoped reads, mutations. The class
surface is the contract; the schema underneath is free to move.@expose-marked methods reach evaluation..live() watches the predicates your query depends
on and re-yields when committed mutations would change the result.Deeper dive in docs/ARCHITECTURE.md.
.select + .join + .where + .groupBy + .having + .orderBy + .limit).insert / .update / .delete / .returning).live() returns an async iterable that
re-yields when committed mutations would change the result@expose-marked
classes/methods are serialized, evaluated server-side under a
constrained interpreter, and JSON-streamed backpg_notify-driven live updates (currently a single shared polling loop, not per-subscription)Recommended: Nix the package manager
- direnv. The
.envrc(use flake) auto-activates the pinned toolchain when youcdinto the repo, andbin/startpgworks out of the box. Without Nix, pointDATABASE_URLat any local Postgres and skipstartpg.
./bin/startpg # one-time dev Postgres socket (Nix)
npm install
npm run check # lint + typecheck + tests
MIT — see LICENSE.