To prevent any frustration, it's recommend to read the full documentation before start using jsdb.
During the work on my current project, I was looking for a possibility to avoid the lot of XMLHttpRequests.
I think, less server requests makes any application less error-prone and let you work much faster.
The script was written to develop AJAX applications.
It's enough to read the database once while loading the site.
All changes while working can be cached into jsdb and stored periodic or just if the work is over.JSDB - JavaScript Runtime Database
Copyright (C) 2007 Ingo Volkmann
Visit my site and get in contact with me at godiv.deThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
The installation is very simple.
Copy the jsdb.js file to your webserver.
Put <script type="text/javascript" language="javascript" src="jsdb.js"></script> between the <head></head> tags of your page.
Don't forget to adjust the 'src' attribute if the jsdb.js file is not located in the same directory as your page.
all global vars and functions are prefixed by jsdb to prevent any collisions with your own scripts
'where' - clause is sometimes optional and sometimes needed
'and' - arguments are optional and not limited
make sure, that 'where' and 'and' are given as strings and in pairs of 3 - columnName, operator, matchedData
valid operators for 'where' and 'and' are '==' and '!=' only
'order' - arguments are optional and limited by 1 - (I hope I'll find a way for more arguments in later versions)
make sure, that 'order' is given as strings and in pairs of 2 - columnName, asc or desc
the returned array will be ordered as exact as possible because of missing a real natsort function
optional parameters must be always set to 'false' if they are not needed
Expects 1 parameter - an array with the column names.
The first column will always be the auto incremented id and can get addressed like all the other columns.
Do NOT create a column called 'id' by your own!var cols = new Array('name', 'mail', 'whatever');
var myFirstTable = new jsdbTable(cols);
Expects 1 parameter - an array with the data.
var data = new Array('someData', 'someData', 'someData');
myFirstTable.insertRow(data);
Expects 3 parameters - an array with the data, an array with the 'where' clause and an optional array with additional 'and'-arguments or 'false' if not needed.
Pay attention to use a valid syntax!var where = new Array('columnName', 'Operator', 'matchedData');
var data = new Array('columnName', 'newData', 'columnName', 'newData');
var and = new Array('columnName', 'Operator', 'matchedData', 'columnName', 'Operator', 'matchedData');
myFirstTable.updateRow(data, where, and);
Expects 2 parameters - an array with the 'where' clause and an optional array with additional 'and'-arguments or 'false' if not needed.
var where = new Array('columnName', 'Operator', 'matchedData');
var and = new Array('columnName', 'Operator', 'matchedData', 'columnName', 'Operator', 'matchedData');
myFirstTable.deleteRow(where, and);
Expects 3 parameters - an optional array with the 'where' clause or 'false' if not needed, an optional array with additional 'and'-arguments or 'false' if not needed and an optional array with the 'order'-arguments or 'false' if not needed.
var where = new Array('columnName', 'Operator', 'matchedData');
var and = new Array('columnName', 'Operator', 'matchedData', 'columnName', 'Operator', 'matchedData');
var order = new Array('columnName', 'asc/desc');
var row = myFirstTable.selectRow(where, false, order);
for( var i=0; i < row.length; i++ )
alert( row[i].columnName );
- raise order arguments
- implement joins