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

View File

@@ -7,6 +7,7 @@
"scripts": {
"start:api": "yarn workspace @dbgate/api start",
"start:web": "yarn workspace @dbgate/web start",
"start:sqltree": "yarn workspace @dbgate/sqltree start",
"start": "concurrently --kill-others-on-fail \"yarn start:api\" \"yarn start:web\"",
"ts:api": "yarn workspace @dbgate/api ts",

View File

@@ -17,7 +17,8 @@
"pg": "^7.17.0",
"socket.io": "^2.3.0",
"uuid": "^3.4.0",
"@dbgate/engines": "^0.1.0"
"@dbgate/engines": "^0.1.0",
"@dbgate/sqltree": "^0.1.0"
},
"scripts": {
"start": "nodemon src/index.js",

View File

@@ -1,13 +0,0 @@
class Command {
/** @param driver {import('@dbgate/types').EngineDriver} */
toSql(driver) {
const dumper = driver.createDumper();
this.dumpSql(dumper);
return dumper.s;
}
/** @param dumper {import('@dbgate/types').SqlDumper} */
dumpSql(dumper) {}
}
module.exports = Command;

View File

@@ -1,37 +0,0 @@
const Command = require('./command');
class Select extends Command {
constructor() {
super();
/** @type {number} */
this.topRecords = undefined;
/** @type {import('@dbgate/types').NamedObjectInfo} */
this.from = undefined;
/** @type {import('@dbgate/types').RangeDefinition} */
this.range = undefined;
this.distinct = false;
this.selectAll = false;
}
/** @param dumper {import('@dbgate/types').SqlDumper} */
dumpSql(dumper) {
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);
}
}
}
module.exports = Select;

View File

@@ -1,6 +1,6 @@
const engines = require('@dbgate/engines');
const Select = require('../dmlf/select');
const driverConnect = require('../utility/driverConnect')
const { Select } = require('@dbgate/sqltree');
const driverConnect = require('../utility/driverConnect');
let systemConnection;
let storedConnection;

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/**/*"
]
}

View File

@@ -1474,6 +1474,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.26.tgz#213e153babac0ed169d44a6d919501e68f59dea9"
integrity sha512-UmUm94/QZvU5xLcUlNR8hA7Ac+fGpO1EG/a8bcWVz0P0LqtxFmun9Y2bbtuckwGboWJIT70DoWq1r3hb56n3DA==
"@types/node@^13.7.0":
version "13.7.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.7.7.tgz#1628e6461ba8cc9b53196dfeaeec7b07fa6eea99"
integrity sha512-Uo4chgKbnPNlxQwoFmYIwctkQVkMMmsAoGGU4JKwLuvBefF0pCq4FybNSnfkfRCpC7ZW7kttcC/TrRtAJsvGtg==
"@types/node@^8.0.47":
version "8.10.59"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.59.tgz#9e34261f30183f9777017a13d185dfac6b899e04"