new Sqlite3Promise(databaseFilePath, initializeDatabasePromise)
Sqlite3Promise provides Promise-based methods to use the Node.js sqlite3
module.
Create a new Sqlite3Promise to use the given SQLite3 file.
Parameters:
Name | Type | Description |
---|---|---|
databaseFilePath |
string | The path of the SQLite3 file. |
initializeDatabasePromise |
function | (optional) When the database is first opened, this calls initializeDatabasePromise(database) where database is this Sqlite3Promise object, and which should return a Promise that resolves when the database is initialized by creating tables and indexes if needed. If omitted, this does not call it. |
- Source:
Methods
eachPromise(sql, params, onRow) → {Promise}
First open the database if needed, then call
sqlite3.Database.each(sql, params, onRow) to execute the SQL query.
Parameters:
Name | Type | Description |
---|---|---|
sql |
string | The SQL command to query. |
params |
object | Array.<object> | The single parameter or array of parameters for the query. If there are no parameters, pass []. |
onRow |
function | For each matched row, this calls onRow(err, row) where row is an object containing the values for the row where the object property names correspond to the column names. If no rows match the query, this is not called. |
- Source:
Returns:
A promise that fulfills when the SQL query is complete,
or that is rejected with Error if there is a database error.
- Type
- Promise
establishDatabasePromise_() → {Promise}
If this.sqlite3Database_ is still null, set up this.sqlite3Database_ and call
this.initializeDatabasePromise_() to create the database tables, etc. Each
method which uses the database must call this first. We can't do this in the
constructor because it is async.
- Source:
Returns:
A promise that fulfills when this.sqlite3Database_ is set up.
- Type
- Promise
getPromise(sql, params) → {Promise}
First open the database if needed, then call
sqlite3.Database.get(sql, params) to execute the SQL query and get a single row.
Parameters:
Name | Type | Description |
---|---|---|
sql |
string | The SQL query to execute. |
params |
object | Array.<object> | (optional) The single parameter or array of parameters for the query. |
- Source:
Returns:
A promise that returns the query result, or that is rejected
with Error if there is a database error. The query result is an object
containing the values for the first matching row where the object property
names correspond to the column names. If no rows are found, the query result
is the undefined value.
- Type
- Promise
runPromise(sql, params) → {Promise}
First open the database if needed, then call
sqlite3.Database.run(sql, params) to execute the SQL command.
Parameters:
Name | Type | Description |
---|---|---|
sql |
string | The SQL command to execute. |
params |
object | Array.<object> | (optional) The single parameter or array of parameters for the command. |
- Source:
Returns:
A promise that fulfills when the SQL command is complete,
or that is rejected with Error if there is a database error.
- Type
- Promise