This is a ScriptDB API for JavaScript.
The tests that are referred to in scriptDB API for JavaScript are implemented in https://storage.googleapis.com/toasty/t/gas/scriptdbapi.html. Code is below
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>scriptDB data input - ramblings.mcpher.com</title> <link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/toasty/cdn/css/d3flights.css"> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript" src="https://apis.google.com/js/client.js"></script> <script type="text/javascript" src="js/scriptdbapi.js"></script> <script type="text/javascript" src="js/firsttime.js"></script> <script type="text/javascript" src="https://storage.googleapis.com/toasty/cdn/js/ccookie.js"></script> <script type="text/javascript"> /* v1.0 */ // do various test excercises on cScrptDbCom class (function () { google.load("jquery", "1"); google.setOnLoadCallback(function() { // these create cookies with credentials for scriptdbAPI, // They only need to be run once for a pc, so they should be in some different script firstTimeReadonly(); firstTimeTest(); // copy a couple of classes from the primer database to the test one testCopy() .done (function() { // do a query------ var dbCustomer = getScriptDb("VBAParseCustomers","dbTest"); dbCustomer.getObjectsByQuery({country:"United States"}) .done (function (data,cob) { renderScriptDb(data.results,'#countryquery'); }) // look up date in another table based on data in another var dbData = getScriptDb("VBAParseData","dbTest"); // restrict to paricular customers dbCustomer.getObjectsByQuery({country:"United States"}) .done (function (data,cob) { $('#matchquery').html(''); for ( var i = 0 ; i < data.results.length;i++) { printTransaction (dbData,data.results[i]); } }) }); function printTransaction (dbData,result) { dbData.getObjectsByQuery({customerid:result.customerid}) .done (function (transaction,cob) { if (transaction.results.length) { $('#matchquery').append(JSON.stringify( { country:result.country, name:result.name, transaction:transaction.results }) + '<br>'); } }); } }); })(); function testCopy() { // do the copies simulatneously var dd = dbCopy ("primer", "dbTest", "VBAParseData"); var dc = dbCopy ("primer", "dbTest", "VBAParseCustomers"); // report when done showCount (dd,'#countcopydata'); showCount (dc,'#countcopycustomers'); // we can return a promise for them all being done return $.when(dd,dc); // show counts function showCount (promise, elemID ) { promise .done (function(pData,cob) { cob.getCount() .done (function (data) { renderScriptDb(data.count,elemID); }) .fail(function (error) { renderScriptDb(JSON.stringify(error),elemID); }); }) .fail(function(error) { alert (JSON.stringify(error)); }); } function dbCopy( source, target , cls) { var dbSource = getScriptDb(cls,source); var dbTarget = getScriptDb(cls,target); var d= $.Deferred(); //delete everything in source db of this class if (!(dbTarget && dbSource)) { d.reject ("scriptdbs not opened"); } else { dbTarget.deleteObjects() .done( function() { // get the whole thing dbSource.getAllMatchingQueries() .done (function (data){ // copy to target dbTarget.createObjects(data); // clear anything in batch not yet done. dbTarget.finalFlush() .done(function(data,cob){ d.resolve(data,cob); }) .fail(function(error,cob){ d.reject(error,cob); }); }) .fail ( function (error,cob){ // failed to do a query alert (JSON.stringify(error)); }); }) .fail( function (error,cob){ // didnt manage to delete it alert (JSON.stringify(error)); }); } return d.promise(); } } /* display contents of some object at given element * @param {object} control some object * @param {string} id the id of the element * @return {null} */ function renderScriptDb(control,id) { $(id).text(JSON.stringify(control)); } </script> </head> <body> <div> <h2>Test scriptdb query access</h2> </div> <div><h2>after copy<br></h2> <div><b>Count on customers</b><div id="countcopycustomers"></div></div> <div><b>Count on data</b><div id="countcopydata"></div></div> <div><b>object query</b><div id="countryquery"></div></div> <div><b>match query</b><div id="matchquery"></div></div> </div> </div> </body> </html>
These are the results you should see, once the copy has completed
Test scriptdb query access after copy Count on customers 100 Count on data 308 object query [{"region":"Castilla y León","zip":"B9L 8T4","city":"Segovia","country":"United States","customerid":97,"email":"nascetur@orciUt.net","address":"P.O. Box 271, 4700 Tellus St.","objectId":"S333422122829","name":"Nash","company":"Nascetur Ridiculus Institute","coordinates":"53.60934, 6.94959"},{"region":"GO","zip":"D51 4LF","city":"Luziânia","country":"United States","customerid":85,"email":"sit.amet@congueturpis.com","address":"2195 Scelerisque Road","objectId":"S333422122822","name":"Hammond","company":"Consectetuer Rhoncus Nullam Industries","coordinates":"-49.77372, 82.53103"},{"region":"Principado de Asturias","zip":"11713","city":"Oviedo","country":"United States","customerid":37,"email":"quis@anteipsum.org","address":"Ap #770-5598 Faucibus Rd.","objectId":"S333421005208","name":"Lyons","company":"Sed Dolor Fusce Foundation","coordinates":"-36.59556, -133.78963"}] match query {"country":"United States","name":"Hammond","transaction":[{"customerid":85,"objectId":"S333421434339","value":2575,"quantity":5,"date":{"__type":"Date","iso":"2013-07-03T00:00:00.000Z"},"invoiceid":161}]} {"country":"United States","name":"Nash","transaction":[{"customerid":97,"objectId":"S333422178785","value":4800,"quantity":10,"date":{"__type":"Date","iso":"2013-06-02T00:00:00.000Z"},"invoiceid":282},{"customerid":97,"objectId":"S333422758773","value":2800,"quantity":5,"date":{"__type":"Date","iso":"2013-06-30T00:00:00.000Z"},"invoiceid":391}]}
For help and more information join our forum, follow the blog or follow me on Twitter .