mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
support for updating entities etc.
This commit is contained in:
parent
6fa6891496
commit
35c7b54176
@ -3,6 +3,8 @@
|
|||||||
const Entity = require('./entity');
|
const Entity = require('./entity');
|
||||||
|
|
||||||
class Attribute extends Entity {
|
class Attribute extends Entity {
|
||||||
|
static get tableName() { return "attributes"; }
|
||||||
|
|
||||||
async getNote() {
|
async getNote() {
|
||||||
return this.repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
return this.repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ const utils = require('../services/utils');
|
|||||||
|
|
||||||
class Entity {
|
class Entity {
|
||||||
constructor(repository, row) {
|
constructor(repository, row) {
|
||||||
utils.assertArguments(repository, row)
|
utils.assertArguments(repository, row);
|
||||||
|
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
|
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const Entity = require('./entity');
|
const Entity = require('./entity');
|
||||||
|
const protected_session = require('../services/protected_session');
|
||||||
|
|
||||||
class Note extends Entity {
|
class Note extends Entity {
|
||||||
|
static get tableName() { return "notes"; }
|
||||||
|
|
||||||
constructor(repository, row) {
|
constructor(repository, row) {
|
||||||
super(repository, row);
|
super(repository, row);
|
||||||
|
|
||||||
|
if (this.isProtected) {
|
||||||
|
protected_session.decryptNote(this.dataKey, this);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isJson()) {
|
if (this.isJson()) {
|
||||||
this.jsonContent = JSON.parse(this.content);
|
this.jsonContent = JSON.parse(this.content);
|
||||||
}
|
}
|
||||||
@ -30,6 +37,14 @@ class Note extends Entity {
|
|||||||
async getTrees() {
|
async getTrees() {
|
||||||
return this.repository.getEntities("SELECT * FROM note_tree WHERE isDeleted = 0 AND noteId = ?", [this.noteId]);
|
return this.repository.getEntities("SELECT * FROM note_tree WHERE isDeleted = 0 AND noteId = ?", [this.noteId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beforeSaving() {
|
||||||
|
this.content = JSON.stringify(this.jsonContent, null, 4);
|
||||||
|
|
||||||
|
if (this.isProtected) {
|
||||||
|
protected_session.encryptNote(this.dataKey, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Note;
|
module.exports = Note;
|
@ -3,6 +3,8 @@
|
|||||||
const Entity = require('./entity');
|
const Entity = require('./entity');
|
||||||
|
|
||||||
class NoteRevision extends Entity {
|
class NoteRevision extends Entity {
|
||||||
|
static get tableName() { return "note_revisions"; }
|
||||||
|
|
||||||
async getNote() {
|
async getNote() {
|
||||||
return this.repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
return this.repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
const Entity = require('./entity');
|
const Entity = require('./entity');
|
||||||
|
|
||||||
class NoteTree extends Entity {
|
class NoteTree extends Entity {
|
||||||
|
static get tableName() { return "note_tree"; }
|
||||||
|
|
||||||
async getNote() {
|
async getNote() {
|
||||||
return this.repository.getEntity("SELECT * FROM note_tree WHERE isDeleted = 0 AND noteId = ?", [this.noteId]);
|
return this.repository.getEntity("SELECT * FROM note_tree WHERE isDeleted = 0 AND noteId = ?", [this.noteId]);
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,20 @@ class Repository {
|
|||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateEntity(entity) {
|
||||||
|
if (entity.beforeSaving) {
|
||||||
|
entity.beforeSaving();
|
||||||
|
}
|
||||||
|
|
||||||
|
const clone = {...entity};
|
||||||
|
|
||||||
|
delete clone.dataKey;
|
||||||
|
delete clone.jsonContent;
|
||||||
|
delete clone.repository;
|
||||||
|
|
||||||
|
await sql.replace(entity.constructor.tableName, entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Repository;
|
module.exports = Repository;
|
Loading…
x
Reference in New Issue
Block a user