mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 23:36:01 +00:00
support for geograpghy view in mssql
This commit is contained in:
@@ -35,17 +35,24 @@ export function dumpSqlExpression(dmp: SqlDumper, expr: Expression) {
|
|||||||
dmp.put(')');
|
dmp.put(')');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'methodCall':
|
||||||
|
dumpSqlExpression(dmp, expr.thisObject)
|
||||||
|
dmp.put('.%s(', expr.method);
|
||||||
|
dmp.putCollection(',', expr.args, x => dumpSqlExpression(dmp, x));
|
||||||
|
dmp.put(')');
|
||||||
|
break;
|
||||||
|
|
||||||
case 'transform':
|
case 'transform':
|
||||||
dmp.transform(expr.transform, () => dumpSqlExpression(dmp, expr.expr));
|
dmp.transform(expr.transform, () => dumpSqlExpression(dmp, expr.expr));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'rowNumber':
|
case 'rowNumber':
|
||||||
dmp.put(" ^row_number() ^over (^order ^by ");
|
dmp.put(' ^row_number() ^over (^order ^by ');
|
||||||
dmp.putCollection(', ', expr.orderBy, x => {
|
dmp.putCollection(', ', expr.orderBy, x => {
|
||||||
dumpSqlExpression(dmp, x);
|
dumpSqlExpression(dmp, x);
|
||||||
dmp.put(' %k', x.direction);
|
dmp.put(' %k', x.direction);
|
||||||
});
|
});
|
||||||
dmp.put(")");
|
dmp.put(')');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ export function evaluateExpression(expr: Expression, values) {
|
|||||||
case 'call':
|
case 'call':
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
case 'methodCall':
|
||||||
|
return null;
|
||||||
|
|
||||||
case 'transform':
|
case 'transform':
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,6 +155,13 @@ export interface CallExpression {
|
|||||||
argsPrefix?: string; // DISTINCT in case of COUNT DISTINCT
|
argsPrefix?: string; // DISTINCT in case of COUNT DISTINCT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MethodCallExpression {
|
||||||
|
exprType: 'methodCall';
|
||||||
|
method: string;
|
||||||
|
args: Expression[];
|
||||||
|
thisObject: Expression;
|
||||||
|
}
|
||||||
|
|
||||||
export interface TranformExpression {
|
export interface TranformExpression {
|
||||||
exprType: 'transform';
|
exprType: 'transform';
|
||||||
expr: Expression;
|
expr: Expression;
|
||||||
@@ -172,6 +179,7 @@ export type Expression =
|
|||||||
| PlaceholderExpression
|
| PlaceholderExpression
|
||||||
| RawExpression
|
| RawExpression
|
||||||
| CallExpression
|
| CallExpression
|
||||||
|
| MethodCallExpression
|
||||||
| TranformExpression
|
| TranformExpression
|
||||||
| RowNumberExpression;
|
| RowNumberExpression;
|
||||||
export type OrderByExpression = Expression & { direction: 'ASC' | 'DESC' };
|
export type OrderByExpression = Expression & { direction: 'ASC' | 'DESC' };
|
||||||
|
|||||||
@@ -88,14 +88,8 @@ export function getIconForRedisType(type) {
|
|||||||
export function isWktGeometry(s) {
|
export function isWktGeometry(s) {
|
||||||
if (!_isString(s)) return false;
|
if (!_isString(s)) return false;
|
||||||
|
|
||||||
return (
|
// return !!s.match(/^POINT\s*\(|/)
|
||||||
s.startsWith('POINT(') ||
|
return !!s.match(
|
||||||
s.startsWith('LINESTRING(') ||
|
/^POINT\s*\(|^LINESTRING\s*\(|^POLYGON\s*\(|^MULTIPOINT\s*\(|^MULTILINESTRING\s*\(|^MULTIPOLYGON\s*\(|^GEOMCOLLECTION\s*\(|^GEOMETRYCOLLECTION\s*\(/
|
||||||
s.startsWith('POLYGON(') ||
|
|
||||||
s.startsWith('MULTIPOINT(') ||
|
|
||||||
s.startsWith('MULTILINESTRING(') ||
|
|
||||||
s.startsWith('MULTIPOLYGON(') ||
|
|
||||||
s.startsWith('GEOMCOLLECTION(') ||
|
|
||||||
s.startsWith('GEOMETRYCOLLECTION(')
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ const { driverBase } = global.DBGATE_TOOLS;
|
|||||||
const MsSqlDumper = require('./MsSqlDumper');
|
const MsSqlDumper = require('./MsSqlDumper');
|
||||||
const { mssqlSplitterOptions } = require('dbgate-query-splitter/lib/options');
|
const { mssqlSplitterOptions } = require('dbgate-query-splitter/lib/options');
|
||||||
|
|
||||||
|
const spatialTypes = ['GEOGRAPHY'];
|
||||||
|
|
||||||
/** @type {import('dbgate-types').SqlDialect} */
|
/** @type {import('dbgate-types').SqlDialect} */
|
||||||
const dialect = {
|
const dialect = {
|
||||||
limitSelect: true,
|
limitSelect: true,
|
||||||
@@ -70,6 +72,21 @@ const dialect = {
|
|||||||
'image',
|
'image',
|
||||||
'xml',
|
'xml',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
createColumnViewExpression(columnName, dataType, source, alias) {
|
||||||
|
if (dataType && spatialTypes.includes(dataType.toUpperCase())) {
|
||||||
|
return {
|
||||||
|
exprType: 'methodCall',
|
||||||
|
method: 'STAsText',
|
||||||
|
alias: alias || columnName,
|
||||||
|
thisObject: {
|
||||||
|
exprType: 'column',
|
||||||
|
columnName,
|
||||||
|
source,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @type {import('dbgate-types').EngineDriver} */
|
/** @type {import('dbgate-types').EngineDriver} */
|
||||||
|
|||||||
Reference in New Issue
Block a user