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

kysely-pgschema

v0.3.0

Published

Generate Kysely type definitions from PostgreSQL schema files — offline, no DB required

Readme

kysely-pgschema

Generate Kysely type definitions from PostgreSQL schema files — no database connection required.

Parses .sql files offline using the official PostgreSQL parser (libpg-query, compiled to WASM).

Installation

npm install --save-dev kysely-pgschema

Usage

kysely-pgschema --schema ./db/schema.sql --out-file ./src/db/types.d.ts

Given this schema:

CREATE TYPE user_role AS ENUM ('admin', 'member');

CREATE TABLE users (
  id         serial PRIMARY KEY,
  email      text NOT NULL,
  role       user_role NOT NULL DEFAULT 'member',
  created_at timestamptz NOT NULL DEFAULT now(),
  deleted_at timestamptz
);

Generates:

import type { ColumnType } from 'kysely';

export type Generated<T> = ...;
export type Timestamp = ColumnType<Date, Date | string, Date | string>;

export type UserRole = 'admin' | 'member';

export interface Users {
  id: Generated<number>;
  email: string;
  role: Generated<UserRole>;
  created_at: Generated<Timestamp>;
  deleted_at: Timestamp | null;
}

export interface DB {
  users: Users;
}

Then use it with Kysely:

import { Kysely, PostgresDialect } from 'kysely';
import { DB } from './types.d.ts';

const db = new Kysely<DB>({ dialect: ... });

\i includes

Schema files that use \i (e.g. from pgschema.com or pg_dump splits) are resolved recursively:

-- schema.sql
\i ./tables/users.sql
\i ./tables/posts.sql

CLI options

| Flag | Default | Description | |---|---|---| | --schema | required | Path to SQL schema file | | --out-file | kysely-pgschema.d.ts | Output file path | | --camel-case | false | Convert snake_case columns to camelCase | | --default-schema | public | Schema used as root in the DB interface | | --include-pattern | — | Glob to include only matching schema.table | | --exclude-pattern | — | Glob to exclude matching schema.table | | --date-parser | timestamp | timestamp or string for date/time columns | | --numeric-parser | string | string, number, or number-or-string | | --runtime-enums | false | Also emit const objects for enum types | | --nullability | null | null (T \| null), optional (field?: T), or undefined (T \| undefined) | | --config-file | auto | Path to config file |

Config file

Options can also be set in .kysely-pgschemarc.json:

{
  "schema": "./db/schema.sql",
  "outFile": "./src/db/types.d.ts",
  "camelCase": true,
  "runtimeEnums": true,
  "nullability": "optional"
}

Supported SQL statements

  • CREATE TABLE
  • CREATE TYPE ... AS ENUM
  • ALTER TABLE ... ADD COLUMN
  • ALTER TABLE ... ALTER COLUMN SET NOT NULL / DROP NOT NULL / SET DEFAULT

Development

npm test          # run tests (node:test)
npm run typecheck # tsc --noEmit
npm run build     # compile to dist/