You've already forked joplin
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:
32
ReactNativeClient/lib/models/NoteResource.js
Normal file
32
ReactNativeClient/lib/models/NoteResource.js
Normal 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;
|
||||
Reference in New Issue
Block a user