opendatabase

0.2.1 • Public • Published

opendatabase

A WebSql standardized Sqlite3 wrapper for Nodejs

NPM

Author: Robert Edward Steckroth II

Digital Persona: Surgemcgee, Bustout RobertSteckroth@gmail.com

License: GNU GENERAL PUBLIC LICENSE Version 3

Features:

  • Modified Sqlite3 binaries to efficiently support this module
  • Low overhead (no regex or looping mechanisms are used).
  • Conforms to WebSql practices

Caveats:

  1. Data type assignment is not supported. All "?" replacements will be inserted as a STRING into the database
  2. Synchronous database calls (Although the module utilizes asynchronous practice).
  3. Database initialize version and size attributes are superficial (not important).
NOTE: opendatabase works the same way as WebSql. The WebSql documentation should be suitable to learn this module.

Description:

This module conforms to the WebSql standard. However, some WebSql features are not integrated yet (see caveats above). A modified version of the Sqlite3 binaries is used to format json data and efficiently integrated into nodejs. Query results are stored statically into JavaScript objects and retrieved via object keys. The module has no dependencies other than the Sqlite3 binaries distributed with it. The install_sqlite3_json.sh script in the base directory compiles and install this module into the correct directory for use with the opendatabase module.

// Example opendatabase run through

var path = require('path'),
        opendatabase = require('opendatabase')

var database_dir = path.join(path.dirname(__filename), 'test_openDatabase.sqlite')
var open_db = new opendatabase({name: database_dir, version: "1.0", description: "Example database for indurate.js", size: 3*1024*1024})


var log = function(message) {
    console.log('[opendatabase test script] '+message)

}

var err = function(tx, error) {
    console.log(error.message+'Code: '+error.code)
    // tx object is here as well
    log('inserting data into table from the error callback..')
    tx.executeSql('INSERT OR REPLACE INTO opendb_test VALUES(?, ?);', ['Column 1 text', 'Column 2 text'], function(tx, results) {
        log('Successfully created new table with sql command --> '+results.rows.sql+'\nResults length is '+results.rows.length+'\nRow Affected: '+results.rowsAffected+'\nInsert Id '+results.insertId)
        log('\n\n-- This should indicate that your opendatabase module is working correctly. --')
    }, err) // <-- !THIS WILL BE CALLED IN A INFINATE LOOP IF THE TX RETURNS AN ERROR

}


log('Opening a new transaction..')
open_db.transaction(function(tx) {
    log('Creating a new table if not exists..')
    tx.executeSql('CREATE TABLE IF NOT EXISTS opendb_test(? TEXT UNIQUE, ? TEXT);', ['name', 'column_field'], function(tx, results) {
        log('Successfully created new table with sql command --> '+results.rows.sql+'\nResults length is '+results.rows.length+'\nRow Affected: '+results.rowsAffected+'\nInsert Id '+results.insertId)
        log('Inserting a table with a bad sql command (syntax errors)..')
        tx.executeSql('INSERT OR REPdLACE INTO opendb_test VALUES(?, ?);', ['Column 1 text', 'Column 2 text'], function(tx, results) {
            log('This can\'t happen because the command syntax is bad')
        }, err) // Call this due to syntax errors
    }, err)

})

The Indurate.js wrapper for opendatabase is the recomended way to manage your server/phonegap application database needs

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i opendatabase

      Weekly Downloads

      2

      Version

      0.2.1

      License

      GNU v3

      Last publish

      Collaborators

      • surgemcgee