mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 16:06:23 +00:00
introduced sqltree typescript library
This commit is contained in:
1
packages/sqltree/.gitignore
vendored
Normal file
1
packages/sqltree/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
lib
|
||||
19
packages/sqltree/package.json
Normal file
19
packages/sqltree/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
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";
|
||||
12
packages/sqltree/tsconfig.json
Normal file
12
packages/sqltree/tsconfig.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2015",
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"skipLibCheck": true,
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user