mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 06:29:29 +01:00
feat: impl database structure
This commit is contained in:
33
packages/core/database/indexer.js
Normal file
33
packages/core/database/indexer.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import Storage from "./storage";
|
||||
|
||||
export default class Indexer extends Storage {
|
||||
constructor(context, type) {
|
||||
super(context);
|
||||
this.type = type;
|
||||
this.indices = [];
|
||||
}
|
||||
|
||||
async initIndexer() {
|
||||
this.indices = (await this.read(this.type)) || [];
|
||||
}
|
||||
|
||||
async index(key) {
|
||||
if (this.indices.length <= 0) {
|
||||
this.indices = (await this.read(this.type)) || [];
|
||||
}
|
||||
this.indices[this.indices.length] = key;
|
||||
await this.write(this.type, this.indices);
|
||||
}
|
||||
|
||||
async getIndices() {
|
||||
if (this.indices.length <= 0) {
|
||||
this.indices = (await this.read(this.type)) || [];
|
||||
}
|
||||
return this.indices;
|
||||
}
|
||||
|
||||
async deindex(key) {
|
||||
this.indices.splice(this.indices.indexOf(key), 1);
|
||||
await this.write(this.type, this.indices);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user