import { KyselySharedLockAdapter } from "@daiso-tech/core/shared-lock/kysely-shared-lock-adapter";
import Sqlite from "better-sqlite3";
import { Kysely, SqliteDialect } from "kysely";
const sharedLockAdapter = new KyselySharedLockAdapter({
kysely: new Kysely({
dialect: new SqliteDialect({
database: new Sqlite("local.db"),
}),
}),
});
// You need initialize the adapter once before using it.
await sharedLockAdapter.init();
Executes a function within a database transaction providing both reader and writer operations. Ensures atomicity of all shared lock operations within the transaction.
Implementations must use the strictest transaction isolation level available to prevent race conditions between concurrent readers and writers.
Async function receiving combined reader/writer transaction object
The value returned by the transaction function
To utilize the
KyselySharedLockAdapter, you must install the"kysely"package and configure aKyselyclass instance.Note in order to use
KyselySharedLockAdaptercorrectly, ensure you use a single, consistent database across all server instances and use a database that has support for transactions. The adapter have been tested withsqlite,postgresandmysqldatabases.IMPORT_PATH:
"@daiso-tech/core/shared-lock/kysely-shared-lock-adapter"