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