Lawnchair-IndexedDB不支持多个记录 [英] Lawnchair-IndexedDB doesn't support multiple records
问题描述
我尝试在indexed-db中创建多个记录,但不允许我,例如nike和adidas objectStores
I tried creating multiple records in indexed-db but it won't allow me, example, nike and adidas objectStores
var nike = Lawnchair({adapter:'indexed-db', name:'stores', record:'nike'},function(e){
console.log("nike store open");
this.save({id:1}, function(data){
console.log('nike data: ', data);
});
});
var adidas = Lawnchair({adapter:'indexed-db', name:'stores', record:'adidas'},function(e){
console.log("adidas store open");
this.save({id:1}, function(data){
console.log('adidas data: ', data);
});
});
我认为这是在indexed-db中创建多个记录的方法.它实际上是在request.onupgradeneeded上发生的.参见下面的代码.
I think this is how to create multiple records in indexed-db. It actually happens on request.onupgradeneeded. See code below.
// Handle datastore upgrades.
request.onupgradeneeded = function(e) {
var db = e.target.result;
var nike = db.createObjectStore('nike');
var adidas = db.createObjectStore('adidas');
};
如果我无法创建adidas记录,则实际上是访问它时抛出的错误.
If I can't create an adidas record this is actually the error that is thrown when accessing it.
[Exception... "The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened." code: "8" ...]
推荐答案
Lawnchair设计用于无模式的用例.为每个Lawnchair实例使用单独的数据库.
Lawnchair is designed for schemaless use case. Use separate database for each Lawnchair instance.
如果您确实需要一个数据库中的多个表,则可以使用其他库,例如我自己的ydn-db.
If you really need multiple tables in an database, you other libraries, like my own, ydn-db.
这篇关于Lawnchair-IndexedDB不支持多个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!