@immich/kysely-adapter-cloudflare
v0.1.0
Published
A Kysely adapter for cloudflare databases
Readme
Kysely Adapter Cloudflare
Kysely adapter for Cloudflare databases.
Install
pnpm i @immich/kysely-adapter-cloudflareExample
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();
});