Files
static-pages/packages/kysely-adapter-cloudflare
immich-push-o-matic[bot] 8dd91c20b6 chore(main): release kysely-adapter-cloudflare 0.1.2 (#731)
Co-authored-by: immich-push-o-matic[bot] <179150890+immich-push-o-matic[bot]@users.noreply.github.com>
2026-08-27 12:24:41 +00:00
..
2026-08-25 18:15:36 -04:00
2026-05-04 14:37:01 -04:00
2026-05-04 14:37:01 -04:00
2026-08-25 16:27:49 +02:00

Kysely Adapter Cloudflare

Kysely adapter for Cloudflare databases.

Install

pnpm i @immich/kysely-adapter-cloudflare

Example

import { CloudflareD1Dialect } from '@immich/kysely-adapter-cloudflare';

const dialect = new CloudflareD1Dialect({ database: process.env.DB });

const db = new Kysely<MySchema>({ dialect });

Transactions

The CloudflareD1Dialect implements Kysely transactions using the D1 batch method. They're not real transactions, since D1 does not support transactions in the traditional sense. In short, queries used inside a transaction() are added to a batch and then submitted all at once when the transaction is committed.

Note: This implies that you cannot use any of the return values, as there aren't any. See examples below.

Good

db.transaction().execute(async (tx) => {
  await tx.insertInto('post').values(item).execute();
  await tx.insertInto('article').values(item).execute();
});

Bad

const article = // will be undefined
  await db.transaction().execute(async (tx) => {
    const post = await tx.insertInto('posts').values(item).execute();
    return tx
      .insertInto('articles')
      .values({
        ...article,
        postId: post.id, // will be undefined
      })
      .execute();
  });