mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 10:40:41 +01:00
basic entities for attributes (unification of labels and relations)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
const build = require('./build');
|
||||
const packageJson = require('../../package');
|
||||
|
||||
const APP_DB_VERSION = 108;
|
||||
const APP_DB_VERSION = 109;
|
||||
const SYNC_VERSION = 1;
|
||||
|
||||
module.exports = {
|
||||
|
||||
52
src/services/attributes.js
Normal file
52
src/services/attributes.js
Normal file
@@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
|
||||
const repository = require('./repository');
|
||||
const Attribute = require('../entities/attribute');
|
||||
|
||||
const BUILTIN_ATTRIBUTES = [
|
||||
'disableVersioning',
|
||||
'calendarRoot',
|
||||
'archived',
|
||||
'excludeFromExport',
|
||||
'run',
|
||||
'manualTransactionHandling',
|
||||
'disableInclusion',
|
||||
'appCss',
|
||||
'hideChildrenOverview'
|
||||
];
|
||||
|
||||
async function getNotesWithAttribute(name, value) {
|
||||
let notes;
|
||||
|
||||
if (value !== undefined) {
|
||||
notes = await repository.getEntities(`SELECT notes.* FROM notes JOIN attributes USING(noteId)
|
||||
WHERE notes.isDeleted = 0 AND attributes.isDeleted = 0 AND attributes.name = ? AND attributes.value = ?`, [name, value]);
|
||||
}
|
||||
else {
|
||||
notes = await repository.getEntities(`SELECT notes.* FROM notes JOIN attributes USING(noteId)
|
||||
WHERE notes.isDeleted = 0 AND attributes.isDeleted = 0 AND attributes.name = ?`, [name]);
|
||||
}
|
||||
|
||||
return notes;
|
||||
}
|
||||
|
||||
async function getNoteWithAttribute(name, value) {
|
||||
const notes = await getNotesWithAttribute(name, value);
|
||||
|
||||
return notes.length > 0 ? notes[0] : null;
|
||||
}
|
||||
|
||||
async function createAttribute(noteId, name, value = "") {
|
||||
return await new Attribute({
|
||||
noteId: noteId,
|
||||
name: name,
|
||||
value: value
|
||||
}).save();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getNotesWithAttribute,
|
||||
getNoteWithAttribute,
|
||||
createAttribute,
|
||||
BUILTIN_ATTRIBUTES
|
||||
};
|
||||
@@ -38,6 +38,10 @@ async function addNoteImageSync(noteImageId, sourceId) {
|
||||
await addEntitySync("note_images", noteImageId, sourceId);
|
||||
}
|
||||
|
||||
async function addAttributeSync(attributeId, sourceId) {
|
||||
await addEntitySync("attributes", attributeId, sourceId);
|
||||
}
|
||||
|
||||
async function addLabelSync(labelId, sourceId) {
|
||||
await addEntitySync("labels", labelId, sourceId);
|
||||
}
|
||||
@@ -104,6 +108,7 @@ async function fillAllSyncRows() {
|
||||
await fillSyncRows("recent_notes", "branchId");
|
||||
await fillSyncRows("images", "imageId");
|
||||
await fillSyncRows("note_images", "noteImageId");
|
||||
await fillSyncRows("attributes", "attributeId");
|
||||
await fillSyncRows("labels", "labelId");
|
||||
await fillSyncRows("relations", "relationId");
|
||||
await fillSyncRows("api_tokens", "apiTokenId");
|
||||
@@ -119,6 +124,7 @@ module.exports = {
|
||||
addRecentNoteSync,
|
||||
addImageSync,
|
||||
addNoteImageSync,
|
||||
addAttributeSync,
|
||||
addLabelSync,
|
||||
addRelationSync,
|
||||
addApiTokenSync,
|
||||
|
||||
@@ -30,6 +30,9 @@ async function updateEntity(sync, entity, sourceId) {
|
||||
else if (entityName === 'note_images') {
|
||||
await updateNoteImage(entity, sourceId);
|
||||
}
|
||||
else if (entityName === 'attributes') {
|
||||
await updateAttribute(entity, sourceId);
|
||||
}
|
||||
else if (entityName === 'labels') {
|
||||
await updateLabel(entity, sourceId);
|
||||
}
|
||||
@@ -174,6 +177,20 @@ async function updateNoteImage(entity, sourceId) {
|
||||
}
|
||||
}
|
||||
|
||||
async function updateAttribute(entity, sourceId) {
|
||||
const origAttribute = await sql.getRow("SELECT * FROM attributes WHERE attributeId = ?", [entity.attributeId]);
|
||||
|
||||
if (!origAttribute || origAttribute.dateModified <= entity.dateModified) {
|
||||
await sql.transactional(async () => {
|
||||
await sql.replace("attributes", entity);
|
||||
|
||||
await syncTableService.addAttributeSync(entity.attributeId, sourceId);
|
||||
});
|
||||
|
||||
log.info("Update/sync attribute " + entity.attributeId);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateLabel(entity, sourceId) {
|
||||
const origLabel = await sql.getRow("SELECT * FROM labels WHERE labelId = ?", [entity.labelId]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user