javascript - 在 Dexie 数据库模式中指定不同的唯一键?

标签 javascript indexeddb dexie

我的基本 dexie 数据库方案是这样的。

const db = new Dexie('MyDatabase');

// Declare tables, IDs and indexes
db.version(1).stores({
    myrecords: 'record_id'
});

我想使用我的 record_id 作为唯一 key 。在indexeddb中我可以像下面这样做

 var myrecordsObjectStore = db.createObjectStore('myrecords' , {
                                keyPath: 'record_id'
                            });

最佳答案

应该使用 & 前缀来实现唯一,如文档中所述

db.version(1).stores({
    myrecords: '&record_id'
});

参见Dexie Quick Reference

关于javascript - 在 Dexie 数据库模式中指定不同的唯一键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58050976/

相关文章:

javascript - 存储和同步数据库架构

javascript - 替换多列中多行中的值,为每列提供一个映射对象

Dexie.js-table.delete(id)不适用于逐行删除

javascript - Vue : How does vuetify make its components available without import?

javascript - 索引数据库。如何在光标移动时更新记录

javascript - 在 Firefox 中打开 IndexedDB 时出现 InvalidStateError

node.js - Dexie.js : get failures data records in bulkAdd() error catch

javascript - 如何在 Android 上以编程方式退出全屏视频?

javascript - Modal 关闭时播放 Bootstrap 轮播

c# - 如何从 Razor 切换到普通的旧 HTML?