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