mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 10:55:55 +01:00
moved becca to top level source dir
This commit is contained in:
58
src/becca/entity_constructor.js
Normal file
58
src/becca/entity_constructor.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const Note = require('./entities/note.js');
|
||||
const NoteRevision = require('./entities/note_revision.js');
|
||||
const Branch = require('./entities/branch.js');
|
||||
const Attribute = require('./entities/attribute.js');
|
||||
const RecentNote = require('./entities/recent_note.js');
|
||||
const ApiToken = require('./entities/api_token.js');
|
||||
|
||||
const ENTITY_NAME_TO_ENTITY = {
|
||||
"attributes": Attribute,
|
||||
"branches": Branch,
|
||||
"notes": Note,
|
||||
"note_contents": Note,
|
||||
"note_revisions": NoteRevision,
|
||||
"note_revision_contents": NoteRevision,
|
||||
"recent_notes": RecentNote,
|
||||
"api_tokens": ApiToken,
|
||||
};
|
||||
|
||||
function getEntityFromEntityName(entityName) {
|
||||
if (!(entityName in ENTITY_NAME_TO_ENTITY)) {
|
||||
throw new Error(`Entity for table ${entityName} not found!`);
|
||||
}
|
||||
|
||||
return ENTITY_NAME_TO_ENTITY[entityName];
|
||||
}
|
||||
|
||||
function createEntityFromRow(row) {
|
||||
let entity;
|
||||
|
||||
if (row.attributeId) {
|
||||
entity = new Attribute(row);
|
||||
}
|
||||
else if (row.noteRevisionId) {
|
||||
entity = new NoteRevision(row);
|
||||
}
|
||||
else if (row.branchId && row.notePath) {
|
||||
entity = new RecentNote(row);
|
||||
}
|
||||
else if (row.apiTokenId) {
|
||||
entity = new ApiToken(row);
|
||||
}
|
||||
else if (row.branchId) {
|
||||
entity = new Branch(row);
|
||||
}
|
||||
else if (row.noteId) {
|
||||
entity = new Note(row);
|
||||
}
|
||||
else {
|
||||
throw new Error('Unknown entity type for row: ' + JSON.stringify(row));
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createEntityFromRow,
|
||||
getEntityFromEntityName
|
||||
};
|
||||
Reference in New Issue
Block a user