1
2
3
4
5
6
7
8
9
10
11
12
13
14
| //>>built
| define("dojo/_base/declare dojo/Deferred dojo/when dstore/QueryResults dstore/Store dstore/SimpleQuery dojo/_base/lang dojo/promise/all".split(" "),function(v,w,n,x,y,z,q,p){function r(a,c){c=c.split(".");for(var k=c.length,f=0;f<k;f++)a=a&&a[c[f]];return a}function m(a){return a.replace(/\./g,"_dot_")}function t(a){return a&&a.__extra?q.mixin(a,JSON.parse(a.__extra)):a}var u={and:" AND ",or:" OR ",eq:"\x3d",ne:"!\x3d",lte:"\x3c\x3d",gte:"\x3e\x3d",lt:"\x3c",gt:"\x3e"};return v([y,z],{constructor:function(a){var c=
| a.dbConfig;this.database=openDatabase(a.dbName||"dojo-db","1.0","dojo-db",4194304);var k=this.indexPrefix=a.indexPrefix||"idx_",f=a.table||a.storeName;this.table=(a.table||a.storeName).replace(/[^\w]/g,"_");a=[];this.indices=c.stores[f];this.repeatingIndices={};for(var d in this.indices)this.indices[d].multiEntry&&(this.repeatingIndices[d]=!0);if(!c.available){for(f in c.stores){var e=c.stores[f],g=f.replace(/[^\w]/g,"_"),l=e[this.idProperty],b=["__extra",this.idProperty+" "+(l&&l.autoIncrement?"INTEGER PRIMARY KEY AUTOINCREMENT":
| "PRIMARY KEY")],l=[this.idProperty];for(d in e)d!=this.idProperty&&b.push(m(d));a.push(this.executeSql("CREATE TABLE IF NOT EXISTS "+g+" ("+b.join(",")+")"));for(d in e)d!=this.idProperty&&(e[d].multiEntry?(l.push(d),b=g+"_repeating_"+m(d),a.push(this.executeSql("CREATE TABLE IF NOT EXISTS "+b+" (id,value)")),a.push(this.executeSql("CREATE INDEX IF NOT EXISTS idx_"+b+"_id ON "+b+"(id)")),a.push(this.executeSql("CREATE INDEX IF NOT EXISTS idx_"+b+"_value ON "+b+"(value)"))):(a.push(this.executeSql("ALTER TABLE "+
| g+" ADD "+m(d)).then(null,function(){})),!1!==e[d].indexed&&a.push(this.executeSql("CREATE INDEX IF NOT EXISTS "+k+g+"_"+m(d)+" ON "+g+"("+m(d)+")"))))}c.available=p(a)}this.available=c.available},idProperty:"id",selectColumns:["*"],get:function(a){var c=this;return n(this.executeSql("SELECT "+this.selectColumns.join(",")+" FROM "+this.table+" WHERE "+this.idProperty+"\x3d?",[a]),function(a){return 0<a.rows.length?c._restore(t(a.rows.item(0))):void 0})},getIdentity:function(a){return a[this.idProperty]},
| remove:function(a){return this.executeSql("DELETE FROM "+this.table+" WHERE "+this.idProperty+"\x3d?",[a])},identifyGeneratedKey:!0,add:function(a){function c(a,c,b){l.repeatingIndices[b||a]?g.push(function(b){return p(c.map(function(c){return l.executeSql("INSERT INTO "+l.table+"_repeating_"+a+" (value, id) VALUES (?, ?)",[c,b])}))}):(d.push(a),f.push("?"),k.push(c))}var k=[],f=[],d=[],e={},g=[],l=this,b;for(b in a)a.hasOwnProperty(b)&&(b in this.indices||b==this.idProperty?c(b,a[b]):e[b]=a[b]);
| for(b in this.indices)-1<b.indexOf(".")&&c(m(b),r(a,b),b);d.push("__extra");f.push("?");k.push(JSON.stringify(e));var h=this.idProperty;this.identifyGeneratedKey&&(k.idColumn=h);e="INSERT INTO "+this.table+" ("+d.join(",")+") VALUES ("+f.join(",")+")";return n(this.executeSql(e,k),function(c){var b=l.indices[h];if(b&&b.autoIncrement){var d=c.insertId;a[h]=d}else d=a[h];return p(g.map(function(a){return a(d)})).then(function(){return d})})},put:function(a,c){function k(a,c,b){if(e.repeatingIndices[b||
| a])for(e.executeSql("DELETE FROM "+e.table+"_repeating_"+a+" WHERE id\x3d?",[f]),b=0;b<c.length;b++)e.executeSql("INSERT INTO "+e.table+"_repeating_"+a+" (value, id) VALUES (?, ?)",[c[b],f]);else l.push(a+"\x3d?"),g.push(c)}c=c||{};var f=c.id||a[this.idProperty],d=c.overwrite;if(void 0===d){var e=this;return this.get(f).then(function(b){return(c.overwrite=!!b)?(c.overwrite=!0,e.put(a,c)):e.add(a,c)})}if(!d)return e.add(a,c);var d="UPDATE "+this.table+" SET ",g=[],l=[],b={},e=this,h;for(h in a)a.hasOwnProperty(h)&&
| (h in this.indices||h==this.idProperty?k(h,a[h]):b[h]=a[h]);for(h in this.indices)-1<h.indexOf(".")&&k(m(h),r(a,h),h);l.push("__extra\x3d?");g.push(JSON.stringify(b));d+=l.join(",")+" WHERE "+this.idProperty+"\x3d?";g.push(a[this.idProperty]);return n(this.executeSql(d,g),function(){return f})},fetchRange:function(a){return this.fetch(a)},generateSql:function(){function a(a){if(a.match(/[^\w_\.]/))throw new URIError("Illegal column name "+a);return b+"."+m(a)}function c(d){var f=d.args,e=f[0],g=f[1];
| switch(d.type){case "eq":case "ne":case "lt":case "lte":case "gt":case "gte":return h.push(g),[a(e),u[d.type]+"?"];case "and":case "or":e=[];for(g=0;g<f.length;g++)e.push(c(f[g]).join(""));return["(",e.join(u[d.type]),")"];case "in":return 0===g.length?"0\x3d1":g.generateSql?(d=g.generateSql(),h.push.apply(h,d.params),[a(e)," IN ("+d.select+d.from+")"]):[a(e)," IN ("+f[1].map(function(a){h.push(a);return"?"}).join(",")+")"];case "contains":var k=b+"_repeating_"+e;return["(",g.map(function(b){b&&b.type?
| b="value "+c(b).slice(1).join(""):(h.push(b),b="value\x3d?");return a(l.idProperty)+" IN (SELECT id FROM "+k+" WHERE "+b+")"}).join(" AND "),")"];case "match":g=g.source;if("^"!==g[0]||g.match(/[\{\}\(\)\[\]\.\,\$\*]/))throw Error("The match filter only supports simple prefix matching like /^starts with/");return[b+"."+e," LIKE '"+g.slice(1).replace(/'/g,"''")+"%'"];default:throw new URIError("Invalid query syntax, "+d.type+" not implemented");}}var k="FROM "+this.table,f="",d="",e="*",g,l=this,b=
| this.table,h=[];this.queryLog.forEach(function(b){if("filter"===b.type)f=(f?" AND ":"")+c(b.normalizedArguments[0]).join("");else if("sort"===b.type)d=" ORDER BY "+b.normalizedArguments[0].map(function(b){return a(b.property)+" "+(b.descending?"desc":"asc")}).join(",");else if("select"===b.type){var h=b.normalizedArguments[0];if(h instanceof Array){for(var k=0;k<h.length;k++)if(!(h[k]in l.indices)){g=b;return}e=h.map(a).join(", ")}else h in l.indices&&(e=a(h)),g=b}});f&&(f=" WHERE "+f);return{select:"SELECT "+
| e+" ",from:k+f+d,params:h,querier:g&&g.querier}},fetch:function(a){a=a||{};var c=this.generateSql(),k=c.from,f=c.params,d=c.querier,c=c.select+" "+k;a.end&&(c+=" LIMIT "+(a.end-(a.start||0)));a.start&&(c+=" OFFSET "+a.start);var e=this;a=q.delegate(this.executeSql(c,f).then(function(a){for(var c=[],b=0;b<a.rows.length;b++)c.push(e._restore(t(a.rows.item(b))));d&&(c=d(c));return c}));e=this;return new x(a,{totalLength:{then:function(a,c){return e.executeSql("SELECT COUNT(*) "+k,f).then(function(a){return a.rows.item(0)["COUNT(*)"]}).then(a,
| c)}}})},executeSql:function(a,c){var k=new w,f,d;this.database.transaction(function(e){e.executeSql(a,c,function(a,c){k.resolve(f=c)},function(a,c){k.reject(d=c)})});if(f)return f;if(d)throw d;return k.promise}})});
|
|