mirror of https://github.com/TriliumNext/Notes
basic entity support with lazy loaded relations
parent
b44412bc32
commit
587f3d833e
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
const Entity = require('./entity');
|
||||
|
||||
class Attribute extends Entity {
|
||||
async getNote() {
|
||||
return this.sql.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Attribute;
|
||||
@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
class Entity {
|
||||
constructor(sql, row) {
|
||||
this.sql = sql;
|
||||
|
||||
for (const key in row) {
|
||||
this[key] = row[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Entity;
|
||||
@ -1,20 +1,22 @@
|
||||
"use strict";
|
||||
|
||||
class Note {
|
||||
constructor(sql, row) {
|
||||
this.sql = sql;
|
||||
const Entity = require('./entity');
|
||||
|
||||
for (const key in row) {
|
||||
this[key] = row[key];
|
||||
}
|
||||
class Note extends Entity {
|
||||
async getAttributes() {
|
||||
return this.sql.getEntities("SELECT * FROM attributes WHERE noteId = ?", [this.noteId]);
|
||||
}
|
||||
|
||||
async attributes() {
|
||||
return this.sql.getRows("SELECT * FROM attributes WHERE noteId = ?", [this.noteId]);
|
||||
async getAttribute(name) {
|
||||
return this.sql.getEntity("SELECT * FROM attributes WHERE noteId = ? AND name = ?", [this.noteId, name]);
|
||||
}
|
||||
|
||||
async revisions() {
|
||||
return this.sql.getRows("SELECT * FROM note_revisions WHERE noteId = ?", [this.noteId]);
|
||||
async getRevisions() {
|
||||
return this.sql.getEntities("SELECT * FROM note_revisions WHERE noteId = ?", [this.noteId]);
|
||||
}
|
||||
|
||||
async getTrees() {
|
||||
return this.sql.getEntities("SELECT * FROM note_tree WHERE isDeleted = 0 AND noteId = ?", [this.noteId]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
const Entity = require('./entity');
|
||||
|
||||
class NoteRevision extends Entity {
|
||||
async getNote() {
|
||||
return this.sql.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NoteRevision;
|
||||
@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
const Entity = require('./entity');
|
||||
|
||||
class NoteTree extends Entity {
|
||||
async getNote() {
|
||||
return this.sql.getEntity("SELECT * FROM note_tree WHERE isDeleted = 0 AND noteId = ?", [this.noteId]);
|
||||
}
|
||||
|
||||
async getParentNote() {
|
||||
return this.sql.getEntity("SELECT * FROM note_tree WHERE isDeleted = 0 AND parentNoteId = ?", [this.parentNoteId]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NoteTree;
|
||||
Loading…
Reference in New Issue