Movatterモバイル変換


[0]ホーム

URL:


@sqlitecloud/drivers
    Preparing search index...

    Class Database

    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.

    Hierarchy

    • EventEmitter
      • Database
    Index

    Constructors

    constructor

    Properties

    Staticprefixed

    prefixed:string|boolean

    Inherited from EventEmitter.prefixed

    • Defined in node_modules/eventemitter3/index.d.ts:9

    Methods

    addListener

    all

    • all<T>(sql:string,callback?:RowsCallback<T>):this

      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.

      Type Parameters

      • T

      Parameters

      • sql:string
      • Optionalcallback:RowsCallback<T>

      Returnsthis

    • all<T>(sql:string,params:any,callback?:RowsCallback<T>):this

      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.

      Type Parameters

      • T

      Parameters

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

      Returnsthis

    close

    • close(callback?:ErrorCallback):void

      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.

      Parameters

      Returnsvoid

    configure

    each

    • each<T>(
          sql:string,
          callback?:RowCallback<T>,
          complete?:RowCountCallback,
      ):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 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.

      Type Parameters

      • T

      Parameters

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

      Returnsthis

    • each<T>(
          sql:string,
          params:any,
          callback?:RowCallback<T>,
          complete?:RowCountCallback,
      ):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 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.

      Type Parameters

      • T

      Parameters

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

      Returnsthis

    emit

    eventNames

    exec

    • exec(sql:string,callback?:ErrorCallback):this

      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.

      Parameters

      Returnsthis

    get

    • get<T>(sql:string,callback?:RowCallback<T>):this

      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.

      Type Parameters

      • T

      Parameters

      • sql:string
      • Optionalcallback:RowCallback<T>

      Returnsthis

    • get<T>(sql:string,params:any,callback?:RowCallback<T>):this

      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.

      Type Parameters

      • T

      Parameters

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

      Returnsthis

    getConfiguration

    getPubSub

    • getPubSub():Promise<PubSub>

      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.

      ReturnsPromise<PubSub>

      A PubSub object

    interrupt

    • interrupt():void

      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.

      Returnsvoid

    isConnected

    listenerCount

    listeners

    loadExtension

    • loadExtension(_path:string,callback?:ErrorCallback):this

      Loads a compiled SQLite extension into the database connection object.

      Parameters

      • _path:string
      • Optionalcallback:ErrorCallback

        If 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.

      Returnsthis

    off

    on

    once

    prepare

    • prepare<T=any>(sql:string,...params:any[]):Statement<T>

      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.

      Type Parameters

      • T =any

      Parameters

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

      ReturnsStatement<T>

    removeAllListeners

    removeListener

    run

    • run<T>(sql:string,callback?:ResultsCallback<T>):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 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.

      Type Parameters

      • T

      Parameters

      Returnsthis

    • run<T>(sql:string,params:any,callback?:ResultsCallback<T>):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 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.

      Type Parameters

      • T

      Parameters

      Returnsthis

    sql

    • sql(
          sql:string|SQLiteCloudCommand|TemplateStringsArray,
          ...values:any[],
      ):Promise<any>

      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.

      Parameters

      • sql:string|SQLiteCloudCommand|TemplateStringsArray

        A sql string or a template string inbackticks format

      • ...values:any[]

      ReturnsPromise<any>

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

    verbose

    Settings

    Member Visibility

    On This Page

    Constructors
    Properties
    Methods

    [8]ページ先頭

    ©2009-2025 Movatter.jp