drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: Support LibSQL transaction behavior
- 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
Assessment
This issue has not been assessed yet.