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 calls the optional provided callback. If the connection cannot be established an error event will be emitted and the optional callback is called with the error information.

Hierarchy

  • EventEmitter
    • Database

Constructors

Properties

prefixed: string | boolean

Methods

  • Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • fn: (...args: any[]) => void
    • Optionalcontext: any

    Returns this

  • Runs the SQL query with the specified parameters and calls the callback with all result rows afterwards. The function returns the Database object to allow for function chaining. The parameters are the same as the Database#run function, with the following differences: The signature of the callback is function(err, rows) {}. rows is an array. 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.

    Type Parameters

    • T

    Parameters

    • sql: string
    • Optionalcallback: RowsCallback<T>

    Returns this

  • Runs the SQL query with the specified parameters and calls the callback with all result rows afterwards. The function returns the Database object to allow for function chaining. The parameters are the same as the Database#run function, with the following differences: The signature of the callback is function(err, rows) {}. rows is an array. 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.

    Type Parameters

    • T

    Parameters

    • sql: string
    • params: any
    • Optionalcallback: RowsCallback<T>

    Returns this

  • If the optional callback is provided, this function will be called when the database was closed successfully or when an error occurred. The first argument is an error object. When it is null, closing succeeded. If no callback is provided and an error occurred, an error event with the error object as the only parameter will be emitted on the database object. If closing succeeded, a close event with no parameters is emitted, regardless of whether a callback was provided or not.

    Parameters

    Returns void

  • Set a configuration option for the database

    Parameters

    • _option: string
    • _value: any

    Returns this

  • 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 the same as the Database#run function, with the following differences: The signature of the callback is 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 correspond exactly to the order of rows in the result set. After all row callbacks were called, the completion callback will be called if present. The first argument is an error object, and the second argument is 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 function will 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 no way to abort execution.

    Type Parameters

    • T

    Parameters

    • sql: string
    • Optionalcallback: RowCallback<T>
    • Optionalcomplete: RowCountCallback

    Returns this

  • 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 the same as the Database#run function, with the following differences: The signature of the callback is 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 correspond exactly to the order of rows in the result set. After all row callbacks were called, the completion callback will be called if present. The first argument is an error object, and the second argument is 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 function will 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 no way to abort execution.

    Type Parameters

    • T

    Parameters

    • sql: string
    • params: any
    • Optionalcallback: RowCallback<T>
    • Optionalcomplete: RowCountCallback

    Returns this

  • Calls each of the listeners registered for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • ...args: any[]

    Returns boolean

  • Return an array listing the events for which the emitter has registered listeners.

    Returns (string | symbol)[]

  • 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 a transaction if you want all or none to be executed). When all statements have been executed successfully, or when an error occurs, the callback function is called, with the first parameter being either null or an error object. When no callback is provided and an error occurs, an error event will be emitted on the database object.

    Parameters

    Returns this

  • Runs the SQL query with the specified parameters and calls the callback with a subsequent result row. The function returns the Database object to allow for function chaining. The parameters are the same as the Database#run function, with the following differences: The signature of the callback is function(err, row) {}. If the result set is empty, the second parameter is undefined, otherwise it is an object containing the values for the first row. 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.

    Type Parameters

    • T

    Parameters

    • sql: string
    • Optionalcallback: RowCallback<T>

    Returns this

  • Runs the SQL query with the specified parameters and calls the callback with a subsequent result row. The function returns the Database object to allow for function chaining. The parameters are the same as the Database#run function, with the following differences: The signature of the callback is function(err, row) {}. If the result set is empty, the second parameter is undefined, otherwise it is an object containing the values for the first row. 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.

    Type Parameters

    • T

    Parameters

    • sql: string
    • params: any
    • Optionalcallback: RowCallback<T>

    Returns this

  • Returns the configuration with which this database was opened. The configuration is readonly and cannot be changed as there may be multiple connections using the same configuration.

    Returns SQLiteCloudConfig

    A configuration object

  • PubSub class provides a Pub/Sub real-time updates and notifications system to allow multiple applications to communicate with each other asynchronously. It allows applications to subscribe to tables and receive notifications whenever data changes in the database table. It also enables sending messages to anyone subscribed to a specific channel.

    Returns Promise<PubSub>

    A PubSub object

  • Allows the user to interrupt long-running queries. Wrapper around sqlite3_interrupt and causes other data-fetching functions to be passed an err with code = sqlite3.INTERRUPT. The database must be open to use this function.

    Returns void

  • Return the number of listeners listening to a given event.

    Parameters

    • event: string | symbol

    Returns number

  • Return the listeners registered for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T

    Returns (...args: any[]) => void[]

  • Loads a compiled SQLite extension into the database connection object.

    Parameters

    • _path: string
    • Optionalcallback: ErrorCallback

      If provided, this function will be called when the extension was loaded successfully or when an error occurred. The first argument is an error object. When it is null, loading succeeded. If no callback is provided and an error occurred, an error event with the error object as the only parameter will be emitted on the database object.

    Returns this

  • Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • Optionalfn: (...args: any[]) => void
    • Optionalcontext: any
    • Optionalonce: boolean

    Returns this

  • Add a listener for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • fn: (...args: any[]) => void
    • Optionalcontext: any

    Returns this

  • Add a one-time listener for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • fn: (...args: any[]) => void
    • Optionalcontext: any

    Returns this

  • Prepares the SQL statement and optionally binds the specified parameters and calls the callback when done. The function returns a Statement object. When preparing was successful, the first and only argument to the callback is null, otherwise it is the error object. When bind parameters are supplied, they are bound to the prepared statement before calling the callback.

    Type Parameters

    • T = any

    Parameters

    • sql: string
    • ...params: any[]

    Returns Statement<T>

  • Remove all listeners, or those of the specified event.

    Parameters

    • Optionalevent: string | symbol

    Returns this

  • Remove the listeners of a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • Optionalfn: (...args: any[]) => void
    • Optionalcontext: any
    • Optionalonce: boolean

    Returns this

  • 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 the case 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 for which it was called to allow for function chaining.

    Type Parameters

    • T

    Parameters

    Returns this

  • 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 the case 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 for which it was called to allow for function chaining.

    Type Parameters

    • T

    Parameters

    Returns this

  • Sql is a promise based API for executing SQL statements. You can pass a simple string with a SQL statement or a template string using backticks and parameters in ${parameter} format. These parameters will be properly escaped and quoted like when using a prepared statement.

    Parameters

    • sql: string | SQLiteCloudCommand | TemplateStringsArray

      A sql string or a template string in backticks format

    • ...values: any[]

    Returns Promise<any>

    An array of rows in case of selections or an object with metadata in case of insert, update, delete.