SQLiteClient
Class: SQLiteClient
Defined in: sqlite/src/connection.ts:146
Adapter of a DatabaseSync to the SQLClient interface, with a bounded prepared statement cache
The connection is shared by every service of the database: while a transaction holds it (see acquireExclusive), the statements of the other async chains wait for its end instead of running inside it.
Implements
SQLClient
Constructors
Constructor
new SQLiteClient(
db,cacheSize?):SQLiteClient
Defined in: sqlite/src/connection.ts:161
Create a new SQLiteClient instance
Parameters
db
DatabaseSync
the open database
cacheSize?
number = 256
max prepared statements kept
Returns
SQLiteClient
Properties
cacheSize
protectedreadonlycacheSize:number=256
Defined in: sqlite/src/connection.ts:163
max prepared statements kept
db
readonlydb:DatabaseSync
Defined in: sqlite/src/connection.ts:162
the open database
exclusive?
protectedoptionalexclusive?:object
Defined in: sqlite/src/connection.ts:154
The transaction holding the connection: isOwner tells whether the current async chain runs in it
isOwner
isOwner: () =>
boolean
Returns
boolean
released
released:
Promise<void>
statements
protectedstatements:Map<string,StatementSync>
Defined in: sqlite/src/connection.ts:150
Statements
Methods
acquireExclusive()
acquireExclusive(
isOwner):Promise<() =>void>
Defined in: sqlite/src/connection.ts:234
Hold the connection for a transaction: once the transactions of the other async chains ended, the statements of
the chains isOwner does not recognize wait until the returned release function is called
Parameters
isOwner
() => boolean
whether the current async chain runs in the transaction
Returns
Promise<() => void>
the release function, to call once the transaction is committed or rolled back
isHeld()
isHeld():
boolean
Defined in: sqlite/src/connection.ts:224
Check whether held
Returns
boolean
true while a transaction holds the connection: reads on it may see uncommitted rows
query()
query(
sql,values?):Promise<{rowCount:number;rows:any[]; }>
Defined in: sqlite/src/connection.ts:191
SELECT / WITH / PRAGMA statements run with all(), the others with run(); the method is async to honor SQLClient
The statement kind is read from its first keyword only: a value inlined in a WHERE clause can never change it. Use rows for a write statement with a RETURNING clause.
Parameters
sql
string
the statement
values?
any[] = []
the parameters
Returns
Promise<{ rowCount: number; rows: any[]; }>
the rows, or the number of changed rows
Implementation of
SQLClient.query
rows()
rows(
sql,values?):Promise<any[]>
Defined in: sqlite/src/connection.ts:212
Run a statement returning rows, a write with a RETURNING clause included
Parameters
sql
string
the statement
values?
any[] = []
the parameters
Returns
Promise<any[]>
the rows
run()
protectedrun<R>(sql,execute):R
Defined in: sqlite/src/connection.ts:257
Run a statement, translating the engine errors
Type Parameters
R
R
Parameters
sql
string
the statement
execute
() => R
the execution
Returns
R
the execution result
statement()
protectedstatement(sql):StatementSync
Defined in: sqlite/src/connection.ts:171
Return the prepared statement, cached
Parameters
sql
string
the statement
Returns
StatementSync
the prepared statement, cached