basic search tests

This commit is contained in:
zadam
2020-05-22 09:38:30 +02:00
parent cd48135394
commit ee053b9fdf
17 changed files with 202 additions and 44 deletions

View File

@@ -11,34 +11,20 @@ const Attribute = require('./entities/attribute');
async function load() {
await sqlInit.dbReady;
noteCache.notes = await getMappedRows(`SELECT noteId, title, isProtected FROM notes WHERE isDeleted = 0`,
row => new Note(noteCache, row));
noteCache.reset();
noteCache.branches = await getMappedRows(`SELECT branchId, noteId, parentNoteId, prefix FROM branches WHERE isDeleted = 0`,
row => new Branch(noteCache, row));
(await sql.getRows(`SELECT noteId, title, isProtected FROM notes WHERE isDeleted = 0`, []))
.map(row => new Note(noteCache, row));
noteCache.attributeIndex = [];
(await sql.getRows(`SELECT branchId, noteId, parentNoteId, prefix FROM branches WHERE isDeleted = 0`, []))
.map(row => new Branch(noteCache, row));
noteCache.attributes = await getMappedRows(`SELECT attributeId, noteId, type, name, value, isInheritable FROM attributes WHERE isDeleted = 0`,
row => new Attribute(noteCache, row));
(await sql.getRows(`SELECT attributeId, noteId, type, name, value, isInheritable FROM attributes WHERE isDeleted = 0`, [])).map(row => new Attribute(noteCache, row));
noteCache.loaded = true;
noteCache.loadedResolve();
}
async function getMappedRows(query, cb) {
const map = {};
const results = await sql.getRows(query, []);
for (const row of results) {
const keys = Object.keys(row);
map[row[keys[0]]] = cb(row);
}
return map;
}
eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED, eventService.ENTITY_SYNCED], async ({entityName, entity}) => {
// note that entity can also be just POJO without methods if coming from sync