mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 17:06:01 +00:00
introduced sqltree typescript library
This commit is contained in:
13
packages/sqltree/src/Command.ts
Normal file
13
packages/sqltree/src/Command.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { EngineDriver, SqlDumper } from "@dbgate/types";
|
||||
|
||||
class Command {
|
||||
toSql(driver: EngineDriver) {
|
||||
const dumper = driver.createDumper();
|
||||
this.dumpSql(dumper);
|
||||
return dumper.s;
|
||||
}
|
||||
|
||||
dumpSql(dumper: SqlDumper) {}
|
||||
}
|
||||
|
||||
export default Command;
|
||||
31
packages/sqltree/src/Select.ts
Normal file
31
packages/sqltree/src/Select.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import Command from "./Command";
|
||||
import { NamedObjectInfo, RangeDefinition, SqlDumper } from "@dbgate/types";
|
||||
|
||||
class Select extends Command {
|
||||
topRecords: number;
|
||||
from: NamedObjectInfo;
|
||||
range: RangeDefinition;
|
||||
distinct = false;
|
||||
selectAll = false;
|
||||
|
||||
dumpSql(dumper: SqlDumper) {
|
||||
dumper.put("^select ");
|
||||
if (this.topRecords) {
|
||||
dumper.put("^top %s ", this.topRecords);
|
||||
}
|
||||
if (this.distinct) {
|
||||
dumper.put("^distinct ");
|
||||
}
|
||||
if (this.selectAll) {
|
||||
dumper.put("* ");
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
dumper.put("^from %f ", this.from);
|
||||
if (this.range) {
|
||||
dumper.put("^limit %s ^offset %s ", this.range.limit, this.range.offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Select;
|
||||
2
packages/sqltree/src/index.ts
Normal file
2
packages/sqltree/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { default as Select } from "./Select";
|
||||
export { default as Command } from "./Command";
|
||||
Reference in New Issue
Block a user