我有大量数据要将其插入 indexedDB 数据库。
数据大小约5MB。
并超过 77,000 行。
我将数据库转换为“all.js”文件,如下所示:-
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" },
to about 77,000
];
以及我的 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 you allow my web app to 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 to handle errors!
};
var objectStore = transaction.objectStore("data");
for (var i 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});
for (var i in AllData){
objectStore.put(AllData[i])
}
};
/*
for (var i 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 to retrieve daa from database!");
};
request.onsuccess = function(event) {
// Do something with the request.result!
if(request.result) {
alert("id: " + request.result.id + ", English: " + request.result.en + ", arabic: " + request.result.ar);
} else {
alert("Kenny couldn't be found in your database!");
}
};
}
</script>
</head>
点击这里
上面的代码在 firefox 和 google chrome 中运行良好,并且插入了所有行。但是当在 firefox os 模拟器中尝试它时它不起作用,当尝试将行数减少到 25,000 时它工作正常。
我尝试将其拆分为每个文件中大约 25,000 个文件,仅添加前 25,000 个,但未添加 25,000 个之后