Flusspferd API and module docs

class sqlite3.SQLite3

Description

SQLite3 is a self-contained, single file based RDBMS. See sqlite3 for an short example.

Constructor

new sqlite3.SQLite3(dsn)
  • dsn (String) – Path to database file, or ‘:memory:’

Opens a handle to the database dsn, which will usually be a filename, but could also be “:memory:”, or any other special string understood by SQLite3.

Class properties

  • version #

    sqlite3.SQLite3.version -> Number

    SQLite3 version as an integer. For example, SQLite v3.6.12 would have a version of 3006012

  • versionStr #

    sqlite3.SQLite3.versionStr -> String

    SQLite3 library version as a human readable string

Instance methods

  • begin #

    sqlite3.SQLite3#begin() ⇒ undefined

    Begin a transaction. See SQLite3 Transactions for details. This method is similar to running dbh.exec('BEGIN WORK').

  • close #

    sqlite3.SQLite3#close() ⇒ undefined

    Close the database handle. Force the database handle to be closed now, instead of when the object gets garbage collected.

  • commit #

    sqlite3.SQLite3#commit() ⇒ undefined

    Commit the current transaction.

  • exec #

    sqlite3.SQLite3#exec(sql[, binds]) ⇒ Number
    • sql (String) – SQL to execute
    • binds (Array | Object) – parameters to bind into sql

    Executes a given SQL statement and optionally, bind parameters can be passed to fill the placeholders in the SQL statement. Returns the number of rows affected by sql

    Note: If the execution throws an exception and the execution is aborted it will not automatically rollback the applied changes. If this is wanted the user of this function has to explicitly take care about it by using sqlite3.SQLite3#begin,sqlite3.SQLite3#commit and sqlite3.SQLite3#rollback.

    Example:
    db.exec('CREATE TABLE foobar (a,b,c)');
    db.exec('INSERT INTO foobar VALUES(?,?,?)',[1,2,3]);
    db.exec('INSERT INTO foobar VALUES(:first, :second, :third)',
            { first: 4, second: 5, third: 6 });
  • execMany #

    sqlite3.SQLite3#execMany(statements) ⇒ Number
    • statements (Array) – an Array of objects with keys sql and bind

    Executes given SQL statement(s). Bind parameters can be passed to fill placeholders used in the corresponding SQL statement.

    The parameter is expected to be an array of objects with sql and optional bind properties. The bind property should contain a value, an array or an object. The object can be used for named placeholders

    Note: If the execution throws an exception and the execution is aborted it will not automatically rollback the applied changes. If this is wanted the user of this function has to explicitly take care about it by using SQLite3#begin,SQLite3#commit and SQLite3#rollback.

    Example
     db.exec([
       { sql: 'CREATE TABLE foobar (a,b,c)'
       },
       { sql: 'INSERT INTO foobar VALUES(?,?,?)',
         bind: [1,2,3]
       },
       { sql: 'INSERT INTO foobar VALUES(:first, :second, :third)',
         bind: { first: 4, second: 5, third: 6 }
       }
     ])
  • lastInsertID #

    sqlite3.SQLite3#lastInsertID() ⇒ Number

    Returns the row id of the last inserted auto-increment column.

  • query #

    sqlite3.SQLite3#query(sql[, bind]) ⇒ sqlite3.SQLite3.Cursor
    • sql (String) – SQL statement to prepare
    • bind (Object | Array) – bind parameters for sql.

    Get a cursor to execute the given SQL statement. Bind parameters can be set at cursor creqation time by passing them in as the second argument, or later by using sqlite3.SQLite3.Cursor#bind.

  • rollback #

    sqlite3.SQLite3#rollback() ⇒ undefined

    Rollback the current transaction without writing the changes to disk.