mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-23 07:22:53 +03:00
342391f39d
This upgrades the version of Ormolu required by the HGE repository to v0.5.0.1, and reformats all code accordingly. Ormolu v0.5 reformats code that uses infix operators. This is mostly useful, adding newlines and indentation to make it clear which operators are applied first, but in some cases, it's unpleasant. To make this easier on the eyes, I had to do the following: * Add a few fixity declarations (search for `infix`) * Add parentheses to make precedence clear, allowing Ormolu to keep everything on one line * Rename `relevantEq` to `(==~)` in #6651 and set it to `infix 4` * Add a few _.ormolu_ files (thanks to @hallettj for helping me get started), mostly for Autodocodec operators that don't have explicit fixity declarations In general, I think these changes are quite reasonable. They mostly affect indentation. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6675 GitOrigin-RevId: cd47d87f1d089fb0bc9dcbbe7798dbceedcd7d83
44 lines
1.7 KiB
Haskell
44 lines
1.7 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.GraphQL.Schema.NamingCase
|
|
import Hasura.GraphQL.Schema.Options qualified as Options
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types.Column
|
|
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 :: Options.StringifyNumbers -> ColumnType ('Postgres pgKind) -> Bool -> Maybe NamingCase -> SQLExp -> SQLExp
|
|
toJSONableExp stringifyNum colType asText tCase expression
|
|
-- If it's 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 Options.StringifyNumbers -> True; Options.Don'tStringifyNumbers -> 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
|
|
| isEnumColumn colType && any isGraphqlCase tCase = applyUppercase expression
|
|
| otherwise = expression
|