mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 18:56:00 +00:00
incremental data loading, flattened some sqltree types
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
import { ResultField } from './types';
|
||||
|
||||
export function createColumnResultField(columnName: string): ResultField {
|
||||
return {
|
||||
expr: {
|
||||
exprType: 'column',
|
||||
columnName,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -18,15 +18,32 @@ export function dumpSqlSelect(dmp: SqlDumper, select: Select) {
|
||||
if (select.selectAll) dmp.put('&n,');
|
||||
dmp.put('&>&n');
|
||||
dmp.putCollection(',&n', select.columns, fld => {
|
||||
dumpSqlExpression(dmp, fld.expr);
|
||||
dumpSqlExpression(dmp, fld);
|
||||
if (fld.alias) dmp.put(' %i', fld.alias);
|
||||
});
|
||||
dmp.put('&n&<');
|
||||
}
|
||||
dmp.put('^from ');
|
||||
dumpSqlFromDefinition(dmp, select.from);
|
||||
if (select.groupBy) {
|
||||
dmp.put('&ngroup ^by ');
|
||||
dmp.putCollection(', ', select.groupBy, expr => dumpSqlExpression(dmp, expr));
|
||||
dmp.put('&n');
|
||||
}
|
||||
if (select.orderBy) {
|
||||
dmp.put('&n^order ^by ');
|
||||
dmp.putCollection(', ', select.orderBy, expr => {
|
||||
dumpSqlExpression(dmp, expr);
|
||||
dmp.put(' %k', expr.direction);
|
||||
});
|
||||
dmp.put('&n');
|
||||
}
|
||||
if (select.range) {
|
||||
dmp.put('^limit %s ^offset %s ', select.range.limit, select.range.offset);
|
||||
if (dmp.dialect.offsetFetchRangeSyntax) {
|
||||
dmp.put('^offset %s ^rows ^fetch ^next %s ^rows ^only', select.range.offset, select.range.limit);
|
||||
} else {
|
||||
dmp.put('^limit %s ^offset %s ', select.range.limit, select.range.offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ export function dumpSqlSourceRef(dmp: SqlDumper, source: Source) {
|
||||
|
||||
export function dumpSqlRelation(dmp: SqlDumper, from: Relation) {
|
||||
dmp.put('&n %k ', from.joinType);
|
||||
dumpSqlSourceDef(dmp, from.source);
|
||||
dumpSqlSourceDef(dmp, from);
|
||||
if (from.conditions) {
|
||||
dmp.put(' ^on ');
|
||||
dmp.putCollection(' ^and ', from.conditions, cond => dumpSqlCondition(dmp, cond));
|
||||
@@ -49,7 +49,7 @@ export function dumpSqlRelation(dmp: SqlDumper, from: Relation) {
|
||||
}
|
||||
|
||||
export function dumpSqlFromDefinition(dmp: SqlDumper, from: FromDefinition) {
|
||||
dumpSqlSourceDef(dmp, from.source);
|
||||
dumpSqlSourceDef(dmp, from);
|
||||
dmp.put(' ');
|
||||
if (from.relations) from.relations.forEach(rel => dumpSqlRelation(dmp, rel));
|
||||
}
|
||||
|
||||
@@ -3,4 +3,3 @@ export * from './dumpSqlCommand';
|
||||
export * from './treeToSql';
|
||||
export * from './dumpSqlSource';
|
||||
export * from './dumpSqlCondition';
|
||||
export * from './createFunctions';
|
||||
|
||||
@@ -13,6 +13,8 @@ export interface Select {
|
||||
range?: RangeDefinition;
|
||||
distinct?: boolean;
|
||||
selectAll?: boolean;
|
||||
orderBy?: OrderByExpression[];
|
||||
groupBy?: Expression[];
|
||||
}
|
||||
|
||||
export type Command = Select;
|
||||
@@ -47,16 +49,11 @@ export interface Source {
|
||||
|
||||
export type JoinType = 'LEFT JOIN' | 'INNER JOIN' | 'RIGHT JOIN';
|
||||
|
||||
export interface Relation {
|
||||
source: Source;
|
||||
export type Relation = Source & {
|
||||
conditions: Condition[];
|
||||
joinType: JoinType;
|
||||
}
|
||||
|
||||
export interface FromDefinition {
|
||||
source: Source;
|
||||
relations?: Relation[];
|
||||
}
|
||||
};
|
||||
export type FromDefinition = Source & { relations?: Relation[] };
|
||||
|
||||
// export interface Expression {
|
||||
// exprType: "column" | "value" | "string" | "literal" | "count";
|
||||
@@ -74,8 +71,6 @@ export interface ValueExpression {
|
||||
}
|
||||
|
||||
export type Expression = ColumnRefExpression | ValueExpression;
|
||||
export type OrderByExpression = Expression & { direction: 'ASC' | 'DESC' };
|
||||
|
||||
export interface ResultField {
|
||||
expr: ValueExpression | ColumnRefExpression;
|
||||
alias?: string;
|
||||
}
|
||||
export type ResultField = Expression & { alias?: string };
|
||||
|
||||
Reference in New Issue
Block a user