of not exitsts fields

This commit is contained in:
Jan Prochazka
2024-07-10 11:57:41 +02:00
parent 4864a376c6
commit 9d5c7e6df2
5 changed files with 59 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ export interface ChangeSetItem {
document?: any;
condition?: { [column: string]: string };
fields?: { [column: string]: string };
insertIfNotExistsFields?: { [column: string]: string };
}
export interface ChangeSetItemFields {
@@ -284,6 +285,9 @@ function changeSetInsertToSql(
targetTable,
commandType: 'insert',
fields,
insertWhereNotExistsCondition: item.insertIfNotExistsFields
? compileSimpleChangeSetCondition(item.insertIfNotExistsFields)
: null,
},
autoInc
? {
@@ -332,6 +336,36 @@ export function extractChangeSetCondition(item: ChangeSetItem, alias?: string):
};
}
function compileSimpleChangeSetCondition(fields: { [column: string]: string }): Condition {
function getColumnCondition(columnName: string): Condition {
const value = fields[columnName];
const expr: Expression = {
exprType: 'column',
columnName,
};
if (value == null) {
return {
conditionType: 'isNull',
expr,
};
} else {
return {
conditionType: 'binary',
operator: '=',
left: expr,
right: {
exprType: 'value',
value,
},
};
}
}
return {
conditionType: 'and',
conditions: _.keys(fields).map(columnName => getColumnCondition(columnName)),
};
}
function changeSetUpdateToSql(item: ChangeSetItem, dbinfo: DatabaseInfo = null): Update {
const table = dbinfo?.tables?.find(x => x.schemaName == item.schemaName && x.pureName == item.pureName);