mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 01:03:58 +00:00
small refactor
This commit is contained in:
@@ -98,31 +98,27 @@ export class DatabaseAnalyser {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
createQuery(template, typeFields) {
|
createQuery(template, typeFields) {
|
||||||
let res = template;
|
// let res = template;
|
||||||
if (this.singleObjectFilter) {
|
if (this.singleObjectFilter) {
|
||||||
const { typeField } = this.singleObjectFilter;
|
const { typeField } = this.singleObjectFilter;
|
||||||
if (!this.singleObjectId) return null;
|
if (!this.singleObjectId) return null;
|
||||||
if (!typeFields || !typeFields.includes(typeField)) return null;
|
if (!typeFields || !typeFields.includes(typeField)) return null;
|
||||||
return res.replace(/=OBJECT_ID_CONDITION/g, ` = ${this.singleObjectId}`);
|
return template.replace(/=OBJECT_ID_CONDITION/g, ` = ${this.singleObjectId}`);
|
||||||
}
|
}
|
||||||
if (!this.modifications || !typeFields || this.modifications.length == 0) {
|
if (!this.modifications || !typeFields || this.modifications.length == 0) {
|
||||||
res = res.replace(/=OBJECT_ID_CONDITION/g, ' is not null');
|
return template.replace(/=OBJECT_ID_CONDITION/g, ' is not null');
|
||||||
} else {
|
}
|
||||||
if (this.modifications.some(x => typeFields.includes(x.objectTypeField) && x.action == 'all')) {
|
if (this.modifications.some(x => typeFields.includes(x.objectTypeField) && x.action == 'all')) {
|
||||||
// do not filter objects
|
// do not filter objects
|
||||||
res = res.replace(/=OBJECT_ID_CONDITION/g, ' is not null');
|
return template.replace(/=OBJECT_ID_CONDITION/g, ' is not null');
|
||||||
}
|
}
|
||||||
|
|
||||||
const filterIds = this.modifications
|
const filterIds = this.modifications
|
||||||
.filter(x => typeFields.includes(x.objectTypeField) && (x.action == 'add' || x.action == 'change'))
|
.filter(x => typeFields.includes(x.objectTypeField) && (x.action == 'add' || x.action == 'change'))
|
||||||
.map(x => x.objectId);
|
.map(x => x.objectId);
|
||||||
if (filterIds.length == 0) {
|
if (filterIds.length == 0) {
|
||||||
res = res.replace(/=OBJECT_ID_CONDITION/g, " = '0'");
|
return template.replace(/=OBJECT_ID_CONDITION/g, " = '0'");
|
||||||
} else {
|
|
||||||
res = res.replace(/=OBJECT_ID_CONDITION/g, ` in (${filterIds.map(x => `'${x}'`).join(',')})`);
|
|
||||||
}
|
}
|
||||||
}
|
return template.replace(/=OBJECT_ID_CONDITION/g, ` in (${filterIds.map(x => `'${x}'`).join(',')})`);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getDeletedObjectsForField(snapshot, objectTypeField) {
|
getDeletedObjectsForField(snapshot, objectTypeField) {
|
||||||
|
|||||||
Reference in New Issue
Block a user