jaydata indexedDb joined database -


i have created sample database , test scripts it. database structure is:

enter image description here

i have created jsfiddle it: fiddle click buttons except stress test on top, click tests.

the problem is, works provider websql, fails on provider indexeddb. downloaded pro packages , makes test 3 work partially still fails on test 2 completely. problem found when query database join relation(ex: employees in department.id 1) indexeddb cannot process request.

how can circumvent situation?

whole code is:

index.html:

<!doctype html> <html> <head>   <meta charset="utf-8">   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>   <script src="jaydatapro/jaydata.min.js"></script>   <script src="jaydatapro/jaydataproviders/indexeddbproprovider.min.js"></script>   <script src="jaydatapro/jaydataproviders/sqliteproprovider.min.js"></script>   <script src="jaydatapro/jaydataproviders/webapiprovider.min.js"></script>   <script src="jaydatapro/jaydataproviders/yqlprovider.min.js"></script>   <script src="sampledatabase.js"></script>   <script src="test.js"></script>   <title>jaydata test</title> </head>  <body>   <div>     <h3>database generation</h3>     <div>       <button onclick="testadddepartments(5);">add departments</button>     </div>     <div>       <button onclick="addemployeelist(testemployeelist(1,100),1);"> employees 1</button>       <button onclick="addemployeelist(testemployeelist(101,100),2);">employees 2</button>       <button onclick="addemployeelist(testemployeelist(201,100),3);">employees 3</button>       <button onclick="addemployeelist(testemployeelist(301,100),4);">employees 4</button>       <button onclick="addemployeelist(testemployeelist(401,100),5);">employees 5</button>     </div>     <div>       <button onclick="addstocklist(teststocklist(1,400),1);">       stocks 1</button>       <button onclick="addstocklist(teststocklist(401,400),2);">       stocks 2</button>       <button onclick="addstocklist(teststocklist(801,400),3);">       stocks 3</button>       <button onclick="addstocklist(teststocklist(1201,400),4);">       stocks 4</button>       <button onclick="addstocklist(teststocklist(1601,400),5);">       stocks 5</button>     </div>     <div>       <button onclick="addstocklist(teststocklist(2001,5000),2);">       stress test test 3</button>     </div>   </div>   <div>     <h3>queries</h3>       <button onclick="testsearchemployeename1()">test 1</button>       <button onclick="testsearchemployeename2()">test 2</button>       <button onclick="testsearchemployeename3()">test 3</button>   </div>   <div>     <h3>results</h3>     <p id='result'>result</p>   </div> </body> </html> 

sampledatabase.js:

/*   x database   database name company   company has 3 tables:     =departments       -id(key,computed)       -departmentname(string,required)     =employees       -id(key,computed)       -name(string,required)     =stocks       -id(key,computed)       -description(string)       -numitems(int,required)   employee connected department   stock connected department   department has list of stocks , employees do:   -insert websql , indexeddb translations document */    $data.entity.extend("org.employee",{   id: {key: true, type: "integer", computed: true},   name: {type: "string", required: true},   department: {type: "org.department", inverseproperty: "employees"} });  $data.entity.extend("org.stock",{   id: {key: true, type: "integer", computed: true},   description: {type: "string"},   numitems: {type: "integer", required: true},   department: {type: "org.department", inverseproperty: "stocks"} });  $data.entity.extend("org.department",{   id: {key: true, type: "integer", computed: true},   departmentname: {type: "string", required: true},   employees:{type: array, elementtype: "org.employee", inverseproperty:"department"},   stocks:{type: array, elementtype: "org.stock", inverseproperty:"department"} });  $data.entitycontext.extend("company",{   employees: {type: $data.entityset, elementtype: org.employee},   departments: {type: $data.entityset, elementtype: org.department},   stocks: {type: $data.entityset, elementtype: org.stock} });  var x= new company({   provider: "indexeddb",   databasename: "db",   version: 1,   dbcreation: $data.storageproviders.dbcreationtype.dropallexistingtables });  function addemployee(emp,department) {   x.departments.first(     function(it){       return it.id==department.valueof()     },      {emp:emp,department:department},      function(dep){       x.departments.attach(dep);       emp.department=dep;       x.employees.add(emp);       x.employees.savechanges();     }   ); }  function removeemployee(emp_id) {   x.employees.first(     function(res){       return res.id==emp_id.valueof();     },     {emp_id:emp_id},     function(emp)     {       x.employees.remove(emp);       x.employees.savechanges();     }   );   }  function changeemployeename(emp_id,new_name) {   x.employees.first(     function(res){       return res.id==emp_id.valueof();     },     {emp_id:emp_id,new_name:new_name},     function(emp)     {       x.employees.attach(emp);       emp.name=new_name;       x.employees.savechanges();     }   ); }  function removedepartment(dep_id) {   x.employees.filter(     function(res){       return res.department.id==dep_id     },     {dep_id:dep_id}   ).foreach(     function(it){       x.employees.remove(it)     });   x.employees.savechanges();   x.departments.first(     function(it)     {       return it.id==dep_id;     },     {dep_id:dep_id},     function(dep)     {       x.departments.remove(dep);       x.departments.savechanges();     }   ); }  function addstock(stock,department) {   x.departments.first(     function(it){       return it.id==department.valueof()},        {emp:emp,department:department},        function(dep){         x.departments.attach(dep);         stock.department=dep;         x.stocks.add(stock);         x.stocks.savechanges();       }); }  function addemployeelist(list,department) {   x.departments.first(     function(it){return it.id==department.valueof()},      {department:department,list:list},      function(dep){       (var = 0; < list.length; i++) {         list[i].department=dep;       };       x.departments.attach(dep);       x.employees.addmany(list);       x.employees.savechanges();     }); }  function addstocklist(list,department) {   x.departments.first(     function(it){return it.id==department.valueof()},      {department:department,list:list},      function(dep){       (var = 0; < list.length; i++) {         list[i].department=dep;       };       x.departments.attach(dep);       x.stocks.addmany(list);       x.stocks.savechanges();     }); } 

test.js:

//testing script  function testadddepartments(number)   //number of departments {   var dep='department';   (var = 1; <= number.valueof(); i++)   {     var temp=dep+i.tostring();     x.departments.add({departmentname:temp});   };   x.departments.savechanges(); }  function testemployeelist(start,number) {   emp_list=new array();   var emp='employee';   (var = start.valueof(); < start.valueof()+number.valueof(); i++)   {     var temp=emp+i.tostring();     emp_list.push({name:temp});   };   return emp_list; }  function teststocklist(start,number) {   stock_list=new array();   var stock='stock';   (var = start.valueof(); < start.valueof()+number.valueof(); i++)   {     var temp=stock+i.tostring();     var num=math.floor((math.random()*1000)+1);     stock_list.push({description:temp,numitems:num});   };   return stock_list; }  /*function testsearchemployeename(number,limit) {   var start= new date().gettime();   var emp='employee';   (var = 1; <= number.valueof(); i++)   {     num=math.floor((math.random()*limit.valueof())+1);     search=emp+num.tostring();     x.employees.filter(       function(res)       {         return res.name==search;       }).     foreach(       function(it)       {         console.log(it.name);       });   };   var elapsed=new date().gettime()-start;   console.log("searching database "+number.tostring()+     " entries took "+elapsed.tostring()+" milliseconds"); } */  //static tests function testsearchemployeename1() {   var start= new date().gettime();   x.employees.filter(     function(res)     {       return res.name=='employee43';     },{start:start}).   toarray(function(it){     var elapsed=new date().gettime()-start;     var res="query "+it.length.tostring()+" result took "+       elapsed.tostring()+" milliseconds";     document.getelementbyid('result').innerhtml = res;   },{start:start}   ); }  function testsearchemployeename2() {   var start= new date().gettime();   x.employees.filter(     function(res)     {       return res.department.id==1;     },{start:start}).   toarray(function(it){     var elapsed=new date().gettime()-start;     var res="query "+it.length.tostring()+" results took "+       elapsed.tostring()+" milliseconds";     document.getelementbyid('result').innerhtml = res;   },{start:start}   ); }  function testsearchemployeename3() {   var start= new date().gettime();   x.stocks.filter(     function(res)     {       return res.numitems>258 || res.department.id<3;     },{start:start}).   toarray(function(it){     var elapsed=new date().gettime()-start;     var res="query "+it.length.tostring()+" results took "+       elapsed.tostring()+" milliseconds";     document.getelementbyid('result').innerhtml = res;   },{start:start}   ); } 

according provider feature matrix, include() , complex type mapping features aren't implemented yet indexeddb, means cannot have navigation properties in indexeddb, in sqlite/websql. can propose feature @ user voice page.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -