javascript - large amount of data into indexedDB in Firefox OS -
i have large amount of data want insert indexeddb database.
the size of data 5mb.
and more 77,000 row.
and converted database "all.js" file this:-
const alldata = [ { id: 1, en: "10th", ar: "arabic word" }, { id: 2, en: "1st", ar: "arabic word" }, { id: 3, en: "2nd", ar: "arabic word" }, { id: 4, en: "3rd", ar: "arabic word" }, { id: 5, en: "4th", ar: "arabic word" }, { id: 6, en: "5th", ar: "arabic word" }, { id: 7, en: "6th", ar: "arabic word" }, { id: 8, en: "7th", ar: "arabic word" }, { id: 9, en: "8th", ar: "arabic word" }, 77,000 ];
and code in html , javascript
<!doctype html> <html> <head> <meta charset="utf-8"> <script src="all.js" type="text/javascript"></script> <script type="text/javascript"> /* var custom = [ {"id":1 ,"name":"hussein","email":"test@gmail.com"}, {"id":2 ,"name":"ali","email":"test2@gmail.com"} ]; */ var db; var request = window.indexeddb.open("yesdata13", 1); request.onerror = function(event) { alert("why didn't allow web app use indexeddb?!"); }; request.onsuccess = function(event) { db = event.target.result; /* var transaction = db.transaction(["data"], "readwrite"); transaction.oncomplete = function(event) { alert("all done!"); }; transaction.onerror = function(event) { // don't forget handle errors! }; var objectstore = transaction.objectstore("data"); (var in alldata) { var request = objectstore.add(alldata[i]); request.onsuccess = function(event) { // event.target.result == customerdata[i].ssn; }; } */ }; request.onupgradeneeded = function(event) { var db = event.target.result; var objectstore = db.createobjectstore("data", { keypath: "id" }); //objectstore.createindex("en","en",{unique:true}); //objectstore.createindex("ar","ar",{unique:false}); (var in alldata){ objectstore.put(alldata[i]) } }; /* (var in alldata) { var request = objectstore.add(alldata[i]); request.onsuccess = function(event) { // event.target.result == customerdata[i].ssn; }; } */ function read() { var transaction = db.transaction(["data"]); var objectstore = transaction.objectstore("data"); var request = objectstore.get(25001); request.onerror = function(event) { alert("unable retrieve daa database!"); }; request.onsuccess = function(event) { // request.result! if(request.result) { alert("id: " + request.result.id + ", english: " + request.result.en + ", arabic: " + request.result.ar); } else { alert("kenny couldn't found in database!"); } }; } </script> </head>
click here
the code above work in firefox , google chrome, , of rows inserted. when try in firefox os simulator no working, , when try reduce rows 25,000 work fine.
and try split files 25000 in each file,only first 25,000 added, after 25,000 not added
from own experiments indexeddb on firefox os, seems simulator imposes small limit on amount of data can store indexeddb. tried writing script add bunch of random data single database , simulator didn't give me error stopped allowing me add data after 12,000 entries. if tried create new database simulator gave me error saying quota exceeded.
however when ran on phone, keeps going , going, suspect simulator not representative of actual device since firefox apps supposedly don't impose indexeddb limit. app should work on device if have on available test.
Comments
Post a Comment