mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 10:55:55 +01:00
basic entities for attributes (unification of labels and relations)
This commit is contained in:
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
|
||||
};
|
||||
Reference in New Issue
Block a user