table grid display, SQL for browse table is generated on FE

This commit is contained in:
Jan Prochazka
2020-03-05 09:40:05 +01:00
parent bbc969fa71
commit aad9512951
14 changed files with 152 additions and 39 deletions

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

@@ -0,0 +1 @@
lib

View File

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

View File

@@ -0,0 +1,5 @@
import {Select} from '@dbgate/sqltree'
export default abstract class GridDisplay {
abstract getPageQuery(offse: number, count: number): string;
}

View File

@@ -0,0 +1,20 @@
import GridDisplay from "./GridDisplay";
import { Select } from "@dbgate/sqltree";
import { TableInfo, EngineDriver } from "@dbgate/types";
export default class TableGridDisplay extends GridDisplay {
constructor(public table: TableInfo, public driver: EngineDriver) {
super();
}
getPageQuery(offset: number, count: number) {
const select = new Select();
if (this.driver.dialect.limitSelect) select.topRecords = count;
if (this.driver.dialect.rangeSelect)
select.range = { offset: offset, limit: count };
select.from = this.table;
select.selectAll = true;
const sql = select.toSql(this.driver);
return sql;
}
}

View File

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

View File

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