JSPM

kysely-do

0.0.1-rc.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4363
  • Score
    100M100P100Q118078F
  • License MIT

Kysely dialect for Cloudflare Durable Objects

Package Exports

  • kysely-do

Readme

kysely-do

ci npm

Kysely adapter for Cloudflare Durable Objects.

npm i kysely-do

This project provides a Kysely dialect for Cloudflare Durable Objects, enabling you to use SQL queries with Durable Object storage.

Usage

Creating a Durable Object with Kysely

To use kysely-do, you need to create a Durable Object class that initializes a Kysely instance with the DODialect. Here's a basic example:

import { DurableObject } from 'cloudflare:workers'
import { Kysely } from 'kysely'
import { DODialect } from 'kysely-do'

export interface Env {
  MY_OBJECT: DurableObjectNamespace<MyObject>
}

export class MyObject extends DurableObject<Env> {
  private db: Kysely<Database>

  constructor(ctx: DurableObjectState, env: Env) {
    super(ctx, env)

    // Create Kysely instance with DODialect
    this.db = new Kysely<Database>({
      dialect: new DODialect({ ctx }),
    })
  }
}

Configuration

You'll need to configure your Durable Object binding in your wrangler.jsonc:

{
  "durable_objects": {
    "bindings": [
      {
        "name": "MY_OBJECT",
        "class_name": "MyObject",
      },
    ],
  },
}