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 🙏

© 2025 – Pkg Stats / Ryan Hefner

kysely-rizzolver-codegen

v0.0.5

Published

Generates a ready to use KyselyRizzolver instance from the output of kysely-codegen tool.

Readme

kysely-rizzolver-codegen

Generates a ready-to-use KyselyRizzolver instance from the output of the kysely-codegen tool.

Usage

You can use this tool via npx:

npx kysely-rizzolver-codegen --schema-from <path> --output <path> [additional opts]

Options

  • --schema-from <path>: The path the kysely-codegen tool wrote the DB interface to.
  • --output <path>: The output file to write this tool's generated code to.
  • --import-from <path>: The path that is used in this tool's generated code to import the DB interface from. Defaults to the relative path between the output and input files.
  • --export-as <name>: The name for the exported KyselyRizzolver instance. Defaults to 'rizzolver'.
  • --fks-from <path>: The path that is used in this tool's generated code to import a function that defines the foreign keys for the schema. See Defining foreign keys for more information.
  • --help, -h: Show the help message and exit.

Example

npx kysely-rizzolver-codegen --schema-from src/generated/db-schema.ts --output src/generated/rizzolver.ts

This will generate a file src/generated/rizzolver.ts with the following content:

// This file was generated by kysely-rizzolver-codegen. Do not edit it manually.

import type { DB } from './db-schema';
import { KyselyRizzolver } from 'kysely-rizzolver';

export const rizzolver = KyselyRizzolver.builder<DB>()
	.table('tableName', ['column1', 'column2'] as const)
	.build();

Defining foreign keys

[!WARNING] This feature is very early in development. To keep things simple as it takes shape I made some heavy assumptions:

  • Only simple, numeric foreign keys are supported (no composite keys, no string keys, etc.)
  • It is assumed every table has a numeric primary key named id.
  • It is assumed the id column is never 0.

I plan on getting rid of these assumptions in the future.

KyselyRizzolver provides useful functions to gather a table and its foreign keys recursively.

However, kysely-codegen does not output the foreign keys, so you have to define them yourself.

Create a file that has a default export for a function that takes in a FkDefsBuilder<DB> instance and returns the foreign key definitions.

Consider the following schema:

path/to/db-schema.ts:

interface User {
	id: Generated<number>;
	username: string;
}

interface Post {
	id: Generated<number>;
	title: string;
	author_id: number;
	pinned_comment_id: number | null;
}

interface Comment {
	id: Generated<number>;
	content: string;
	author_id: number;
	post_id: number;
}

export interface DB {
	user: User;
	post: Post;
	comment: Comment;
}

You can define the foreign keys like this:

path/to/fks.ts:

import type { FkDefsBuilder } from 'kysely-rizzolver';
import type { DB } from './db-schema';

export default (fks: FkDefsBuilder<DB>) => fks
	// arguments are:
	// - from table
	// - from column
	// - to table
	// - to column
	.add('post', 'author_id', 'user', 'id')
	.add('post', 'pinned_comment_id', 'comment', 'id', true) // true for nullable
	.add('comment', 'author_id', 'user', 'id')
	.add('comment', 'post_id', 'post', 'id')
	.build();

Then, you can generate the Rizzolver instance with the following command:

npx kysely-rizzolver-codegen --schema-from path/to/db-schema.ts --output path/to/rizzolver.ts --fks-from './fks'

This will generate path/to/rizzolver.ts with the following content:

import type { DB } from './db-schema';
import { KyselyRizzolver } from 'kysely-rizzolver';
import defineFks from './fks';

export const rizzolver = KyselyRizzolver.builder<DB>()
	.table('user', ['id', 'username'] as const)
	.table('post', ['id', 'title', 'author_id', 'pinned_comment_Id'] as const)
	.table('comment', ['id', 'content', 'author_id', 'post_id'] as const)
	.build(defineFks);

License

This project is licensed under the MIT License.