1
2
3
4
5
6
7
8
9
10
11
| //>>built
| define("dojo/_base/declare dojo/Deferred dojo/when dojo/store/util/QueryResults dojo/_base/lang dojo/promise/all".split(" "),function(t,u,l,v,p,m){function q(a){return a&&p.mixin(a,JSON.parse(a.__extra))}var w=/(.*)\*$/;return t([],{constructor:function(a){var c=a.dbConfig;this.database=openDatabase(a.dbName||"dojo-db","1.0","dojo-db",4194304);var g=this.indexPrefix=a.indexPrefix||"idx_",d=a.table||a.storeName;this.table=(a.table||a.storeName).replace(/[^\w]/g,"_");a=[];this.indices=c.stores[d];this.repeatingIndices=
| {};for(var b in this.indices)this.indices[b].multiEntry&&(this.repeatingIndices[b]=!0);if(!c.available){for(d in c.stores){var h=c.stores[d],k=d.replace(/[^\w]/g,"_"),f=h[this.idProperty],e=["__extra",this.idProperty+" "+(f&&f.autoIncrement?"INTEGER PRIMARY KEY AUTOINCREMENT":"PRIMARY KEY")],f=[this.idProperty];for(b in h)b!=this.idProperty&&e.push(b);a.push(this.executeSql("CREATE TABLE IF NOT EXISTS "+k+" ("+e.join(",")+")"));for(b in h)b!=this.idProperty&&(h[b].multiEntry?(f.push(b),e=k+"_repeating_"+
| b,a.push(this.executeSql("CREATE TABLE IF NOT EXISTS "+e+" (id,value)")),a.push(this.executeSql("CREATE INDEX IF NOT EXISTS idx_"+e+"_id ON "+e+"(id)")),a.push(this.executeSql("CREATE INDEX IF NOT EXISTS idx_"+e+"_value ON "+e+"(value)"))):(a.push(this.executeSql("ALTER TABLE "+k+" ADD "+b).then(null,function(){})),!1!==h[b].indexed&&a.push(this.executeSql("CREATE INDEX IF NOT EXISTS "+g+k+"_"+b+" ON "+k+"("+b+")"))))}c.available=m(a)}this.available=c.available},idProperty:"id",selectColumns:["*"],
| get:function(a){return l(this.executeSql("SELECT "+this.selectColumns.join(",")+" FROM "+this.table+" WHERE "+this.idProperty+"\x3d?",[a]),function(a){return 0<a.rows.length?q(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,c){c=[];var g=[],d=[],b={},h=[],k=this,f;for(f in a)a.hasOwnProperty(f)&&(f in this.indices||f==this.idProperty?
| this.repeatingIndices[f]?h.push(function(c){return m(a[f].map(function(a){return k.executeSql("INSERT INTO "+k.table+"_repeating_"+f+" (value, id) VALUES (?, ?)",[a,c])}))}):(d.push(f),g.push("?"),c.push(a[f])):b[f]=a[f]);d.push("__extra");g.push("?");c.push(JSON.stringify(b));var e=this.idProperty;this.identifyGeneratedKey&&(c.idColumn=e);g="INSERT INTO "+this.table+" ("+d.join(",")+") VALUES ("+g.join(",")+")";return l(this.executeSql(g,c),function(c){var b=c.insertId;a[e]=b;return m(h.map(function(a){return a(b)})).then(function(){return b})})},
| put:function(a,c){c=c||{};var g=c.id||a[this.idProperty],d=c.overwrite;if(void 0===d){var b=this;return this.get(g).then(function(e){return(c.overwrite=!!e)?(c.overwrite=!0,b.put(a,c)):b.add(a,c)})}if(!d)return b.add(a,c);var d="UPDATE "+this.table+" SET ",h=[],k=[],f={},e;for(e in a)if(a.hasOwnProperty(e))if(e in this.indices||e==this.idProperty)if(this.repeatingIndices[e]){this.executeSql("DELETE FROM "+this.table+"_repeating_"+e+" WHERE id\x3d?",[g]);for(var r=a[e],n=0;n<r.length;n++)this.executeSql("INSERT INTO "+
| this.table+"_repeating_"+e+" (value, id) VALUES (?, ?)",[r[n],g])}else k.push(e+"\x3d?"),h.push(a[e]);else f[e]=a[e];k.push("__extra\x3d?");h.push(JSON.stringify(f));d+=k.join(",")+" WHERE "+this.idProperty+"\x3d?";h.push(a[this.idProperty]);return l(this.executeSql(d,h),function(a){return g})},query:function(a,c){function g(a){var c=[],b;for(b in a){var e=function(a){var b=a&&a.match&&a.match(w);if(b)return f.push(b[1]+"%")," LIKE ?";f.push(a);return"\x3d?"},d=a[b];if(d)if(d.contains){var g=h.table+
| "_repeating_"+b;c.push(d.contains.map(function(a){return h.idProperty+" IN (SELECT id FROM "+g+" WHERE value"+e(a)+")"}).join(" AND "));continue}else if("object"==typeof d&&("from"in d||"to"in d)){var l=d.excludeFrom?"\x3e":"\x3e\x3d",m=d.excludeTo?"\x3c":"\x3c\x3d";"from"in d?(f.push(d.from),"to"in d?(f.push(d.to),c.push("("+k+"."+b+l+"? AND "+k+"."+b+m+"?)")):c.push(k+"."+b+l+"?")):(f.push(d.to),c.push(k+"."+b+m+"?"));continue}c.push(k+"."+b+e(d))}return c.join(" AND ")}c=c||{};var d="FROM "+this.table,
| b,h=this,k=this.table,f=[];a.forEach?(b=a.map(g).join(") OR ("))&&(b="("+b+")"):b=g(a);b&&(b=" WHERE "+b);c.sort&&(b+=" ORDER BY "+c.sort.map(function(a){return k+"."+a.attribute+" "+(a.descending?"desc":"asc")}));a=b;c.count&&(a+=" LIMIT "+c.count);c.start&&(a+=" OFFSET "+c.start);c=p.delegate(this.executeSql("SELECT * "+d+a,f).then(function(a){for(var b=[],c=0;c<a.rows.length;c++)b.push(q(a.rows.item(c)));return b}));h=this;c.total={then:function(a,c){return h.executeSql("SELECT COUNT(*) "+d+b,
| f).then(function(a){return a.rows.item(0)["COUNT(*)"]}).then(a,c)}};return new v(c)},executeSql:function(a,c){var g=new u,d,b;this.database.transaction(function(h){h.executeSql(a,c,function(a,b){g.resolve(d=b)},function(a,c){g.reject(b=c)})});if(d)return d;if(b)throw b;return g.promise}})});
|
|