我可以使用 jsstore 在 indexeddb 中拥有多个数据库吗

Can I have multiple database in indexeddb using jsstore

我可以在 indexeddb 中使用 angular2 中的 jsstore 拥有多个数据库吗?

请指导我如何实现这一目标。请提供语法。

这会降低性能吗?

下面是我的服务代码

constructor(private _http:Http)
{
    this._connection=new JsStore.Instance();
    let that=this, dbName='DTSubscription';
    JsStore.isDbExist(dbName,function(isExist)
    {
        if(isExist)
        {
            that._connection.openDb(dbName);
        }
        else
        {
            const Database=that.GetDatabase();
            that._connection.createDb(Database);
        }
    },function(err)
    {
        alert(err.Message);
    });

    this._connection=new JsStore.Instance();
    let t=this, db2='DTSubscriptionNew';
    JsStore.isDbExist(db2,function(isExist)
    {
        if(isExist)
        {
            t._connection.openDb(db2);
        }
        else{
            const Database2=t.GetDatabase2();
            t._connection.createDb(Database2);
        }
    },function(err)
    {
    alert(err.Message);
    });
}

数据库已创建。但是在插入时我需要提到 db 否则它会给出这样的错误 -

{ 姓名:"table_not_exist", 消息:"Table 'ArticleNew' does not exist" }

我可以看到数据库在那里。

您可以创建多个数据库,但一次只能创建一个。因此,如果您想在应用程序中使用两个数据库 - 通过调用 'openDb' api.

更改数据库

因此,如果您的数据库是 - DTSubscription、DTSubscriptionNew

当您想对数据库执行查询时 - DTSubscription。查询将是这样的 -

var Connection = new JsStore.Instance();
Connection.openDb('DTSubscription');

当你想为数据库执行查询时 - 'DTSubscriptionNew'

Connection.openDb('DTSubscriptionNew');

由于您使用的是angular2,我建议为两个数据库定义两个服务并保持JsStore 连接通用。这样特定的服务将执行特定数据库的查询。

有关如何使用它的更多信息,请查看在 jsstore 中使用两个数据库的演示项目 -

https://github.com/ujjwalguptaofficial/multipledb-in-jsstore

更新

从 JsStore v4 开始,您可以对多个数据库使用多个连接,所有这些都将并行工作。