sql tree - before refactor

This commit is contained in:
Jan Prochazka
2020-03-05 11:42:16 +01:00
parent 0507e84457
commit bf607fcb06
12 changed files with 136 additions and 18 deletions

View File

@@ -1,6 +1,6 @@
import { EngineDriver, SqlDumper } from "@dbgate/types";
class Command {
export class Command {
toSql(driver: EngineDriver) {
const dumper = driver.createDumper();
this.dumpSql(dumper);
@@ -9,5 +9,3 @@ class Command {
dumpSql(dumper: SqlDumper) {}
}
export default Command;

View File

@@ -0,0 +1,9 @@
import { SqlDumper } from "@dbgate/types";
export abstract class Condition {
abstract dumpSql(dumper: SqlDumper) ;
}
export abstract class UnaryCondition extends Condition {
// expr: Expresssion;
}

View File

@@ -0,0 +1,4 @@
export abstract class Expression {
}

View File

@@ -1,7 +1,7 @@
import Command from "./Command";
import { Command } from "./Command";
import { NamedObjectInfo, RangeDefinition, SqlDumper } from "@dbgate/types";
class Select extends Command {
export class Select extends Command {
topRecords: number;
from: NamedObjectInfo;
range: RangeDefinition;
@@ -27,5 +27,3 @@ class Select extends Command {
}
}
}
export default Select;

View File

@@ -0,0 +1,78 @@
import { SqlDumper, NamedObjectInfo } from "@dbgate/types";
import { Select } from "./Select";
export class Source {
name: NamedObjectInfo;
alias: string;
subQuery: Select;
subQueryString: string;
dumpSqlDef(dumper: SqlDumper) {
let sources = 0;
if (this.name != null) sources++;
if (this.subQuery != null) sources++;
if (this.subQueryString != null) sources++;
if (sources != 1)
throw new Error("sqltree.Source should have exactly one source");
if (this.name != null) {
dumper.put("%f", this.name);
}
if (this.subQuery) {
dumper.put("(");
this.subQuery.dumpSql(dumper);
dumper.put(")");
}
if (this.subQueryString) {
dumper.put("(");
dumper.putRaw(this.subQueryString);
dumper.put(")");
}
if (this.alias) {
dumper.put(" %i", this.alias);
}
}
dumpSqlRef(dumper: SqlDumper) {
if (this.alias != null) {
dumper.put("%i", this.alias);
return true;
} else if (this.name != null) {
dumper.put("%f", this.name);
return true;
}
return false;
}
}
class Relation {
source:Source;
joinType: string;
// conditions:
// dumpSqlRef(dumper: SqlDumper) {
// dumper.put("&n");
// dumper.putRaw(this.joinType);
// dumper.put(" ");
// this.source.dumpSqlDef(dumper)
// if (Conditions.Any())
// {
// dumper.put(" ^on ");
// bool was = false;
// foreach (var cond in Conditions)
// {
// if (was) dumper.put(" ^and ");
// cond.GenSql(dmp);
// was = true;
// }
// }
// }
}
export class FromDefinition {
source: Source;
relations: Relation[] = [];
}

View File

@@ -1,2 +1,2 @@
export { default as Select } from "./Select";
export { default as Command } from "./Command";
export { Select } from "./Select";
export { Command } from "./Command";