introduced sqltree typescript library

This commit is contained in:
Jan Prochazka
2020-03-05 07:35:23 +01:00
parent 17e2c18c49
commit bbc969fa71
12 changed files with 88 additions and 53 deletions

1
packages/sqltree/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
lib

View File

@@ -0,0 +1,19 @@
{
"version": "0.1.0",
"name": "@dbgate/sqltree",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"scripts": {
"prepare": "yarn build",
"build": "tsc",
"start": "tsc --watch"
},
"files": [
"lib"
],
"devDependencies": {
"@dbgate/types": "^0.1.0",
"@types/node": "^13.7.0",
"typescript": "^3.7.5"
}
}

View 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;

View 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;

View File

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

View File

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ES2015",
"module": "commonjs",
"declaration": true,
"skipLibCheck": true,
"outDir": "lib"
},
"include": [
"src/**/*"
]
}