mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
mssql: basic support for geography and geometry types
GitOrigin-RevId: 97bbf0e8d53b00c9f4365b145adb19bdcd769ceb
This commit is contained in:
parent
6fb181a4ee
commit
74a58fb66c
@ -1,6 +1,12 @@
|
||||
# Hasura GraphQL Engine Changelog
|
||||
|
||||
## Next release
|
||||
|
||||
### Bug fixes and improvements
|
||||
|
||||
- server/mssql: fix runtime errors when selecting geography/geometry columns
|
||||
|
||||
## v1.4.0-alpha.2
|
||||
### MSSQL support
|
||||
|
||||
It's now possible to add a MSSQL server as a source. For now, only read-only queries and subscriptions are supported.
|
||||
|
@ -587,14 +587,20 @@ fromAnnColumnField ::
|
||||
-> ReaderT EntityAlias FromIr Expression
|
||||
fromAnnColumnField _stringifyNumbers annColumnField = do
|
||||
fieldName <- fromPGCol pgCol
|
||||
if asText || True -- TODO: FIXME:
|
||||
-- TODO: Does MSSQL support bignums? Probably, but needs researching.
|
||||
-- TODO: Handle stringifying large numbers
|
||||
{-(IR.isScalarColumnWhere PG.isBigNum typ && stringifyNumbers == StringifyNumbers)-}
|
||||
then pure (ToStringExpression (ColumnExpression fieldName))
|
||||
|
||||
-- for geometry and geography values, the automatic json encoding on sql
|
||||
-- server would fail. So we need to convert it to a format the json encoding
|
||||
-- handles. Ideally we want this representation to be GeoJSON but sql server
|
||||
-- doesn't have any functions to convert to GeoJSON format. So we return it in
|
||||
-- WKT format
|
||||
if typ == (IR.ColumnScalar GeometryType) || typ == (IR.ColumnScalar GeographyType)
|
||||
then pure $ MethodExpression (ColumnExpression fieldName) "STAsText" []
|
||||
else pure (ColumnExpression fieldName)
|
||||
where
|
||||
IR.AnnColumnField { _acfInfo = IR.ColumnInfo{pgiColumn=pgCol,pgiType=_typ}
|
||||
, _acfAsText = asText :: Bool
|
||||
IR.AnnColumnField { _acfInfo = IR.ColumnInfo{pgiColumn=pgCol,pgiType=typ}
|
||||
, _acfAsText = _asText :: Bool
|
||||
, _acfOp = _ :: Maybe (IR.ColumnOp 'MSSQL) -- TODO: What's this?
|
||||
} = annColumnField
|
||||
|
||||
|
@ -3,8 +3,7 @@
|
||||
-- |
|
||||
|
||||
module Hasura.Backends.MSSQL.Meta
|
||||
( MetadataError(..)
|
||||
, loadDBMetadata
|
||||
( loadDBMetadata
|
||||
) where
|
||||
|
||||
import Hasura.Prelude
|
||||
@ -31,10 +30,6 @@ import Hasura.SQL.Backend
|
||||
--------------------------------------------------------------------------------
|
||||
-- Loader
|
||||
|
||||
data MetadataError
|
||||
= UnknownScalarType Text
|
||||
deriving (Show)
|
||||
|
||||
loadDBMetadata :: Connection -> IO (DBTablesMetadata 'MSSQL)
|
||||
loadDBMetadata conn = do
|
||||
let sql = $(Q.sqlFromFile "src-rsr/mssql_table_metadata.sql")
|
||||
@ -179,6 +174,8 @@ parseScalarType = \case
|
||||
"varbinary" -> VarbinaryType
|
||||
"bit" -> BitType
|
||||
"uniqueidentifier" -> GuidType
|
||||
"geography" -> GeographyType
|
||||
"geometry" -> GeometryType
|
||||
t -> UnknownType t
|
||||
|
||||
|
||||
|
@ -93,6 +93,10 @@ fromExpression =
|
||||
"(" <+> fromExpression x <+> ") != (" <+> fromExpression y <+> ")"
|
||||
ToStringExpression e -> "CONCAT(" <+> fromExpression e <+> ", '')"
|
||||
SelectExpression s -> "(" <+> IndentPrinter 1 (fromSelect s) <+> ")"
|
||||
MethodExpression field method args ->
|
||||
fromExpression field <+> "." <+>
|
||||
fromString (T.unpack method) <+>
|
||||
"(" <+> (SeqPrinter $ map fromExpression args) <+> ")"
|
||||
OpExpression op x y ->
|
||||
"(" <+>
|
||||
fromExpression x <+>
|
||||
|
@ -157,6 +157,8 @@ data Expression
|
||||
-- behave like it knows your field is JSON and not double-encode
|
||||
-- it.
|
||||
| ToStringExpression Expression
|
||||
-- expression.text(e1, e2, ..)
|
||||
| MethodExpression !Expression !Text ![Expression]
|
||||
| JsonValueExpression Expression JsonPath
|
||||
-- ^ This is for getting actual atomic values out of a JSON
|
||||
-- string.
|
||||
@ -266,6 +268,8 @@ data ScalarType
|
||||
| TinyintType
|
||||
| BitType
|
||||
| GuidType
|
||||
| GeographyType
|
||||
| GeometryType
|
||||
| UnknownType !Text
|
||||
|
||||
scalarTypeDBName :: ScalarType -> Text
|
||||
@ -291,6 +295,8 @@ scalarTypeDBName = \case
|
||||
TinyintType -> "tinyint"
|
||||
BitType -> "bit"
|
||||
GuidType -> "uniqueidentifier"
|
||||
GeographyType -> "geography"
|
||||
GeometryType -> "geometry"
|
||||
-- the input form for types that aren't explicitly supported is a string
|
||||
UnknownType t -> t
|
||||
|
||||
@ -317,6 +323,11 @@ parseScalarValue scalarType jValue = case scalarType of
|
||||
TinyintType -> ODBC.IntValue <$> parseJValue jValue
|
||||
BitType -> ODBC.ByteValue <$> parseJValue jValue
|
||||
GuidType -> ODBC.TextValue <$> parseJValue jValue
|
||||
|
||||
-- TODO: We'll need to wrap this with geography::STGeomFromText
|
||||
GeographyType -> ODBC.TextValue <$> parseJValue jValue
|
||||
GeometryType -> ODBC.TextValue <$> parseJValue jValue
|
||||
|
||||
-- the input format for types that aren't explicitly supported is a string
|
||||
UnknownType _ -> ODBC.TextValue <$> parseJValue jValue
|
||||
where
|
||||
|
Loading…
Reference in New Issue
Block a user