Skip to main content
zerotal

Documentation


Documentation / @zerotal/core / lock / SqliteLockDriver

Class: SqliteLockDriver

Defined in: lock/drivers/SqliteLockDriver.ts:16

SQLite-backed lock driver.

Suitable for single-server deployments that need locks to survive process restarts. Backed by bun:sqlite — fully synchronous under the hood so every acquire/release is a single atomic statement.

Use :memory: as the path for in-process persistence across tests without touching the filesystem.

Implements

Constructors

Constructor

new SqliteLockDriver(path?): SqliteLockDriver

Defined in: lock/drivers/SqliteLockDriver.ts:19

Parameters

path?

string = ":memory:"

Returns

SqliteLockDriver

Methods

acquire()

acquire(key, owner, ttlSeconds): Promise<boolean>

Defined in: lock/drivers/SqliteLockDriver.ts:30

Try to acquire the lock. Returns true when acquired, false if already held by another owner and not yet expired.

Parameters

key

string

owner

string

ttlSeconds

number

Returns

Promise<boolean>

Implementation of

LockDriver.acquire


release()

release(key, owner): Promise<boolean>

Defined in: lock/drivers/SqliteLockDriver.ts:62

Release the lock only if the caller is still the owner. Returns true when released, false if the lock was held by someone else (e.g. TTL expired and another process re-acquired).

Parameters

key

string

owner

string

Returns

Promise<boolean>

Implementation of

LockDriver.release


forceRelease()

forceRelease(key): Promise<void>

Defined in: lock/drivers/SqliteLockDriver.ts:69

Unconditionally delete the lock regardless of owner.

Parameters

key

string

Returns

Promise<void>

Implementation of

LockDriver.forceRelease


exists()

exists(key): Promise<boolean>

Defined in: lock/drivers/SqliteLockDriver.ts:73

Returns true if the lock is currently held (not expired).

Parameters

key

string

Returns

Promise<boolean>

Implementation of

LockDriver.exists


dispose()

dispose(): void

Defined in: lock/drivers/SqliteLockDriver.ts:82

Release background resources (timers, DB connections).

Returns

void

Implementation of

LockDriver.dispose