graphql-engine/server/src-lib/Hasura/Backends/Postgres/Translate/Column.hs
Robert 11a454c2d6 server, pro: actually reformat the code-base using ormolu
This commit applies ormolu to the whole Haskell code base by running `make format`.

For in-flight branches, simply merging changes from `main` will result in merge conflicts.
To avoid this, update your branch using the following instructions. Replace `<format-commit>`
by the hash of *this* commit.

$ git checkout my-feature-branch
$ git merge <format-commit>^    # and resolve conflicts normally
$ make format
$ git commit -a -m "reformat with ormolu"
$ git merge -s ours post-ormolu

https://github.com/hasura/graphql-engine-mono/pull/2404

GitOrigin-RevId: 75049f5c12f430c615eafb4c6b8e83e371e01c8e
2021-09-23 22:57:37 +00:00

38 lines
1.3 KiB
Haskell

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.SQL.Backend
toTxtValue :: ColumnValue ('Postgres pgKind) -> SQLExp
toTxtValue ColumnValue {..} =
withTyAnn ty . withConstructorFn ty $ txtEncoder cvValue
where
ty = unsafePGColumnToBackend cvType
-- | Formats each columns to appropriate SQL expression
toJSONableExp :: Bool -> 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 && stringifyNum) =
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