Skip to content

Latest commit

 

History

History
384 lines (224 loc) · 10.7 KB

_src_database_.database.md

File metadata and controls

384 lines (224 loc) · 10.7 KB

sqliteGlobals"src/Database"Database

Class: Database ‹Driver, Stmt

Promisified wrapper for the sqlite3#Database interface.

Type parameters

Driver: Database

Stmt: Statement

Hierarchy

  • Database

Index

Constructors

Properties

Methods

Constructors

constructor

+ new Database(config: Config): Database

Defined in src/Database.ts:18

Parameters:

Name Type
config Config

Returns: Database

Properties

config

config: Config

Defined in src/Database.ts:17


db

db: Driver

Defined in src/Database.ts:18

Methods

all

allT›(sql: SqlType, ...params: any[]): Promise‹T›

Defined in src/Database.ts:255

Runs the SQL query with the specified parameters. The parameters are the same as the Database#run function, with the following differences:

If the result set is empty, it will be an empty array, otherwise it will have an object for each result row which in turn contains the values of that row, like the Database#get function.

Note that it first retrieves all result rows and stores them in memory. For queries that have potentially large result sets, use the Database#each function to retrieve all rows or Database#prepare followed by multiple Statement#get calls to retrieve a previously unknown amount of rows.

see https://github.com/mapbox/node-sqlite3/wiki/API#databaseallsql-param--callback

Type parameters:

T

Parameters:

Name Type Description
sql SqlType The SQL query to run.
...params any[] -

Returns: Promise‹T›


close

close(): Promise‹void›

Defined in src/Database.ts:79

Closes the database.

Returns: Promise‹void›


configure

configure(option: ConfigureOption, value: any): any

Defined in src/Database.ts:94

see https://github.com/mapbox/node-sqlite3/wiki/API#databaseconfigureoption-value

Parameters:

Name Type
option ConfigureOption
value any

Returns: any


each

eachT›(sql: SqlType, ...params: any[]): Promise‹number›

Defined in src/Database.ts:187

Runs the SQL query with the specified parameters and calls the callback once for each result row. The parameters are the same as the Database#run function, with the following differences:

If the result set succeeds but is empty, the callback is never called. In all other cases, the callback is called once for every retrieved row. The order of calls correspond exactly to the order of rows in the result set.

There is currently no way to abort execution!

The last parameter to each() must be a callback function.

example await db.each('SELECT * FROM x WHERE y = ?', 'z', (err, row) => { // row contains the row data // each() resolves when there are no more rows to fetch })

see https://github.com/mapbox/node-sqlite3/wiki/API#databaseeachsql-param--callback-complete

Type parameters:

T

Parameters:

Name Type
sql SqlType
...params any[]

Returns: Promise‹number›

Promise Number of rows returned


exec

exec(sql: SqlType): Promise‹void›

Defined in src/Database.ts:280

Runs all SQL queries in the supplied string. No result rows are retrieved. If a query fails, no subsequent statements will be executed (wrap it in a transaction if you want all or none to be executed).

Note: This function will only execute statements up to the first NULL byte. Comments are not allowed and will lead to runtime errors.

see https://github.com/mapbox/node-sqlite3/wiki/API#databaseexecsql-callback

Parameters:

Name Type Description
sql SqlType The SQL query to run.

Returns: Promise‹void›


get

getT›(sql: SqlType, ...params: any[]): Promise‹T | undefined›

Defined in src/Database.ts:150

Runs the SQL query with the specified parameters and resolves with with the first result row afterwards. If the result set is empty, returns undefined.

The property names correspond to the column names of the result set. It is impossible to access them by column index; the only supported way is by column name.

see https://github.com/mapbox/node-sqlite3/wiki/API#databasegetsql-param--callback

Type parameters:

T

Parameters:

Name Type Description
sql SqlType The SQL query to run.
...params any[] -

Returns: Promise‹T | undefined›


getDatabaseInstance

getDatabaseInstance(): Driver

Defined in src/Database.ts:36

Returns the underlying sqlite3 Database instance

Returns: Driver


loadExtension

loadExtension(path: string): Promise‹unknown›

Defined in src/Database.ts:325

Loads a compiled SQLite extension into the database connection object.

Parameters:

Name Type Description
path string Filename of the extension to load

Returns: Promise‹unknown›


migrate

migrate(config?: MigrationParams): Promise‹void›

Defined in src/Database.ts:340

Performs a database migration.

Parameters:

Name Type
config? MigrationParams

Returns: Promise‹void›


on

on(event: string, listener: any): void

Defined in src/Database.ts:29

Event handler when verbose mode is enabled.

see https://github.com/mapbox/node-sqlite3/wiki/Debugging

Parameters:

Name Type
event string
listener any

Returns: void


open

open(): Promise‹void›

Defined in src/Database.ts:43

Opens the database

Returns: Promise‹void›


parallelize

parallelize(): void

Defined in src/Database.ts:360

Returns: void


prepare

prepare(sql: SqlType, ...params: any[]): Promise‹Statement‹Stmt››

Defined in src/Database.ts:306

Prepares the SQL statement and optionally binds the specified parameters. When bind parameters are supplied, they are bound to the prepared statement.

Parameters:

Name Type Description
sql SqlType The SQL query to run.
...params any[] -

Returns: Promise‹Statement‹Stmt››

Promise Statement object


run

run(sql: SqlType, ...params: any[]): Promise‹RunResult‹Stmt››

Defined in src/Database.ts:112

Runs the SQL query with the specified parameters. It does not retrieve any result data. The function returns the Database object for which it was called to allow for function chaining.

see https://github.com/mapbox/node-sqlite3/wiki/API#databaserunsql-param--callback

Parameters:

Name Type Description
sql SqlType The SQL query to run.
...params any[] -

Returns: Promise‹RunResult‹Stmt››


serialize

serialize(): void

Defined in src/Database.ts:351

The methods underneath requires creative work to implement. PRs / proposals accepted!

Returns: void