You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-23 22:36:32 +02:00
This commit is contained in:
@@ -4,6 +4,7 @@ import uuid from './uuid';
|
||||
import time from './time';
|
||||
import JoplinDatabase, { TableField } from './JoplinDatabase';
|
||||
import { LoadOptions, SaveOptions } from './models/utils/types';
|
||||
import ActionLogger, { ItemActionType as ItemActionType } from './utils/ActionLogger';
|
||||
import { SqlQuery } from './services/database/types';
|
||||
const Mutex = require('async-mutex').Mutex;
|
||||
|
||||
@@ -41,6 +42,9 @@ export interface DeleteOptions {
|
||||
|
||||
disableReadOnlyCheck?: boolean;
|
||||
|
||||
// Used for logging
|
||||
sourceDescription?: string|ActionLogger;
|
||||
|
||||
// Tells whether the deleted item should be moved to the trash. By default
|
||||
// it is permanently deleted.
|
||||
toTrash?: boolean;
|
||||
@@ -688,13 +692,17 @@ class BaseModel {
|
||||
return output;
|
||||
}
|
||||
|
||||
public static delete(id: string) {
|
||||
public static delete(id: string, options?: DeleteOptions) {
|
||||
if (!id) throw new Error('Cannot delete object without an ID');
|
||||
ActionLogger.from(options?.sourceDescription).log(ItemActionType.Delete, id);
|
||||
|
||||
return this.db().exec(`DELETE FROM ${this.tableName()} WHERE id = ?`, [id]);
|
||||
}
|
||||
|
||||
public static async batchDelete(ids: string[], options: DeleteOptions = null) {
|
||||
public static async batchDelete(ids: string[], options?: DeleteOptions) {
|
||||
if (!ids.length) return;
|
||||
ActionLogger.from(options?.sourceDescription).log(ItemActionType.Delete, ids);
|
||||
|
||||
options = this.modOptions(options);
|
||||
const idFieldName = options.idFieldName ? options.idFieldName : 'id';
|
||||
const sql = `DELETE FROM ${this.tableName()} WHERE ${idFieldName} IN ("${ids.join('","')}")`;
|
||||
|
||||
Reference in New Issue
Block a user