mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 19:36:00 +00:00
sqlgen
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user