2021-04-20 19:57:14 +03:00
|
|
|
module Hasura.SQL.Value where
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Aeson qualified as A
|
|
|
|
import Data.Aeson.Types qualified as AT
|
|
|
|
import Data.Text qualified as T
|
|
|
|
import Hasura.Prelude
|
2021-04-20 19:57:14 +03:00
|
|
|
|
|
|
|
data TxtEncodedVal
|
|
|
|
= TENull
|
|
|
|
| TELit !T.Text
|
|
|
|
deriving (Show, Eq, Generic)
|
|
|
|
|
|
|
|
instance Hashable TxtEncodedVal
|
|
|
|
|
|
|
|
instance A.ToJSON TxtEncodedVal where
|
|
|
|
toJSON = \case
|
2021-09-24 01:56:37 +03:00
|
|
|
TENull -> AT.Null
|
2021-04-20 19:57:14 +03:00
|
|
|
TELit t -> AT.String t
|
|
|
|
|
|
|
|
instance A.FromJSON TxtEncodedVal where
|
2021-09-24 01:56:37 +03:00
|
|
|
parseJSON A.Null = pure TENull
|
2021-04-20 19:57:14 +03:00
|
|
|
parseJSON (A.String t) = pure $ TELit t
|
2021-09-24 01:56:37 +03:00
|
|
|
parseJSON v = AT.typeMismatch "String" v
|