unified prettier

This commit is contained in:
Jan Prochazka
2020-03-05 13:32:42 +01:00
parent 9ef719ec95
commit ffe8f1027f
12 changed files with 88 additions and 100 deletions

View File

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