import { KyselyLockAdapter } from "@daiso-tech/core/lock/kysely-lock-adapter";
import Sqlite from "better-sqlite3";
const lockAdapter = new KyselyLockAdapter({
kysely: new Kysely({
dialect: new SqliteDialect({
database: new Sqlite("local.db"),
}),
}),
});
// You need initialize the adapter once before using it.
await lockAdapter.init();
Removes a lock from the database regardless of its owner.
The unique identifier for the lock to remove.
Removes a lock from the database only if it is currently held by the specified owner.
The unique identifier for the lock.
Returns ILockExpirationData | null. The ILockExpirationData data if successfully removed, otherwise null if the lock wasn't found or the owner didn't match.
The transaction method runs the fn function inside a transaction.
The fn function is given a IDatabaseLockTransaction object.
Note when implementing this method use the strictest transaction level mode.
Updates the expiration date of a lock if it is currently held by the specified owner.
The unique identifier for the lock.
The new date and time when the lock should expire.
Returns a number greater than or equal to 1 if the lock's expiration was updated, or 0 if the lock wasn't found or the owner didn't match.
To utilize the
KyselyLockAdapter, you must install the"kysely"package and configure aKyselyclass instance.Note in order to use
KyselyLockAdaptercorrectly, ensure you use a single, consistent database across all server instances. The adapter have been tested withsqlite,postgresandmysqldatabases.IMPORT_PATH:
"@daiso-tech/core/lock/kysely-lock-adapter"