1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Adding service to keep track of note resources associations

This commit is contained in:
Laurent Cozic
2018-03-12 23:40:43 +00:00
parent eef106c99b
commit f595be07d4
9 changed files with 174 additions and 109 deletions

View File

@@ -0,0 +1,32 @@
const BaseModel = require('lib/BaseModel.js');
class NoteResource extends BaseModel {
static tableName() {
return 'note_resources';
}
static modelType() {
return BaseModel.TYPE_NOTE_RESOURCE;
}
static async associate(noteId, resourceIds) {
let queries = [];
queries.push({ sql: 'DELETE FROM note_resources WHERE note_id = ?', params: [noteId] });
for (let i = 0; i < resourceIds.length; i++) {
queries.push({ sql: 'INSERT INTO note_resources (note_id, resource_id) VALUES (?, ?)', params: [noteId, resourceIds[i]] });
}
await this.db().transactionExecBatch(queries);
}
static async remove(noteId) {
let queries = [];
queries.push({ sql: 'DELETE FROM note_resources WHERE note_id = ?', params: [noteId] });
await this.db().transactionExecBatch(queries);
}
}
module.exports = NoteResource;