mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 11:26:00 +00:00
unified prettier
This commit is contained in:
@@ -1,58 +1,55 @@
|
||||
import { Source, FromDefinition, Relation } from "./types";
|
||||
import { SqlDumper } from "@dbgate/types";
|
||||
import { dumpSqlSelect } from "./dumpSqlCommand";
|
||||
import { dumpSqlCondition } from "./dumpSqlCondition";
|
||||
import { Source, FromDefinition, Relation } from './types';
|
||||
import { SqlDumper } from '@dbgate/types';
|
||||
import { dumpSqlSelect } from './dumpSqlCommand';
|
||||
import { dumpSqlCondition } from './dumpSqlCondition';
|
||||
|
||||
export function dumpSqlSourceDef(dmp: SqlDumper, source: Source) {
|
||||
let sources = 0;
|
||||
if (source.name != null) sources++;
|
||||
if (source.subQuery != null) sources++;
|
||||
if (source.subQueryString != null) sources++;
|
||||
if (sources != 1)
|
||||
throw new Error("sqltree.Source should have exactly one source");
|
||||
if (sources != 1) throw new Error('sqltree.Source should have exactly one source');
|
||||
|
||||
if (source.name != null) {
|
||||
dmp.put("%f", source.name);
|
||||
dmp.put('%f', source.name);
|
||||
}
|
||||
if (source.subQuery) {
|
||||
dmp.put("(");
|
||||
dmp.put('(');
|
||||
dumpSqlSelect(dmp, source.subQuery);
|
||||
dmp.put(")");
|
||||
dmp.put(')');
|
||||
}
|
||||
if (source.subQueryString) {
|
||||
dmp.put("(");
|
||||
dmp.put('(');
|
||||
dmp.putRaw(source.subQueryString);
|
||||
dmp.put(")");
|
||||
dmp.put(')');
|
||||
}
|
||||
if (source.alias) {
|
||||
dmp.put(" %i", this.alias);
|
||||
dmp.put(' %i', this.alias);
|
||||
}
|
||||
}
|
||||
|
||||
export function dumpSqlSourceRef(dmp: SqlDumper, source: Source) {
|
||||
if (source.alias) {
|
||||
dmp.put("%i", source.alias);
|
||||
dmp.put('%i', source.alias);
|
||||
return true;
|
||||
} else if (source.name) {
|
||||
dmp.put("%f", source.name);
|
||||
dmp.put('%f', source.name);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function dumpSqlRelation(dmp: SqlDumper, from: Relation) {
|
||||
dmp.put("&n %k ", from.joinType);
|
||||
dmp.put('&n %k ', from.joinType);
|
||||
dumpSqlSourceDef(dmp, from.source);
|
||||
if (from.conditions) {
|
||||
dmp.put(" ^on ");
|
||||
dmp.putCollection(" ^and ", from.conditions, cond =>
|
||||
dumpSqlCondition(dmp, cond)
|
||||
);
|
||||
dmp.put(' ^on ');
|
||||
dmp.putCollection(' ^and ', from.conditions, cond => dumpSqlCondition(dmp, cond));
|
||||
}
|
||||
}
|
||||
|
||||
export function dumpSqlFromDefinition(dmp: SqlDumper, from: FromDefinition) {
|
||||
dumpSqlSourceDef(dmp, from.source);
|
||||
dmp.put(" ");
|
||||
dmp.put(' ');
|
||||
if (from.relations) from.relations.forEach(rel => dumpSqlRelation(dmp, rel));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user