2020-03-12 11:46:07 +00:00
|
|
|
import _ from 'lodash';
|
2020-03-05 12:32:42 +00:00
|
|
|
import { SqlDumper } from '@dbgate/types';
|
|
|
|
import { Expression, ColumnRefExpression } from './types';
|
|
|
|
import { dumpSqlSourceRef } from './dumpSqlSource';
|
2020-03-05 11:23:07 +00:00
|
|
|
|
2020-03-05 12:19:25 +00:00
|
|
|
export function dumpSqlExpression(dmp: SqlDumper, expr: Expression) {
|
2020-03-05 11:23:07 +00:00
|
|
|
switch (expr.exprType) {
|
2020-03-05 12:32:42 +00:00
|
|
|
case 'column':
|
2020-03-05 12:19:25 +00:00
|
|
|
{
|
|
|
|
if (expr.source) {
|
|
|
|
if (dumpSqlSourceRef(dmp, expr.source)) {
|
2020-03-05 12:32:42 +00:00
|
|
|
dmp.put('.');
|
2020-03-05 12:19:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-05 12:32:42 +00:00
|
|
|
dmp.put('%i', expr.columnName);
|
2020-03-05 12:19:25 +00:00
|
|
|
}
|
2020-03-05 11:23:07 +00:00
|
|
|
break;
|
2020-03-12 11:46:07 +00:00
|
|
|
|
|
|
|
case 'placeholder':
|
|
|
|
dmp.putRaw('{PLACEHOLDER}');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'value':
|
|
|
|
dmp.put('%v', expr.value);
|
|
|
|
break;
|
2020-03-05 11:23:07 +00:00
|
|
|
}
|
|
|
|
}
|