@bitfinex/bfx-facs-db-better-sqlite
v2.1.0
Published
Bitfinex DB Sqlite3 Facility
Keywords
Readme
bfx-facs-db-better-sqlite
Config
Available the following config options:
{
name,
label,
dbPathAbsolute,
isSqliteStoredInMemory = false,
workerPathAbsolute,
isNotWorkerSpawned = false,
minWorkersCount = 4,
maxWorkersCount = 16,
unacceptableWalFileSize = 100000000,
readonly = false,
fileMustExist = false,
timeout = 5000,
verbose = false
}name: <string> used to construct the database name: `db-sqlite${name}${label}.db`label: <string> used to construct the database name: `db-sqlite${name}${label}.db`dbPathAbsolute: <string> absolute path to specify a folder for storing DB filesisSqliteStoredInMemory(by defaultfalse): <boolean> store DB in memory in-memory database, passing":memory:"as the first argument into the database optionsworkerPathAbsolute: <string> absolute path to specify a worker file for extending DB async query actions, see base implementation in the ./worker folder and extended implementation in the ./test/extended-worker folderisNotWorkerSpawned(by defaultfalse): <boolean> not spawn worker threads for async queriesminWorkersCount(by default4): <integer> count spawned workers are equal CPU cores count but not less than this value. If set0one worker will be spawned anywaymaxWorkersCount(by default16): <integer> count spawned workers are equal CPU cores count but not more than this valueunacceptableWalFileSize(by default100000000): <integer> unacceptable WAL file size in bytes, when the WAL file gets more than passed valuePRAGMA wal_checkpoint(RESTART)will be executed related to checkpoint starvationreadonly(by defaultfalse): <boolean> open the database connection in readonly mode passing as the second argument into the database optionsfileMustExist(by defaultfalse): <boolean> if the database does not exist, an Error will be thrown instead of creating a new file. This option does not affect in-memory or readonly database connections, passing as the second argument into the database optionstimeout(by default5000): <integer> the number of milliseconds to wait when executing queries on a locked database, before throwing a SQLITE_BUSY error passing as the second argument into the database optionsverbose(by defaultfalse): <boolean> iftruetheconsole.logwill called with every SQL string executed by the database connection, passingconsole.logas the second argument into the database options
API
Sqlite class provides the following methods:
.asyncQuery(args): provides an async way to delegate a query into DB using implemented worker actions or extended worker actions. For that uses Node.js worker threadsParameters:
args: <Object>action(required): <string> action that needs to pick to process logicsql: <string | Array[string]> SQL that needs to execute by the DB driver via workerparams: <any> parameters that pass into worker action
Returns:
- <Promise> contains returning action result
.initializeWalCheckpointRestart(ms): checks WAL file size in bytes which setting inunacceptableWalFileSizeconfig option, by set interval, when the WAL file gets more than passed valuePRAGMA wal_checkpoint(RESTART)will be executed related to checkpoint starvationParameters:
ms(by default 10000): <integer> interval in milliseconds with which the WAL file size will be checked
