2

我尝试在 indexed-db 中创建多个记录,但它不允许我,例如 nike 和 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 上。请参阅下面的代码。

// Handle datastore upgrades.
request.onupgradeneeded = function(e) {
    var db = e.target.result;

    var nike = db.createObjectStore('nike');
    var adidas = db.createObjectStore('adidas');
};

如果我无法创建 adidas 记录,这实际上是访问它时引发的错误。

[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" ...]
4

2 回答 2

1

找到了修复它的方法。我通过records在选项对象上添加一个属性来添加一个补丁。请参阅下面的{适配器...,记录:[...]}。

<script>

    var nike = Lawnchair({adapter:'indexed-db', name:'stores', record:'nike', records:['nike','adidas']},function(e){
        console.log("nike store open", this);
        this.save({id:1}, function(data){
            console.log('nike data: ', data);
        });
    });


    var adidas = Lawnchair({adapter:'indexed-db', name:'stores', record:'adidas', records:['nike','adidas']},function(e){
        console.log("adidas store open");
        this.save({id:1}, function(data){
            console.log('adidas data: ', data);
        });
    });

</script>

在此处查看我的拉取请求:https ://github.com/brianleroux/lawnchair/pull/175

于 2013-08-01T12:01:58.320 回答
1

Lawnchair 专为无模式用例而设计。为每个 Lawnchair 实例使用单独的数据库。

如果您真的需要数据库中的多个表,您可以使用其他库,例如我自己的 ydn-db。

于 2013-07-31T08:56:24.127 回答