mirror of
https://github.com/zadam/trilium.git
synced 2024-09-29 12:05:58 +08:00
26 lines
540 B
JavaScript
26 lines
540 B
JavaScript
"use strict";
|
|
|
|
const utils = require('../services/utils');
|
|
const repository = require('../services/repository');
|
|
|
|
class Entity {
|
|
constructor(row = {}) {
|
|
utils.assertArguments(row);
|
|
|
|
for (const key in row) {
|
|
this[key] = row[key];
|
|
}
|
|
}
|
|
|
|
beforeSaving() {
|
|
if (!this[this.constructor.primaryKeyName]) {
|
|
this[this.constructor.primaryKeyName] = utils.newEntityId();
|
|
}
|
|
}
|
|
|
|
async save() {
|
|
await repository.updateEntity(this);
|
|
}
|
|
}
|
|
|
|
module.exports = Entity; |