import { KyselySemaphoreAdapter } from "@daiso-tech/core/semaphore/kysely-semaphore-adapter";
import Sqlite from "better-sqlite3";
const semaphoreAdapter = new KyselySemaphoreAdapter({
kysely: new Kysely({
dialect: new SqliteDialect({
database: new Sqlite("local.db"),
}),
}),
});
// You need initialize the adapter once before using it.
await semaphoreAdapter.init();
The removeAllSlots removes all slots of the given semaphore.
Returns the slot expiration.
The removeSlot removes the specified slot.
Returns the slot expiration.
The transaction method runs the fn function inside a transaction.
The fn function is given a IDatabaseSemaphoreTransaction object.
Note when implementing this method use the strictest transaction level mode.
The updateExpiration updates the specified slot expiration as long as it is expireable and unexpired of the given semaphore.
Returns a number greater than 0 if the slot expiration was updated, otherwise returns 0.
To utilize the
KyselySemaphoreAdapter, you must install the"kysely"package and configure aKyselyclass instance.Note in order to use
KyselySemaphoreAdaptercorrectly, ensure you use a single, consistent database across all server instances. The adapter have been tested withsqlite,postgresandmysqldatabases.IMPORT_PATH:
"@daiso-tech/core/semaphore/kysely-semaphore-adapter"