mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
feat: impl fully indexed & searchable data stores
This commit is contained in:
48
packages/core/database/persistentmap.js
Normal file
48
packages/core/database/persistentmap.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import Indexer from "./indexer";
|
||||
import Storage from "./storage";
|
||||
|
||||
export default class PersistentMap {
|
||||
/**
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {Storage} storage
|
||||
*/
|
||||
constructor(key, storage) {
|
||||
this.key = key;
|
||||
this.indexer = new Indexer(storage, key);
|
||||
}
|
||||
|
||||
init() {
|
||||
return this.indexer.init();
|
||||
}
|
||||
|
||||
async set(key, value) {
|
||||
await this.indexer.write(key, value);
|
||||
await this.indexer.index(key);
|
||||
}
|
||||
|
||||
async delete(key) {
|
||||
await this.indexer.remove(key);
|
||||
await this.indexer.deindex(key);
|
||||
}
|
||||
|
||||
get(key) {
|
||||
return this.indexer.read(key);
|
||||
}
|
||||
|
||||
has(key) {
|
||||
return this.indexer.exists(key);
|
||||
}
|
||||
|
||||
async clear() {
|
||||
await this.indexer.clear();
|
||||
}
|
||||
|
||||
async values() {
|
||||
const data = await this.indexer.readMulti(this.indexer.indices);
|
||||
return data.reduce((total, current) => {
|
||||
total.push(current[1]);
|
||||
return total;
|
||||
}, []);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user