SYNC: Merge pull request #3 from dbgate/feature/zip

This commit is contained in:
Jan Prochazka
2025-04-23 13:17:54 +02:00
committed by Diflow
parent 54c53f0b56
commit 8f4118a6b8
82 changed files with 3981 additions and 2814 deletions

View File

@@ -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;
}