kysely-durable-object-sqlite
TypeScript icon, indicating that this package has built-in type declarations

0.0.0 • Public • Published

Kysely Migrator Local

A Kysely dialect for Cloudflare Durable Objects Sqlite Storage.

Install

npm i kysely kysely-durable-objects-sqlite

Usage

import { DurableObject } from "cloudflare:workers";
import { Kysely } from "kysely";
import { DurableObjectSqliteDialect } from "kysely-durable-object-sqlite";

interface ExampleDatabase {
  users: {
    id: number;
    name: string;
  };
}

export class ExampleDurableObject extends DurableObject {
  private _db: Kysely<ExampleDatabase>;

  constructor(ctx, env) {
    super(ctx, env);

    this._db = new Kysely({
      dialect: new DurableObjectSqliteDialect({
        sql: this.ctx.storage.sql
      }),
    });

    this.ctx.blockConcurrencyWhile(async () => {
      // Do some migrations...?
    });
  }

  async getUsers() {
    const users = await this._db
      .selectFrom("users")
      .selectAll()
      .execute();

    return users;
  }
}

Dependencies (0)

    Dev Dependencies (11)

    Package Sidebar

    Install

    npm i kysely-durable-object-sqlite

    Weekly Downloads

    8

    Version

    0.0.0

    License

    MIT

    Unpacked Size

    37.3 kB

    Total Files

    11

    Last publish

    Collaborators

    • samuellaycock