mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
becca conversion WIP
This commit is contained in:
parent
1af10d48a2
commit
77eac8f764
@ -75,24 +75,6 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
*/
|
||||
this.getAttribute = becca.getAttribute;
|
||||
|
||||
/**
|
||||
* Retrieves first entity from the SQL's result set.
|
||||
*
|
||||
* @method
|
||||
* @param {string} SQL query
|
||||
* @param {Array.<?>} array of params
|
||||
* @returns {Entity|null}
|
||||
*/
|
||||
this.getEntity = repository.getEntity;
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @param {string} SQL query
|
||||
* @param {Array.<?>} array of params
|
||||
* @returns {Entity[]}
|
||||
*/
|
||||
this.getEntities = repository.getEntities;
|
||||
|
||||
/**
|
||||
* This is a powerful search method - you can search by attributes and their values, e.g.:
|
||||
* "#dateModified =* MONTH AND #log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search
|
||||
|
@ -79,6 +79,21 @@ class Becca {
|
||||
getOption(name) {
|
||||
return this.options[name];
|
||||
}
|
||||
|
||||
getEntityFromName(entityName, entityId) {
|
||||
if (!entityName || !entityId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const camelCaseEntityName = entityName.toLowerCase().replace(/(_[a-z])/g,
|
||||
group =>
|
||||
group
|
||||
.toUpperCase()
|
||||
.replace('_', '')
|
||||
);
|
||||
|
||||
return this[camelCaseEntityName][entityId];
|
||||
}
|
||||
}
|
||||
|
||||
const becca = new Becca();
|
||||
|
@ -6,16 +6,6 @@ const eventService = require('./events');
|
||||
const cls = require('./cls');
|
||||
const entityConstructor = require('../entities/entity_constructor');
|
||||
|
||||
function getEntityFromName(entityName, entityId) {
|
||||
if (!entityName || !entityId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const constructor = entityConstructor.getEntityFromEntityName(entityName);
|
||||
|
||||
return getEntity(`SELECT * FROM ${constructor.entityName} WHERE ${constructor.primaryKeyName} = ?`, [entityId]);
|
||||
}
|
||||
|
||||
function getEntities(query, params = []) {
|
||||
const rows = sql.getRows(query, params);
|
||||
|
||||
@ -151,9 +141,6 @@ function updateEntity(entity) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getEntityFromName,
|
||||
getEntities,
|
||||
getEntity,
|
||||
getNote,
|
||||
updateEntity
|
||||
};
|
||||
|
@ -2,6 +2,7 @@ const ScriptContext = require('./script_context');
|
||||
const repository = require('./repository');
|
||||
const cls = require('./cls');
|
||||
const log = require('./log');
|
||||
const becca = require("./becca/becca.js");
|
||||
|
||||
async function executeNote(note, apiParams) {
|
||||
if (!note.isJavaScript() || note.getScriptEnv() !== 'backend' || !note.isContentAvailable) {
|
||||
@ -54,7 +55,7 @@ async function executeBundle(bundle, apiParams = {}) {
|
||||
async function executeScript(script, params, startNoteId, currentNoteId, originEntityName, originEntityId) {
|
||||
const startNote = becca.getNote(startNoteId);
|
||||
const currentNote = becca.getNote(currentNoteId);
|
||||
const originEntity = repository.getEntityFromName(originEntityName, originEntityId);
|
||||
const originEntity = becca.getEntityFromName(originEntityName, originEntityId);
|
||||
|
||||
currentNote.content = `return (${script}\r\n)(${getParams(params)})`;
|
||||
currentNote.type = 'code';
|
||||
|
Loading…
x
Reference in New Issue
Block a user