mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
unified prettier
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import GridDisplay from "./GridDisplay";
|
||||
import { Select, treeToSql, dumpSqlSelect } from "@dbgate/sqltree";
|
||||
import {
|
||||
Select,
|
||||
treeToSql,
|
||||
dumpSqlSelect,
|
||||
createColumnResultField
|
||||
} from "@dbgate/sqltree";
|
||||
import { TableInfo, EngineDriver } from "@dbgate/types";
|
||||
import GridConfig from "./GridConfig";
|
||||
|
||||
@@ -19,12 +24,9 @@ export default class TableGridDisplay extends GridDisplay {
|
||||
from: {
|
||||
source: { name: this.table }
|
||||
},
|
||||
columns: this.table.columns.map(col => ({
|
||||
expr: {
|
||||
exprType: "column",
|
||||
columnName: col.columnName
|
||||
}
|
||||
}))
|
||||
columns: this.table.columns.map(col =>
|
||||
createColumnResultField(col.columnName)
|
||||
)
|
||||
};
|
||||
return select;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { ResultField } from "./types";
|
||||
import { ResultField } from './types';
|
||||
|
||||
export function createColumnResultField(columnName: string): ResultField {
|
||||
return {
|
||||
expr: {
|
||||
exprType: "column",
|
||||
columnName
|
||||
}
|
||||
exprType: 'column',
|
||||
columnName,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
import { SqlDumper } from "@dbgate/types";
|
||||
import { Command, Select } from "./types";
|
||||
import { dumpSqlExpression } from "./dumpSqlExpression";
|
||||
import { dumpSqlFromDefinition } from "./dumpSqlSource";
|
||||
import { SqlDumper } from '@dbgate/types';
|
||||
import { Command, Select } from './types';
|
||||
import { dumpSqlExpression } from './dumpSqlExpression';
|
||||
import { dumpSqlFromDefinition } from './dumpSqlSource';
|
||||
|
||||
export function dumpSqlSelect(dmp: SqlDumper, select: Select) {
|
||||
dmp.put("^select ");
|
||||
dmp.put('^select ');
|
||||
if (select.topRecords) {
|
||||
dmp.put("^top %s ", select.topRecords);
|
||||
dmp.put('^top %s ', select.topRecords);
|
||||
}
|
||||
if (select.distinct) {
|
||||
dmp.put("^distinct ");
|
||||
dmp.put('^distinct ');
|
||||
}
|
||||
if (select.selectAll) {
|
||||
dmp.put("* ");
|
||||
dmp.put('* ');
|
||||
}
|
||||
if (select.columns) {
|
||||
if (select.selectAll) dmp.put("&n,");
|
||||
dmp.put("&>&n");
|
||||
dmp.putCollection(",&n", select.columns, fld => {
|
||||
if (select.selectAll) dmp.put('&n,');
|
||||
dmp.put('&>&n');
|
||||
dmp.putCollection(',&n', select.columns, fld => {
|
||||
dumpSqlExpression(dmp, fld.expr);
|
||||
if (fld.alias) dmp.put(" %i", fld.alias);
|
||||
if (fld.alias) dmp.put(' %i', fld.alias);
|
||||
});
|
||||
dmp.put("&n&<");
|
||||
dmp.put('&n&<');
|
||||
}
|
||||
dmp.put("^from ");
|
||||
dmp.put('^from ');
|
||||
dumpSqlFromDefinition(dmp, select.from);
|
||||
if (select.range) {
|
||||
dmp.put("^limit %s ^offset %s ", select.range.limit, select.range.offset);
|
||||
dmp.put('^limit %s ^offset %s ', select.range.limit, select.range.offset);
|
||||
}
|
||||
}
|
||||
|
||||
export function dumpSqlCommand(dmp: SqlDumper, command: Command) {
|
||||
switch (command.commandType) {
|
||||
case "select":
|
||||
case 'select':
|
||||
dumpSqlSelect(dmp, command);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { SqlDumper } from "@dbgate/types";
|
||||
import { Condition, BinaryCondition } from "./types";
|
||||
import { dumpSqlExpression } from "./dumpSqlExpression";
|
||||
import { SqlDumper } from '@dbgate/types';
|
||||
import { Condition, BinaryCondition } from './types';
|
||||
import { dumpSqlExpression } from './dumpSqlExpression';
|
||||
|
||||
export function dumpSqlCondition(dmp: SqlDumper, condition: Condition) {
|
||||
switch (condition.conditionType) {
|
||||
case "binary":
|
||||
dmp.put("(");
|
||||
case 'binary':
|
||||
dmp.put('(');
|
||||
dumpSqlExpression(dmp, condition.left);
|
||||
dmp.put(" %s ", condition.operator);
|
||||
dmp.put(' %s ', condition.operator);
|
||||
dumpSqlExpression(dmp, condition.right);
|
||||
dmp.put(")");
|
||||
dmp.put(')');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { SqlDumper } from "@dbgate/types";
|
||||
import { Expression, ColumnRefExpression } from "./types";
|
||||
import { dumpSqlSourceRef } from "./dumpSqlSource";
|
||||
import { SqlDumper } from '@dbgate/types';
|
||||
import { Expression, ColumnRefExpression } from './types';
|
||||
import { dumpSqlSourceRef } from './dumpSqlSource';
|
||||
|
||||
export function dumpSqlExpression(dmp: SqlDumper, expr: Expression) {
|
||||
switch (expr.exprType) {
|
||||
case "column":
|
||||
case 'column':
|
||||
{
|
||||
if (expr.source) {
|
||||
if (dumpSqlSourceRef(dmp, expr.source)) {
|
||||
dmp.put(".");
|
||||
dmp.put('.');
|
||||
}
|
||||
}
|
||||
dmp.put("%i", expr.columnName);
|
||||
dmp.put('%i', expr.columnName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,58 +1,55 @@
|
||||
import { Source, FromDefinition, Relation } from "./types";
|
||||
import { SqlDumper } from "@dbgate/types";
|
||||
import { dumpSqlSelect } from "./dumpSqlCommand";
|
||||
import { dumpSqlCondition } from "./dumpSqlCondition";
|
||||
import { Source, FromDefinition, Relation } from './types';
|
||||
import { SqlDumper } from '@dbgate/types';
|
||||
import { dumpSqlSelect } from './dumpSqlCommand';
|
||||
import { dumpSqlCondition } from './dumpSqlCondition';
|
||||
|
||||
export function dumpSqlSourceDef(dmp: SqlDumper, source: Source) {
|
||||
let sources = 0;
|
||||
if (source.name != null) sources++;
|
||||
if (source.subQuery != null) sources++;
|
||||
if (source.subQueryString != null) sources++;
|
||||
if (sources != 1)
|
||||
throw new Error("sqltree.Source should have exactly one source");
|
||||
if (sources != 1) throw new Error('sqltree.Source should have exactly one source');
|
||||
|
||||
if (source.name != null) {
|
||||
dmp.put("%f", source.name);
|
||||
dmp.put('%f', source.name);
|
||||
}
|
||||
if (source.subQuery) {
|
||||
dmp.put("(");
|
||||
dmp.put('(');
|
||||
dumpSqlSelect(dmp, source.subQuery);
|
||||
dmp.put(")");
|
||||
dmp.put(')');
|
||||
}
|
||||
if (source.subQueryString) {
|
||||
dmp.put("(");
|
||||
dmp.put('(');
|
||||
dmp.putRaw(source.subQueryString);
|
||||
dmp.put(")");
|
||||
dmp.put(')');
|
||||
}
|
||||
if (source.alias) {
|
||||
dmp.put(" %i", this.alias);
|
||||
dmp.put(' %i', this.alias);
|
||||
}
|
||||
}
|
||||
|
||||
export function dumpSqlSourceRef(dmp: SqlDumper, source: Source) {
|
||||
if (source.alias) {
|
||||
dmp.put("%i", source.alias);
|
||||
dmp.put('%i', source.alias);
|
||||
return true;
|
||||
} else if (source.name) {
|
||||
dmp.put("%f", source.name);
|
||||
dmp.put('%f', source.name);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function dumpSqlRelation(dmp: SqlDumper, from: Relation) {
|
||||
dmp.put("&n %k ", from.joinType);
|
||||
dmp.put('&n %k ', from.joinType);
|
||||
dumpSqlSourceDef(dmp, from.source);
|
||||
if (from.conditions) {
|
||||
dmp.put(" ^on ");
|
||||
dmp.putCollection(" ^and ", from.conditions, cond =>
|
||||
dumpSqlCondition(dmp, cond)
|
||||
);
|
||||
dmp.put(' ^on ');
|
||||
dmp.putCollection(' ^and ', from.conditions, cond => dumpSqlCondition(dmp, cond));
|
||||
}
|
||||
}
|
||||
|
||||
export function dumpSqlFromDefinition(dmp: SqlDumper, from: FromDefinition) {
|
||||
dumpSqlSourceDef(dmp, from.source);
|
||||
dmp.put(" ");
|
||||
dmp.put(' ');
|
||||
if (from.relations) from.relations.forEach(rel => dumpSqlRelation(dmp, rel));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from "./types";
|
||||
export * from "./dumpSqlCommand";
|
||||
export * from "./treeToSql";
|
||||
export * from "./dumpSqlSource";
|
||||
export * from "./dumpSqlCondition";
|
||||
export * from './types';
|
||||
export * from './dumpSqlCommand';
|
||||
export * from './treeToSql';
|
||||
export * from './dumpSqlSource';
|
||||
export * from './dumpSqlCondition';
|
||||
export * from './createFunctions';
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { EngineDriver, SqlDumper } from "@dbgate/types";
|
||||
import { EngineDriver, SqlDumper } from '@dbgate/types';
|
||||
|
||||
export function treeToSql<T>(
|
||||
driver: EngineDriver,
|
||||
object: T,
|
||||
func: (dmp: SqlDumper, obj: T) => void
|
||||
) {
|
||||
export function treeToSql<T>(driver: EngineDriver, object: T, func: (dmp: SqlDumper, obj: T) => void) {
|
||||
const dmp = driver.createDumper();
|
||||
func(dmp, object);
|
||||
return dmp.s;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { NamedObjectInfo, RangeDefinition } from "@dbgate/types";
|
||||
import { NamedObjectInfo, RangeDefinition } from '@dbgate/types';
|
||||
|
||||
// export interface Command {
|
||||
// }
|
||||
|
||||
export interface Select {
|
||||
commandType: "select";
|
||||
commandType: 'select';
|
||||
|
||||
from: FromDefinition;
|
||||
|
||||
@@ -26,14 +26,14 @@ export interface UnaryCondition {
|
||||
}
|
||||
|
||||
export interface BinaryCondition {
|
||||
operator: "=" | "!=" | "<" | ">" | ">=" | "<=";
|
||||
conditionType: "binary";
|
||||
operator: '=' | '!=' | '<' | '>' | '>=' | '<=';
|
||||
conditionType: 'binary';
|
||||
left: Expression;
|
||||
right: Expression;
|
||||
}
|
||||
|
||||
export interface NotCondition extends UnaryCondition {
|
||||
conditionType: "not";
|
||||
conditionType: 'not';
|
||||
}
|
||||
|
||||
export type Condition = BinaryCondition | NotCondition;
|
||||
@@ -45,7 +45,7 @@ export interface Source {
|
||||
subQueryString?: string;
|
||||
}
|
||||
|
||||
export type JoinType = "LEFT JOIN" | "INNER JOIN" | "RIGHT JOIN";
|
||||
export type JoinType = 'LEFT JOIN' | 'INNER JOIN' | 'RIGHT JOIN';
|
||||
|
||||
export interface Relation {
|
||||
source: Source;
|
||||
@@ -63,13 +63,13 @@ export interface FromDefinition {
|
||||
// }
|
||||
|
||||
export interface ColumnRefExpression {
|
||||
exprType: "column";
|
||||
exprType: 'column';
|
||||
columnName: string;
|
||||
source?: Source;
|
||||
}
|
||||
|
||||
export interface ValueExpression {
|
||||
exprType: "value";
|
||||
exprType: 'value';
|
||||
value: any;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
module.exports = {
|
||||
trailingComma: 'es5',
|
||||
tabWidth: 2,
|
||||
semi: true,
|
||||
singleQuote: true,
|
||||
arrowParen: 'avoid',
|
||||
printWidth: 120,
|
||||
};
|
||||
@@ -1,17 +1,17 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import "./index.css";
|
||||
import "@fortawesome/fontawesome-free/css/all.css";
|
||||
import App from "./App";
|
||||
import * as serviceWorker from "./serviceWorker";
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import './index.css';
|
||||
import '@fortawesome/fontawesome-free/css/all.css';
|
||||
import App from './App';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
|
||||
import "ace-builds/src-noconflict/mode-sql";
|
||||
import "ace-builds/src-noconflict/mode-mysql";
|
||||
import "ace-builds/src-noconflict/mode-pgsql";
|
||||
import "ace-builds/src-noconflict/mode-sqlserver";
|
||||
import "ace-builds/src-noconflict/theme-github";
|
||||
import 'ace-builds/src-noconflict/mode-sql';
|
||||
import 'ace-builds/src-noconflict/mode-mysql';
|
||||
import 'ace-builds/src-noconflict/mode-pgsql';
|
||||
import 'ace-builds/src-noconflict/mode-sqlserver';
|
||||
import 'ace-builds/src-noconflict/theme-github';
|
||||
|
||||
ReactDOM.render(<App />, document.getElementById("root"));
|
||||
ReactDOM.render(<App />, document.getElementById('root'));
|
||||
|
||||
// If you want your app to work offline and load faster, you can change
|
||||
// unregister() to register() below. Note this comes with some pitfalls.
|
||||
|
||||
Reference in New Issue
Block a user