opendatabase
v0.2.1
Published
The WebSql standard for Nodejs using Sqlite3.
Downloads
32
Readme
#opendatabase
A WebSql standardized Sqlite3 wrapper for Nodejs
Author: Robert Edward Steckroth II
Digital Persona: Surgemcgee, Bustout [email protected]
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:
- SQLResultSet.rowsAffected is not integrated.
- Data type assignment is not supported. All "?" replacements will be inserted as a STRING into the database
- Synchronous database calls (Although the module utilizes asynchronous practice).
- Database init version and size attributes are superficial (not important).
- Only works on Linux varients (developed on Ubuntu)
#####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 inserted data with sql command --> '+results.rows.sql+'\nResults length is '+results.rows.length)
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)
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)
})