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

@wofflos/kysely-utils

v0.4.2

Published

Utilities for Kysely

Readme

@wofflos/kysely-utils

Personal package, published for convenience. No stability guarantees or support.

Utilities for Kysely. Requires Node >= 22.5.0.

Install

pnpm add @wofflos/kysely-utils kysely

Features

SerializerPlugin

Handles camelCase ↔ snake_case column name conversion and value serialization automatically.

  • Query: camelCase → snake_case column names
  • Result: snake_case → camelCase column names
  • Serializes boolean → "true" / "false", Date → Unix timestamp, objects → JSON
  • Deserializes columns ending in _at / _date → Date, "true" / "false" → boolean
import { createSerializerPlugin } from "@wofflos/kysely-utils";

const db = new Kysely<DB>({
  dialect,
  plugins: [createSerializerPlugin()],
});

SerializerPlugin, QueryTransformer, and ResultTransformer are also exported for building custom plugins.


NodeSqliteDialect

A Kysely dialect for Node's built-in node:sqlite module (Node 22.5+).

import { DatabaseSync } from "node:sqlite";
import { NodeSqliteDialect } from "@wofflos/kysely-utils";

const db = new Kysely<DB>({
  dialect: new NodeSqliteDialect({
    database: new DatabaseSync("./app.db"),
    // or a factory function, opened lazily on first query:
    // database: () => new DatabaseSync("./app.db"),
  }),
});

MigrationRunner

A wrapper around Kysely's Migrator with optional logging.

import { MigrationRunner } from "@wofflos/kysely-utils";

const runner = new MigrationRunner({
  db,
  migrations: [
    {
      name: "2024_01_create_users",
      async up(db) {
        /* ... */
      },
      async down(db) {
        /* ... */
      },
    },
  ],
  // optional: provide a logger for migration status messages
  logger: { log: console.log, error: console.error },
});

await runner.migrateToLatest(); // run all pending migrations
await runner.migrateUp(); // run one migration
await runner.migrateTo("name"); // migrate to a specific migration
await runner.migrateDown(); // roll back one migration
await runner.reset(); // roll back all migrations
await runner.status(); // log migration status
runner.close(); // destroy the db connection

MigrationsProvider is also exported for use directly with Kysely's Migrator.


Logger

Functions that return a Kysely Logger for SQL query logging.

import { consoleLogger, noopLogger } from "@wofflos/kysely-utils";

// Logs queries with duration and colorized SQL
const db = new Kysely<DB>({ dialect, log: consoleLogger() });

// Silences all SQL logs
const db = new Kysely<DB>({ dialect, log: noopLogger() });

Schema Introspector

Introspects a SQLite database and generates Kysely-compatible TypeScript types.

Generated output:

  • export interface Users { ... } per table, with camelCase property names
  • export interface Database { ... } mapping table names to interfaces
  • export type User = Selectable<Users> + NewUser + UserUpdate aliases (skippable with --no-aliases)
  • Generated<number> for single-column INTEGER PRIMARY KEY
  • Date for columns ending in _at or _date

CLI

Installed as kysely-utils, uses a config file by default.

# Introspect (flags override config)
kysely-utils introspect --db ./app.db --out ./src/schema.ts

# Migrate
kysely-utils migrate up
kysely-utils migrate down
kysely-utils migrate reset
kysely-utils migrate status

# Custom config file
kysely-utils migrate up --config ./my.config.ts

introspect flags:

| Flag | Default | Description | | ----------------- | ------------- | --------------------------------------------------- | | --db <path> | from config | Path to the SQLite .db file | | --out <path> | schema.ts | Output file path | | --tables <csv> | all tables | Tables to include | | --no-aliases | off | Skip Selectable/Insertable/Updateable aliases | | --config <path> | auto-detected | Config file path |

Config file

kysely-utils.config.ts (or .js) in your project root. Also looks for kysely.config.ts / kysely.config.js as fallbacks.

import { defineConfig, NodeSqliteDialect, consoleLogger } from "@wofflos/kysely-utils";
import { DatabaseSync } from "node:sqlite";
import { migrations } from "./dist/migrations.js";

export default defineConfig({
  dialect: new NodeSqliteDialect({ database: new DatabaseSync("./app.db") }),
  migrations,
  dbLogger: consoleLogger(), // SQL query logging (optional)
  migrationLogger: { log: console.log, error: console.error }, // migration status (optional)
  introspect: {
    db: "./app.db",
    out: "./src/schema.ts",
  },
});

On Node 22, .ts config files require --experimental-strip-types or a loader like tsx. Node 24 loads them natively.

Programmatic API

import { introspect } from "@wofflos/kysely-utils";

// Pass a file path (opened read-only, closed automatically)
const { code } = introspect("./app.db");
await fs.writeFile("schema.ts", code);

// Or pass an existing DatabaseSync instance
import { DatabaseSync } from "node:sqlite";
const db = new DatabaseSync("./app.db");
const { code, tables } = introspect(db, {
  tables: ["users", "posts"], // optional filter
  generateTypeAliases: false, // skip Selectable/Insertable/Updateable
  locale: "es", // BCP 47 tag for pluralization rules
});

License

MIT