mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 19:56:02 +00:00
SYNC: Merge pull request #3 from dbgate/feature/zip
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { EngineDriver, SqlDumper } from 'dbgate-types';
|
||||
import { Command, Condition } from './types';
|
||||
import { Command, Condition, Select, Source } from './types';
|
||||
import { dumpSqlCommand } from './dumpSqlCommand';
|
||||
|
||||
export function treeToSql<T>(driver: EngineDriver, object: T, func: (dmp: SqlDumper, obj: T) => void) {
|
||||
@@ -43,3 +43,43 @@ export function mergeConditions(condition1: Condition, condition2: Condition): C
|
||||
conditions: [condition1, condition2],
|
||||
};
|
||||
}
|
||||
|
||||
export function selectKeysFromTable(options: {
|
||||
pureName: string;
|
||||
schemaName: string;
|
||||
keyColumns: [];
|
||||
loadKeys: any[][];
|
||||
}): Select {
|
||||
const source: Source = {
|
||||
name: { pureName: options.pureName, schemaName: options.schemaName },
|
||||
};
|
||||
const res: Select = {
|
||||
commandType: 'select',
|
||||
columns: options.keyColumns.map(col => ({
|
||||
exprType: 'column',
|
||||
columnName: col,
|
||||
source,
|
||||
})),
|
||||
from: source,
|
||||
where: {
|
||||
conditionType: 'or',
|
||||
conditions: options.loadKeys.map(key => ({
|
||||
conditionType: 'and',
|
||||
conditions: key.map((keyValue, index) => ({
|
||||
conditionType: 'binary',
|
||||
operator: '=',
|
||||
left: {
|
||||
exprType: 'column',
|
||||
columnName: options.keyColumns[index],
|
||||
source,
|
||||
},
|
||||
right: {
|
||||
exprType: 'value',
|
||||
value: keyValue,
|
||||
},
|
||||
})),
|
||||
})),
|
||||
},
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user