标签:sse quic await friends unique ssi 一个 自动 erro
var db = new Dexie("MyDatabase");
db.version(1).stores({
friends: "++id, name, age, *tags",
gameSessions: "id, score"
});
++
Auto-incremented primary key(自动递增的主键)&
Unique(独一无二的索引)*
Multi-entry index(值为数组的索引,可以通过数组中的某一项索引)[A+B]
Compound index(联合索引?)db.version(1).stores({
friends: "++id,name,age,*tags",
gameSessions: "id,score"
});
db.version(2).stores({
friends: "++id, [firstName+lastName], yearOfBirth, *tags", // Change indexes(改变索引)
gameSessions: null // Delete table(删除表)
}).upgrade(tx => {
// Will only be executed if a version below 2 was installed.(当前浏览器数据库版本低于2时触发)
return tx.friends.modify(friend => {
friend.firstName = friend.name.split(' ')[0];
friend.lastName = friend.name.split(' ')[1];
friend.birthDate = new Date(new Date().getFullYear() - friend.age, 0);
delete friend.name;
delete friend.age;
});
});
class Friend {
// Prototype method
save() {
return db.friends.put(this); // Will only save own props.
}
// Prototype property
get age() { // 这里个get 是类中的一个关键字,new Friend().age时会调用该函数
return moment(Date.now()).diff (this.birthDate, 'years'); // moment是一个日期处理库
}
}
db.friends.mapToClass(Friend);
await db.friends.add({name: "Josephine", age: 21});
await db.friends.bulkAdd([
{name: "Foo", age: 31},
{name: "Bar", age: 32}
]);
// 根据对象更新
await db.friends.put({id: 4, name: "Foo", age: 33});
await db.friends.bulkPut([
{id: 4, name: "Foo2", age: 34},
{id: 5, name: "Bar2", age: 44}
]);
// 根据主键更新
await db.friends.update(4, {name: "Bar"});
// 根据搜索结果更新
await db.customers
.where("age")
.inAnyRange([ [0, 18], [65, Infinity] ])
.modify({discount: 0.5});
标签:sse quic await friends unique ssi 一个 自动 erro
原文地址:https://www.cnblogs.com/qq3279338858/p/10980944.html