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

@doync/schema-codegen

v0.4.0

Published

Generate a plain doync schema module from SQLite migration DDL via an in-memory node:sqlite oracle

Readme

@doync/schema-codegen

Generate a plain doync schema module (satisfies DoyncSchema) from your SQLite migration DDL. Pass the emitted schema to createDoync({ schema, ctxValidationSchema }). One command (or one function call) replaces hand-archaeology of column names, affinities, primary-key order, and NOT NULL.

Codegen-time only. The engine is Node's built-in node:sqlite (DatabaseSync). This package never runs inside Cloudflare Workers or any other non-Node runtime — use it in a build script, a CI step, or at the terminal, then commit the emitted source next to your schema.

Install

pnpm add -D @doync/schema-codegen

Requires Node ≥ 22.5 (when node:sqlite stabilized). Zero runtime npm dependencies.

Why real SQLite

Exotic DDL comes out right because the database built it:

  • Composite primary keys declared mid-column-list land in key order, not table order.
  • Layered ALTER TABLE (add / drop / rename column, rename table) collapses to the final shape.
  • Declared types map through SQLite's five-rule affinity derivation (VARCHAR(255)text, INT8integer, DOUBLE PRECISIONreal, DECIMAL(10,2)numeric, empty → blob).
  • STRICT tables and generated columns report whatever pragma_table_xinfo sees after the DDL applies.

CLI

# Print the tables: array to stdout
pnpm schema-codegen migrations/
# or
npx schema-codegen path/to/0001_init.sql path/to/0002_add_priority.sql

# Write to a file
schema-codegen migrations/ --out src/schema.tables.ts

Inputs are .sql files and/or directories of .sql files. Files run in sorted full-path order (so 0001_…sql before 0002_…sql). Multiple ;-separated statements per file are fine.

Programmatic API

import {
  generateTablesFromSql,
  generateTablesFromFiles,
} from '@doync/schema-codegen'

// From ordered SQL strings:
const { tables, migrations, source } = generateTablesFromSql(
  migrationSql.map((m) => m.sql),
)

// Or from files on disk:
const fromDisk = generateTablesFromFiles(['./migrations'])

// `source` is a ready module — commit and import:
//
//   import { schema } from './generated'
//   export const { defineQuery, … } = createDoync({
//     schema,
//     ctxValidationSchema,
//   })
//
// `tables` / `migrations` are the same shape as data if you prefer to wire without eval.

doync-fit: DoyncSchema

Emitted column objects match doync's consumer column surface:

{
  name: string
  type: 'text' | 'integer' | 'real' | 'blob' | 'numeric'
  pk?: true       // omitted when false
  notNull?: true  // omitted when false
}

Primary-key columns are emitted first, in primary-key ordinal order; remaining columns follow in table order. That matches the Drizzle auto-derivation convention so hand-written, Drizzle-derived, and codegen-produced schemas compare equal.

Internal tables are skipped:

  • sqlite_* — SQLite catalog / sequence tables
  • __doync_* — doync-reserved engine tables

Generated columns

pragma_table_info omits generated columns. This package reads pragma_table_xinfo instead, so VIRTUAL and STORED generated columns appear in the emission with their declared affinity and nullability. doync's boot verifier also reads the physical schema; if you ship a generated column on a synced table, list it here so declaration and database agree. (There is no separate generated flag on the column surface — affinity + name + nullability is what boot checks today.)

STRICT tables

STRICT is a table-level SQLite property. Column affinities still flow from declared types the same way; the emitter does not special-case STRICT. After migrations apply, what you see in the emission is what SQLite stored.

Affinity rules (normative)

Declared type substring match, case-insensitive, first match wins:

  1. contains INTinteger
  2. contains CHAR, CLOB, or TEXTtext
  3. contains BLOB, or the declared type is empty → blob
  4. contains REAL, FLOA, or DOUBreal
  5. else → numeric

The affinity rules are documented here; the helper itself lives on @doync/schema-codegen/internal.

License

MIT