mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 13:46:00 +00:00
of not exitsts fields
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user