indurate
Version:
Indurate.js is an asynchronous sqlite3 wrapper for the openDatabase module.
42 lines (41 loc) • 7.45 kB
JSON
{
"name": "indurate",
"description": "Indurate.js is an asynchronous sqlite3 wrapper for the openDatabase module.",
"version": "0.2.0",
"private": false,
"homepage": "https://bitbucket.org/surgemcgee/indurate-database/src",
"repository": {
"type": "hg",
"url": "https://bitbucket.org/surgemcgee/indurate-database/src"
},
"author": {
"name": "Robert Steckroth",
"email": "RobertSteckroth@gmail.com",
"url": "http://www.surgemcgee.com"
},
"main": "indurate_1.2",
"keywords": [
"indurate",
"openDatabase",
"WebSql",
"wrapper",
"sqlite3",
"sqlite"
],
"dependencies": {
"opendatabase": "0.2.0"
},
"readmeFilename": "README.md",
"license": "GNU v3",
"_npmUser": {
"name": "surgemcgee",
"email": "robertsteckroth@gmail.com"
},
"readme": "# Indurate Database \n## A wrapper to WebSql and node [openDatabase](https://npmjs.org/package/opendatabase/) \n[](https://nodei.co/npm/indurate/)\n\n**Author:** Robert Edward Steckroth II\n\n**Digital Persona:** Surgemcgee, Bustout <RobertSteckroth@gmail.com>\n\n**Licence:** GNU GENERAL PUBLIC LICENSE Version 3\n \n**Description:**\n\nIndurate.js is a user friendly API for server and mobile applications. Indurate uses WebSql node openDatabase with a strong object oriented structure. Indurate can provide database driven applications or supplement existing mobile applications.\n\n**Features:**\n\n* Efficient design\n* Simple table management\n* Pretty database and table printing\n* Asynchronous or synchronous code structure\n\n\n###_Example usage_\n\n```\nvar path = require('path'),\n Indurate = require('indurate')\n\n\nfunction log(message) {\n console.log('[Indurate Test Server] '+message)\n}\n\nvar server_db = function() {\n\n this.appcwd = path.dirname(__filename)\n this.database_dir = path.join(this.appcwd, 'Indurate_test_database.sqlite')\n this.db = new Indurate({name: this.database_dir, version: \"1.0\", description: \"Example database for indurate.js\", size: 3})\n\n}\n\n\nserver_db.prototype = {\n\n get_set_test: function(t_name) {\n var newThis = this // Gots to have the scope cheat to be functional\n var table_object = {}\n // First array value will be used as the primary key/object identifier\n // If the table was created outside of Indurate, the first column in the table will be used as the primary key\n this[t_name] = this.db.initTable(t_name, ['key', 'name', 'last_updated', 'has_failed'], function() {\n log('Initializing table '+this.name)\n this.getTable(function(table, out) {\n log('Fetching table '+this.name+' as js object')\n\n log('Retrieved '+out.rows.length+' from '+this.name) // This.name is the table name passed into initTable\n log('Table has columns: '+this.columns)\n log('Table colums is stored in results as a array '+out.rows.info().toString())\n log('The second paramater is optional and WebSql compliant./nout.rows.length: '+out.rows.length+'\\nout.rows.item(0): ')\n console.dir(out.rows.item(0))\n log('Table columns are stored in results.rows.info() as an array '+out.rows.info().toString())\n table_object = table\n table_object['my_key'] = {}\n table_object['my_key'].name = 'Cool yo'\n table_object['my_key'].last_updated = new Date()\n table_object['my_key'].has_failed = false\n\n this.set(table_object, function(){\n // Set it the table with the values we built in the getTable() call\n this.describe(function(output) { log(output) }) // Provide us with pretty printing of the table\n\n })\n })\n })\n\n },\n\n change_table_test: function(t_name, key, name, value) {\n // If the table exists, the column fields are ignored so we will leave it empty here for convenience\n this[t_name].getTable(function(t_obj) { // Second paramater (WebSql) is ommited here which uses less memory\n console.dir(t_obj)\n log('Columns in table '+this.name+' are '+this.columns.toString())\n if ( t_obj[key] ) // Does the rows/key exists? We can also check this.columns or out.row.info() in here\n t_obj[key][name] = value\n this.set(t_obj, function() {\n this.describe() // All callbacks are optional and will log to console if not provided\n })\n })\n },\n\n\n}\n\n\nvar tests = new server_db()\n\n\ntests.get_set_test('my_table1')\nsetTimeout(function(){\n tests.change_table_test('my_table1', 'my_key', 'name', 'Surgemcgee') // DON'T SO THIS TOO QUICK. Remember that Indurate is asynchronous\n}, 1000)\n\n\n```\n\n\n_example output table describe_ \n````\n___________________________________________________________________________________________\n|key |name |last_updated |has_failed|\n|___________|__________________________|_______________________________________|__________|\n|my_key . . |Surgemcgee . . . . . . . .|Sat Oct 26 2013 10:58:54 GMT-0400 (EDT)|false . . |\n|another_key|Robert Edward Steckroth II|Sat Oct 26 2013 10:52:52 GMT-0400 (EDT)|No way! . |\n|___________|__________________________|_______________________________________|__________|\n````\n\n_example output show database_ \n````\n| Show Database: example Version: 1.0 Size(bytes): 3145728\t Description: Example database for indurate.js\n| Rows: 5\t Columns: 5\n______________________________________________________________________________________________________________________________________________________________________________________________________________________\n|type |name |tbl_name |rootpage|sql |\n|_____|___________________________|___________________________|________|_____________________________________________________________________________________________________________________________________________|\n|table|__WebKitDatabaseInfoTable__|__WebKitDatabaseInfoTable__|3 . . . |CREATE TABLE __WebKitDatabaseInfoTable__ (key TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,value TEXT NOT NULL ON CONFLICT FAIL)|\n|table|userTable . . . . . . . . .|userTable . . . . . . . . .|5 . . . |CREATE TABLE userTable(name TEXT UNIQUE, value TEXT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |\n|table|peopleTable . . . . . . . .|peopleTable . . . . . . . .|7 . . . |CREATE TABLE peopleTable(name TEXT UNIQUE, value TEXT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |\n|_____|___________________________|___________________________|________|_____________________________________________________________________________________________________________________________________________| \n````\n\n\n\n\n \n\n",
"_id": "indurate@0.1.7",
"_from": "indurate@",
"dist": {
"shasum": "34a63e715ccf645e9bb81188d7ec6f18528f9dff"
},
"_resolved": "https://registry.npmjs.org/indurate/-/indurate-0.1.6.tgz"
}