npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@typed-sql/postgres

v2.1.0

Published

PostgreSQL grammar, schema introspection, type resolution, and driver-neutral runtime codecs for typed-sql.

Readme

@typed-sql/postgres

The stable PostgreSQL grammar for typed-sql, including catalog introspection, row and parameter inference, type policy, runtime codecs, and an optional application-owned pg adapter, native live verifier, and structured-plan inspector.

pnpm add @typed-sql/core @typed-sql/postgres pg
pnpm add -D @typed-sql/cli [email protected]

pg is loaded only through @typed-sql/postgres/pg; it is not a dependency or peer dependency of the grammar. Applications that stream rows also install the optional application-owned cursor:

pnpm add pg-cursor

Applications that use PostgreSQL COPY also install its optional application-owned stream:

pnpm add pg-copy-streams
import { requireAdapterCapability } from "@typed-sql/core";
import { postgresCopy, sql, typePolicy } from "@typed-sql/postgres";
import { createPgDatabase } from "@typed-sql/postgres/pg";

const query = sql`
  SELECT account.id, account.email, project.budget
  FROM users AS account
  LEFT JOIN projects AS project ON project.owner_id = account.id
`;

const database = await createPgDatabase({
  connectionString: process.env.DATABASE_URL!,
  compatibilitySnapshot: new URL("./generated/db/schema.json", import.meta.url),
  poolConfig: { pipeline: true },
  typePolicy,
  copyStreamsImporter: () => import("pg-copy-streams"),
  // observer: createOpenTelemetryObserver(),
});

// pipeline() requires the application-owned pg 8.23.0 or newer.

const rows = await database.execute(query);

const accountById = database.prepare("account-by-id", (id: bigint) => sql`
  SELECT account.id, account.email
  FROM users AS account
  WHERE account.id = ${id}
`);

const [selectedAccounts, allAccounts] = await database.batch([accountById(42n), query]);
const [pipelinedAccount, pipelinedAll] = await database.pipeline([accountById(42n), query]);

for await (const account of database.stream(accountById(42n), { batchSize: 500 })) {
  // account retains the query's inferred row type
}

const copy = requireAdapterCapability(database, postgresCopy);
await copy.copyFrom(
  (account: { readonly id: bigint; readonly email: string }) =>
    sql`INSERT INTO users (id, email) VALUES (${account.id}, ${account.email})`,
  accounts,
);

The package root exports sql, postgres, and the PostgreSQL type policy. The /pg entrypoint exports the schema provider, execution adapter, createPgLiveVerifier, and createPgPlanInspector; /runtime exposes driver-neutral PostgreSQL rendering and codecs.

The root also exports createPostgresRoutedDatabase, the runtime semantic resolver, and the native transaction retry classifier. These compose application-owned adapters without installing or creating pg pools.

The stable grammar supports PostgreSQL majors 14 through 18 and is release-tested against exact 14.24, 15.19, 16.15, 17.11, and 18.6 targets. POSTGRES_SUPPORT_POLICY exposes those per-major targets, the separately reported PostgreSQL 19beta3 canary, and the upstream end-of-life deprecation rule; future and prerelease majors remain conservative unless canary policy is selected explicitly.

Operator and snapshot-routine overloads use PostgreSQL-owned canonical types, cast contexts, preferred categories, unknown-literal selection, and simple/common polymorphic families. Ambiguous or incompatible candidates produce diagnostics instead of optimistic result types.

The grammar resolves PostgreSQL grouping sets and ordered aggregates, inherited and framed windows, lateral function relations and ROWS FROM, WITH ORDINALITY, TABLESAMPLE, and FETCH pagination. PostgreSQL DML includes identity overriding, snapshot-backed expression and partial-index ON CONFLICT inference, action-scoped excluded, typed row/subquery assignments, versioned MERGE, and PostgreSQL 18 old/new RETURNING namespaces. Unsupported or structurally invalid forms fail closed with source diagnostics.

Read the PostgreSQL grammar guide, execution guide, bulk data guide, observability guide, live verification guide, query plan governance guide, routing and retry guide, configuration, and database type mappings.

MIT © typed-sql contributors