mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-22 06:51:32 +03:00
f684fecc6c
## Description As the name suggests, `DML.Internal` contains internal implementation details of RQL's DML. However, a lot of unrelated parts of the codebase still use some of the code it contains. This PR fixes this, and removes all imports of `RQL.DML.Internal` from outside of `RQL.DML`. Most of the time, this involves moving a function out of `DML.Internal` to an underlying module (see `getRolePermInfo`) or moving a function _back_ into it (see `checkRetCols`). This PR also clarifies a bit the situation with `withTyAnn` and `withTypeAnn` by renaming the former into `withScalarTypeAnn` and moving them together. Worth noting: there might be a bug lurking in that function, as it doesn't seem to use the proper type annotations for some extension types! PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4380 GitOrigin-RevId: c8ae5b4e8378fefc0bcccf778d97813df727d3cb
42 lines
1.6 KiB
Haskell
42 lines
1.6 KiB
Haskell
-- | Postgres Translate Column
|
|
--
|
|
-- Translate column values to Postgres-specific SQL expressions.
|
|
module Hasura.Backends.Postgres.Translate.Column
|
|
( toTxtValue,
|
|
toJSONableExp,
|
|
)
|
|
where
|
|
|
|
import Hasura.Backends.Postgres.SQL.DML
|
|
import Hasura.Backends.Postgres.SQL.Types
|
|
import Hasura.Backends.Postgres.SQL.Value
|
|
import Hasura.Backends.Postgres.Types.Column
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types.Column
|
|
import Hasura.RQL.Types.Common (StringifyNumbers (..))
|
|
import Hasura.SQL.Backend
|
|
|
|
toTxtValue :: ColumnValue ('Postgres pgKind) -> SQLExp
|
|
toTxtValue ColumnValue {..} =
|
|
withScalarTypeAnn ty . withConstructorFn ty $ txtEncoder cvValue
|
|
where
|
|
ty = unsafePGColumnToBackend cvType
|
|
|
|
-- | Formats each columns to appropriate SQL expression
|
|
toJSONableExp :: StringifyNumbers -> ColumnType ('Postgres pgKind) -> Bool -> SQLExp -> SQLExp
|
|
toJSONableExp stringifyNum colType asText expression
|
|
-- If its a numeric column greater than a 32-bit integer, we have to stringify it as JSON spec doesn't support >32-bit integers
|
|
| asText || (isScalarColumnWhere isBigNum colType && (case stringifyNum of StringifyNumbers -> True; LeaveNumbersAlone -> False)) =
|
|
expression `SETyAnn` textTypeAnn
|
|
-- If the column is either a `Geometry` or `Geography` then apply the `ST_AsGeoJSON` function to convert it into GeoJSON format
|
|
| isScalarColumnWhere isGeoType colType =
|
|
SEFnApp
|
|
"ST_AsGeoJSON"
|
|
[ expression,
|
|
SEUnsafe "15", -- max decimal digits
|
|
SEUnsafe "4" -- to print out crs
|
|
]
|
|
Nothing
|
|
`SETyAnn` jsonTypeAnn
|
|
| otherwise = expression
|