Creating a Database object automatically opens a connection to the SQLite database.When the connection is established the Database object emits an open event and callsthe optional provided callback. If the connection cannot be established an error eventwill be emitted and the optional callback is called with the error information.
Create and initialize a database from a full configuration object, or connection string
Optionalcallback:ErrorCallbackOverrides EventEmitter.constructor
Optionalmode:numberOptionalcallback:ErrorCallbackOverrides EventEmitter.constructor
StaticprefixedInherited from EventEmitter.prefixed
Optionalcontext:anyInherited from EventEmitter.addListener
Runs the SQL query with the specified parameters and calls the callbackwith all result rows afterwards. The function returns the Database object toallow for function chaining. The parameters are the same as the Database#runfunction, with the following differences: The signature of the callback isfunction(err, rows) {}. rows is an array. If the result set is empty, it willbe an empty array, otherwise it will have an object for each result row whichin 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#eachfunction to retrieve all rows or Database#prepare followed by multiple Statement#getcalls to retrieve a previously unknown amount of rows.
Optionalcallback:RowsCallback<T>Runs the SQL query with the specified parameters and calls the callbackwith all result rows afterwards. The function returns the Database object toallow for function chaining. The parameters are the same as the Database#runfunction, with the following differences: The signature of the callback isfunction(err, rows) {}. rows is an array. If the result set is empty, it willbe an empty array, otherwise it will have an object for each result row whichin 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#eachfunction to retrieve all rows or Database#prepare followed by multiple Statement#getcalls to retrieve a previously unknown amount of rows.
Optionalcallback:RowsCallback<T>If the optional callback is provided, this function will be called when thedatabase was closed successfully or when an error occurred. The first argumentis an error object. When it is null, closing succeeded. If no callback is providedand an error occurred, an error event with the error object as the only parameterwill be emitted on the database object. If closing succeeded, a close event with noparameters is emitted, regardless of whether a callback was provided or not.
Optionalcallback:ErrorCallbackSet a configuration option for the database
Runs the SQL query with the specified parameters and calls the callback once for each result row.The function returns the Database object to allow for function chaining. The parameters are thesame as the Database#run function, with the following differences: The signature of the callbackis function(err, row) {}. 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 correspondexactly to the order of rows in the result set. After all row callbacks were called, the completioncallback will be called if present. The first argument is an error object, and the second argumentis the number of retrieved rows. If you specify only one function, it will be treated as row callback,if you specify two, the first (== second to last) function will be the row callback, the last functionwill be the completion callback. If you know that a query only returns a very limited number of rows,it might be more convenient to use Database#all to retrieve all rows at once. There is currently noway to abort execution.
Optionalcallback:RowCallback<T>Optionalcomplete:RowCountCallbackRuns the SQL query with the specified parameters and calls the callback once for each result row.The function returns the Database object to allow for function chaining. The parameters are thesame as the Database#run function, with the following differences: The signature of the callbackis function(err, row) {}. 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 correspondexactly to the order of rows in the result set. After all row callbacks were called, the completioncallback will be called if present. The first argument is an error object, and the second argumentis the number of retrieved rows. If you specify only one function, it will be treated as row callback,if you specify two, the first (== second to last) function will be the row callback, the last functionwill be the completion callback. If you know that a query only returns a very limited number of rows,it might be more convenient to use Database#all to retrieve all rows at once. There is currently noway to abort execution.
Optionalcallback:RowCallback<T>Optionalcomplete:RowCountCallbackCalls each of the listeners registered for a given event.
Inherited from EventEmitter.emit
Return an array listing the events for which the emitter has registeredlisteners.
Inherited from EventEmitter.eventNames
Runs all SQL queries in the supplied string. No result rows are retrieved.The function returns the Database object to allow for function chaining.If a query fails, no subsequent statements will be executed (wrap it in atransaction if you want all or none to be executed). When all statementshave been executed successfully, or when an error occurs, the callbackfunction is called, with the first parameter being either null or an errorobject. When no callback is provided and an error occurs, an error eventwill be emitted on the database object.
Optionalcallback:ErrorCallbackRuns the SQL query with the specified parameters and calls the callback witha subsequent result row. The function returns the Database object to allow forfunction chaining. The parameters are the same as the Database#run function,with the following differences: The signature of the callback isfunction(err, row) {}.If the result set is empty, the second parameter is undefined, otherwise it is anobject containing the values for the first row. The property names correspond tothe column names of the result set. It is impossible to access them by column index;the only supported way is by column name.
Optionalcallback:RowCallback<T>Runs the SQL query with the specified parameters and calls the callback witha subsequent result row. The function returns the Database object to allow forfunction chaining. The parameters are the same as the Database#run function,with the following differences: The signature of the callback isfunction(err, row) {}.If the result set is empty, the second parameter is undefined, otherwise it is anobject containing the values for the first row. The property names correspond tothe column names of the result set. It is impossible to access them by column index;the only supported way is by column name.
Optionalcallback:RowCallback<T>Returns the configuration with which this database was opened.The configuration is readonly and cannot be changed as there maybe multiple connections using the same configuration.
A configuration object
PubSub class provides a Pub/Sub real-time updates and notifications system toallow multiple applications to communicate with each other asynchronously.It allows applications to subscribe to tables and receive notifications wheneverdata changes in the database table. It also enables sending messages to anyonesubscribed to a specific channel.
A PubSub object
Allows the user to interrupt long-running queries. Wrapper aroundsqlite3_interrupt and causes other data-fetching functions to bepassed an err with code = sqlite3.INTERRUPT. The database must beopen to use this function.
Return the number of listeners listening to a given event.
Inherited from EventEmitter.listenerCount
Return the listeners registered for a given event.
Inherited from EventEmitter.listeners
Loads a compiled SQLite extension into the database connection object.
Optionalcallback:ErrorCallbackIf provided, this function will be called when the extensionwas loaded successfully or when an error occurred. The first argument is anerror object. When it is null, loading succeeded. If no callback is providedand an error occurred, an error event with the error object as the only parameterwill be emitted on the database object.
Optionalfn:(...args:any[])=>voidOptionalcontext:anyOptionalonce:booleanInherited from EventEmitter.off
Add a listener for a given event.
Optionalcontext:anyInherited from EventEmitter.on
Add a one-time listener for a given event.
Optionalcontext:anyInherited from EventEmitter.once
Prepares the SQL statement and optionally binds the specified parameters andcalls the callback when done. The function returns a Statement object.When preparing was successful, the first and only argument to the callbackis null, otherwise it is the error object. When bind parameters are supplied,they are bound to the prepared statement before calling the callback.
Remove all listeners, or those of the specified event.
Optionalevent:string|symbolInherited from EventEmitter.removeAllListeners
Remove the listeners of a given event.
Optionalfn:(...args:any[])=>voidOptionalcontext:anyOptionalonce:booleanInherited from EventEmitter.removeListener
Runs the SQL query with the specified parameters and calls the callback afterwards.The callback will contain the results passed back from the server, for example in thecase of an update or insert, these would contain the number of rows modified, etc.It does not retrieve any result data. The function returns the Database object forwhich it was called to allow for function chaining.
Optionalcallback:ResultsCallback<T>Runs the SQL query with the specified parameters and calls the callback afterwards.The callback will contain the results passed back from the server, for example in thecase of an update or insert, these would contain the number of rows modified, etc.It does not retrieve any result data. The function returns the Database object forwhich it was called to allow for function chaining.
Optionalcallback:ResultsCallback<T>Sql is a promise based API for executing SQL statements. You canpass a simple string with a SQL statement or a template stringusing backticks and parameters in ${parameter} format. These parameterswill be properly escaped and quoted like when using a prepared statement.
A sql string or a template string inbackticks format
An array of rows in case of selections or an object withmetadata in case of insert, update, delete.