1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-18 23:07:45 +02:00

Desktop, Cli: Fixes #2331: Only de-duplicate imported notebook titles when needed

This commit is contained in:
Laurent Cozic
2020-06-28 18:00:51 +01:00
parent d601575549
commit eb8841379c
4 changed files with 68 additions and 4 deletions

View File

@ -284,6 +284,21 @@ class BaseModel {
return this.modelSelectOne(sql, [fieldValue]);
}
static loadByFields(fields, options = null) {
if (!options) options = {};
if (!('caseInsensitive' in options)) options.caseInsensitive = false;
if (!options.fields) options.fields = '*';
const whereSql = [];
const params = [];
for (const fieldName in fields) {
whereSql.push(`\`${fieldName}\` = ?`);
params.push(fields[fieldName]);
}
let sql = `SELECT ${this.db().escapeFields(options.fields)} FROM \`${this.tableName()}\` WHERE ${whereSql.join(' AND ')}`;
if (options.caseInsensitive) sql += ' COLLATE NOCASE';
return this.modelSelectOne(sql, params);
}
static loadByTitle(fieldValue) {
return this.modelSelectOne(`SELECT * FROM \`${this.tableName()}\` WHERE \`title\` = ?`, [fieldValue]);
}