This commit is contained in:
Jan Prochazka
2020-03-05 13:19:25 +01:00
parent c47711d346
commit 9ef719ec95
8 changed files with 115 additions and 36 deletions

View File

@@ -1,5 +1,7 @@
import { SqlDumper } from "@dbgate/types";
import { Command, Select } from "./types";
import { dumpSqlExpression } from "./dumpSqlExpression";
import { dumpSqlFromDefinition } from "./dumpSqlSource";
export function dumpSqlSelect(dmp: SqlDumper, select: Select) {
dmp.put("^select ");
@@ -11,10 +13,18 @@ export function dumpSqlSelect(dmp: SqlDumper, select: Select) {
}
if (select.selectAll) {
dmp.put("* ");
} else {
// TODO
}
dmp.put("^from %f ", select.from);
if (select.columns) {
if (select.selectAll) dmp.put("&n,");
dmp.put("&>&n");
dmp.putCollection(",&n", select.columns, fld => {
dumpSqlExpression(dmp, fld.expr);
if (fld.alias) dmp.put(" %i", fld.alias);
});
dmp.put("&n&<");
}
dmp.put("^from ");
dumpSqlFromDefinition(dmp, select.from);
if (select.range) {
dmp.put("^limit %s ^offset %s ", select.range.limit, select.range.offset);
}
@@ -23,7 +33,7 @@ export function dumpSqlSelect(dmp: SqlDumper, select: Select) {
export function dumpSqlCommand(dmp: SqlDumper, command: Command) {
switch (command.commandType) {
case "select":
dumpSqlSelect(dmp, command as Select);
dumpSqlSelect(dmp, command);
break;
}
}