drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Support LibSQL transaction behavior

Open
#1,331 0 comments 4 reactions 0 assignees View on GitHub
db/sqlite driver/libsql enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Support LibSQL transaction behaviour

LibSQL clients provides an interface to pick one of the transaction methods.

```ts
import { createClient } from "@libsql/client";

const client = createClient({
url: DatabaseConfig.URL,
authToken: DatabaseConfig.AuthToken,
});

client.transaction("deferred")
client.transaction("write")
client.transaction("read")
```

There is also a related bug with types for drizzle LibSQLDatabase.

If you initialise transaction you receive `SQLiteTransaction` instead of `LibSQLiteTransaction`, which results in supported behaviours for SQLite.

```ts
import { drizzle } from "drizzle-orm/libsql";

const database = drizzle(client, { logger: true });

await database.transaction(
async (tx) => {
return SaveSomething(tx, entity);
},
{
behavior: "exclusive",
}
);
```
### Expected behaviour

```ts
import { drizzle } from "drizzle-orm/libsql";

const database = drizzle(client, { logger: true });

await database.transaction(
async (tx) => {
return SaveSomething(tx, entity);
},
{
behavior: "read" | "write" | "deferred",
}
);
```

Same mechanism should be also supported for `LibSQLDatabase.batch` method.

[Documentation](https://docs.turso.tech/libsql/client-access/javascript-typescript-sdk#batches-and-interactive-transactions) from turso's site.

[TODO](https://github.com/drizzle-team/drizzle-orm/blob/a7dc7e8bbdc3784f67ff32ce39bee3283f080751/drizzle-orm/src/libsql/session.ts#L141) in the code noting that change.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.