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

@8x/kysely-d1

v1.0.1

Published

Readme

@8x/kysely-d1

Install

bun add @8x/kysely-d1

Usage

Create a Kysely instance (recommended)

initD1Kysely takes a D1Database and returns a Kysely instance configured with the D1 dialect.

import { initD1Kysely } from "@8x/kysely-d1";

// Example database type
type Database = {
	Comment: {
		id: number;
		content: string;
		isHidden: 0 | 1;
	};
};

export default {
	async fetch(_req: Request, env: { DB: D1Database }) {
		const db = initD1Kysely<Database>(env.DB);

		const comments = await db.selectFrom("Comment").selectAll().execute();
		const rows = await db
			.selectFrom("Comment")
			.select(["Comment.content", "id", "isHidden as is"])
			.execute();

		return Response.json({ comments, rows });
	},
};

Create manually with D1SQLiteDialect

If you prefer to construct Kysely yourself, you can use D1SQLiteDialect directly.

import { Kysely } from "kysely";
import { D1SQLiteDialect } from "@8x/kysely-d1";

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

Run batch (atomic on D1)

runBatch(db, queries) executes an array of Kysely queries (Compilable) using D1's db.batch(). Per D1 behavior, a batch is executed atomically; if any statement fails, the batch is rolled back.

import { runBatch } from "@8x/kysely-d1";

const result = await runBatch(env.DB, [
	db.insertInto("Person").values({ first_name: "John" }),
	db.insertInto("Pet").values({ name: "Fido", owner_id: 1 }),
	db.selectFrom("Person").selectAll(),
]);

console.log(result[0].meta.last_row_id); // insert id of the first query
console.log(result[1].meta.last_row_id); // insert id of the second query
console.log(result[2].results); // rows returned by the third (select) query

For insert / update / delete queries without returning(), D1 returns an empty results array (typed as never[]); the affected-row info lives in meta (last_row_id, changes). Add returning() / returningAll() to get typed rows back.

Notes / Limitations

  • Kysely transaction() is not supported because D1 does not support SQL transaction statements like BEGIN, COMMIT, and ROLLBACK.
  • streamQuery is not supported.

Development

To install dependencies:

bun install

To run:

bun run src/index.ts

This project was created using bun init in bun v1.3.6. Bun is a fast all-in-one JavaScript runtime.

Test

bun run cf-typegen
bun run vitest