{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TemplateHaskell #-}

module Hasura.RQL.Types.Source.Column
  ( SourceColumnInfo (..),
    sciName,
    sciType,
    sciNullable,
    sciDescription,
    sciInsertable,
    sciUpdatable,
    sciValueGenerated,
    ColumnValueGenerationStrategy (..),
  )
where

--------------------------------------------------------------------------------

import Autodocodec
import Autodocodec.OpenAPI ()
import Control.DeepSeq (NFData)
import Control.Lens.TH (makeLenses)
import Data.Aeson (FromJSON, ToJSON)
import Data.HashMap.Strict qualified as HashMap
import Data.Hashable (Hashable)
import Data.OpenApi (ToSchema)
import Data.Text (Text)
import GHC.Generics (Generic)
import Hasura.RQL.Types.Backend (Backend (..))
import Hasura.RQL.Types.Column (RawColumnType (..))
import Prelude

--------------------------------------------------------------------------------

data SourceColumnInfo b = SourceColumnInfo
  { forall (b :: BackendType). SourceColumnInfo b -> Column b
_sciName :: Column b,
    forall (b :: BackendType). SourceColumnInfo b -> RawColumnType b
_sciType :: RawColumnType b,
    forall (b :: BackendType). SourceColumnInfo b -> Bool
_sciNullable :: Bool,
    forall (b :: BackendType). SourceColumnInfo b -> Maybe Text
_sciDescription :: Maybe Text,
    forall (b :: BackendType). SourceColumnInfo b -> Bool
_sciInsertable :: Bool,
    forall (b :: BackendType). SourceColumnInfo b -> Bool
_sciUpdatable :: Bool,
    forall (b :: BackendType).
SourceColumnInfo b -> Maybe ColumnValueGenerationStrategy
_sciValueGenerated :: Maybe ColumnValueGenerationStrategy
  }
  deriving stock ((forall x. SourceColumnInfo b -> Rep (SourceColumnInfo b) x)
-> (forall x. Rep (SourceColumnInfo b) x -> SourceColumnInfo b)
-> Generic (SourceColumnInfo b)
forall x. Rep (SourceColumnInfo b) x -> SourceColumnInfo b
forall x. SourceColumnInfo b -> Rep (SourceColumnInfo b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x.
Rep (SourceColumnInfo b) x -> SourceColumnInfo b
forall (b :: BackendType) x.
SourceColumnInfo b -> Rep (SourceColumnInfo b) x
$cfrom :: forall (b :: BackendType) x.
SourceColumnInfo b -> Rep (SourceColumnInfo b) x
from :: forall x. SourceColumnInfo b -> Rep (SourceColumnInfo b) x
$cto :: forall (b :: BackendType) x.
Rep (SourceColumnInfo b) x -> SourceColumnInfo b
to :: forall x. Rep (SourceColumnInfo b) x -> SourceColumnInfo b
Generic)
  deriving anyclass (Eq (SourceColumnInfo b)
Eq (SourceColumnInfo b)
-> (Int -> SourceColumnInfo b -> Int)
-> (SourceColumnInfo b -> Int)
-> Hashable (SourceColumnInfo b)
Int -> SourceColumnInfo b -> Int
SourceColumnInfo b -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
forall {b :: BackendType}. Backend b => Eq (SourceColumnInfo b)
forall (b :: BackendType).
Backend b =>
Int -> SourceColumnInfo b -> Int
forall (b :: BackendType). Backend b => SourceColumnInfo b -> Int
$chashWithSalt :: forall (b :: BackendType).
Backend b =>
Int -> SourceColumnInfo b -> Int
hashWithSalt :: Int -> SourceColumnInfo b -> Int
$chash :: forall (b :: BackendType). Backend b => SourceColumnInfo b -> Int
hash :: SourceColumnInfo b -> Int
Hashable)
  deriving (Value -> Parser [SourceColumnInfo b]
Value -> Parser (SourceColumnInfo b)
(Value -> Parser (SourceColumnInfo b))
-> (Value -> Parser [SourceColumnInfo b])
-> FromJSON (SourceColumnInfo b)
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
forall (b :: BackendType).
Backend b =>
Value -> Parser [SourceColumnInfo b]
forall (b :: BackendType).
Backend b =>
Value -> Parser (SourceColumnInfo b)
$cparseJSON :: forall (b :: BackendType).
Backend b =>
Value -> Parser (SourceColumnInfo b)
parseJSON :: Value -> Parser (SourceColumnInfo b)
$cparseJSONList :: forall (b :: BackendType).
Backend b =>
Value -> Parser [SourceColumnInfo b]
parseJSONList :: Value -> Parser [SourceColumnInfo b]
FromJSON, [SourceColumnInfo b] -> Value
[SourceColumnInfo b] -> Encoding
SourceColumnInfo b -> Value
SourceColumnInfo b -> Encoding
(SourceColumnInfo b -> Value)
-> (SourceColumnInfo b -> Encoding)
-> ([SourceColumnInfo b] -> Value)
-> ([SourceColumnInfo b] -> Encoding)
-> ToJSON (SourceColumnInfo b)
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
forall (b :: BackendType).
Backend b =>
[SourceColumnInfo b] -> Value
forall (b :: BackendType).
Backend b =>
[SourceColumnInfo b] -> Encoding
forall (b :: BackendType). Backend b => SourceColumnInfo b -> Value
forall (b :: BackendType).
Backend b =>
SourceColumnInfo b -> Encoding
$ctoJSON :: forall (b :: BackendType). Backend b => SourceColumnInfo b -> Value
toJSON :: SourceColumnInfo b -> Value
$ctoEncoding :: forall (b :: BackendType).
Backend b =>
SourceColumnInfo b -> Encoding
toEncoding :: SourceColumnInfo b -> Encoding
$ctoJSONList :: forall (b :: BackendType).
Backend b =>
[SourceColumnInfo b] -> Value
toJSONList :: [SourceColumnInfo b] -> Value
$ctoEncodingList :: forall (b :: BackendType).
Backend b =>
[SourceColumnInfo b] -> Encoding
toEncodingList :: [SourceColumnInfo b] -> Encoding
ToJSON, Typeable (SourceColumnInfo b)
Typeable (SourceColumnInfo b)
-> (Proxy (SourceColumnInfo b)
    -> Declare (Definitions Schema) NamedSchema)
-> ToSchema (SourceColumnInfo b)
Proxy (SourceColumnInfo b)
-> Declare (Definitions Schema) NamedSchema
forall a.
Typeable a
-> (Proxy a -> Declare (Definitions Schema) NamedSchema)
-> ToSchema a
forall {b :: BackendType}.
Backend b =>
Typeable (SourceColumnInfo b)
forall (b :: BackendType).
Backend b =>
Proxy (SourceColumnInfo b)
-> Declare (Definitions Schema) NamedSchema
$cdeclareNamedSchema :: forall (b :: BackendType).
Backend b =>
Proxy (SourceColumnInfo b)
-> Declare (Definitions Schema) NamedSchema
declareNamedSchema :: Proxy (SourceColumnInfo b)
-> Declare (Definitions Schema) NamedSchema
ToSchema) via Autodocodec (SourceColumnInfo b)

deriving instance (Backend b) => Eq (SourceColumnInfo b)

deriving instance (Backend b) => Ord (SourceColumnInfo b)

deriving instance (Backend b) => Show (SourceColumnInfo b)

instance (Backend b) => HasCodec (SourceColumnInfo b) where
  codec :: JSONCodec (SourceColumnInfo b)
codec =
    Text
-> ObjectCodec (SourceColumnInfo b) (SourceColumnInfo b)
-> JSONCodec (SourceColumnInfo b)
forall input output.
Text -> ObjectCodec input output -> ValueCodec input output
object Text
"ColumnInfo" (ObjectCodec (SourceColumnInfo b) (SourceColumnInfo b)
 -> JSONCodec (SourceColumnInfo b))
-> ObjectCodec (SourceColumnInfo b) (SourceColumnInfo b)
-> JSONCodec (SourceColumnInfo b)
forall a b. (a -> b) -> a -> b
$
      Column b
-> RawColumnType b
-> Bool
-> Maybe Text
-> Bool
-> Bool
-> Maybe ColumnValueGenerationStrategy
-> SourceColumnInfo b
forall (b :: BackendType).
Column b
-> RawColumnType b
-> Bool
-> Maybe Text
-> Bool
-> Bool
-> Maybe ColumnValueGenerationStrategy
-> SourceColumnInfo b
SourceColumnInfo
        (Column b
 -> RawColumnType b
 -> Bool
 -> Maybe Text
 -> Bool
 -> Bool
 -> Maybe ColumnValueGenerationStrategy
 -> SourceColumnInfo b)
-> Codec Object (SourceColumnInfo b) (Column b)
-> Codec
     Object
     (SourceColumnInfo b)
     (RawColumnType b
      -> Bool
      -> Maybe Text
      -> Bool
      -> Bool
      -> Maybe ColumnValueGenerationStrategy
      -> SourceColumnInfo b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Text -> ObjectCodec (Column b) (Column b)
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec output output
requiredField Text
"name" Text
"Column name" ObjectCodec (Column b) (Column b)
-> (SourceColumnInfo b -> Column b)
-> Codec Object (SourceColumnInfo b) (Column b)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= SourceColumnInfo b -> Column b
forall (b :: BackendType). SourceColumnInfo b -> Column b
_sciName
        Codec
  Object
  (SourceColumnInfo b)
  (RawColumnType b
   -> Bool
   -> Maybe Text
   -> Bool
   -> Bool
   -> Maybe ColumnValueGenerationStrategy
   -> SourceColumnInfo b)
-> Codec Object (SourceColumnInfo b) (RawColumnType b)
-> Codec
     Object
     (SourceColumnInfo b)
     (Bool
      -> Maybe Text
      -> Bool
      -> Bool
      -> Maybe ColumnValueGenerationStrategy
      -> SourceColumnInfo b)
forall a b.
Codec Object (SourceColumnInfo b) (a -> b)
-> Codec Object (SourceColumnInfo b) a
-> Codec Object (SourceColumnInfo b) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> Text -> ObjectCodec (RawColumnType b) (RawColumnType b)
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec output output
requiredField Text
"type" Text
"Column type" ObjectCodec (RawColumnType b) (RawColumnType b)
-> (SourceColumnInfo b -> RawColumnType b)
-> Codec Object (SourceColumnInfo b) (RawColumnType b)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= SourceColumnInfo b -> RawColumnType b
forall (b :: BackendType). SourceColumnInfo b -> RawColumnType b
_sciType
        Codec
  Object
  (SourceColumnInfo b)
  (Bool
   -> Maybe Text
   -> Bool
   -> Bool
   -> Maybe ColumnValueGenerationStrategy
   -> SourceColumnInfo b)
-> Codec Object (SourceColumnInfo b) Bool
-> Codec
     Object
     (SourceColumnInfo b)
     (Maybe Text
      -> Bool
      -> Bool
      -> Maybe ColumnValueGenerationStrategy
      -> SourceColumnInfo b)
forall a b.
Codec Object (SourceColumnInfo b) (a -> b)
-> Codec Object (SourceColumnInfo b) a
-> Codec Object (SourceColumnInfo b) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> Text -> ObjectCodec Bool Bool
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec output output
requiredField Text
"nullable" Text
"Is column nullable" ObjectCodec Bool Bool
-> (SourceColumnInfo b -> Bool)
-> Codec Object (SourceColumnInfo b) Bool
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= SourceColumnInfo b -> Bool
forall (b :: BackendType). SourceColumnInfo b -> Bool
_sciNullable
        Codec
  Object
  (SourceColumnInfo b)
  (Maybe Text
   -> Bool
   -> Bool
   -> Maybe ColumnValueGenerationStrategy
   -> SourceColumnInfo b)
-> Codec Object (SourceColumnInfo b) (Maybe Text)
-> Codec
     Object
     (SourceColumnInfo b)
     (Bool
      -> Bool
      -> Maybe ColumnValueGenerationStrategy
      -> SourceColumnInfo b)
forall a b.
Codec Object (SourceColumnInfo b) (a -> b)
-> Codec Object (SourceColumnInfo b) a
-> Codec Object (SourceColumnInfo b) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> Text -> ObjectCodec (Maybe Text) (Maybe Text)
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec (Maybe output) (Maybe output)
optionalFieldOrNull Text
"description" Text
"Column description" ObjectCodec (Maybe Text) (Maybe Text)
-> (SourceColumnInfo b -> Maybe Text)
-> Codec Object (SourceColumnInfo b) (Maybe Text)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= SourceColumnInfo b -> Maybe Text
forall (b :: BackendType). SourceColumnInfo b -> Maybe Text
_sciDescription
        Codec
  Object
  (SourceColumnInfo b)
  (Bool
   -> Bool
   -> Maybe ColumnValueGenerationStrategy
   -> SourceColumnInfo b)
-> Codec Object (SourceColumnInfo b) Bool
-> Codec
     Object
     (SourceColumnInfo b)
     (Bool -> Maybe ColumnValueGenerationStrategy -> SourceColumnInfo b)
forall a b.
Codec Object (SourceColumnInfo b) (a -> b)
-> Codec Object (SourceColumnInfo b) a
-> Codec Object (SourceColumnInfo b) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> Bool -> Text -> ObjectCodec Bool Bool
forall output.
HasCodec output =>
Text -> output -> Text -> ObjectCodec output output
optionalFieldWithDefault Text
"insertable" Bool
False Text
"Whether or not the column can be inserted into" ObjectCodec Bool Bool
-> (SourceColumnInfo b -> Bool)
-> Codec Object (SourceColumnInfo b) Bool
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= SourceColumnInfo b -> Bool
forall (b :: BackendType). SourceColumnInfo b -> Bool
_sciInsertable
        Codec
  Object
  (SourceColumnInfo b)
  (Bool -> Maybe ColumnValueGenerationStrategy -> SourceColumnInfo b)
-> Codec Object (SourceColumnInfo b) Bool
-> Codec
     Object
     (SourceColumnInfo b)
     (Maybe ColumnValueGenerationStrategy -> SourceColumnInfo b)
forall a b.
Codec Object (SourceColumnInfo b) (a -> b)
-> Codec Object (SourceColumnInfo b) a
-> Codec Object (SourceColumnInfo b) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> Bool -> Text -> ObjectCodec Bool Bool
forall output.
HasCodec output =>
Text -> output -> Text -> ObjectCodec output output
optionalFieldWithDefault Text
"updatable" Bool
False Text
"Whether or not the column can be updated" ObjectCodec Bool Bool
-> (SourceColumnInfo b -> Bool)
-> Codec Object (SourceColumnInfo b) Bool
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= SourceColumnInfo b -> Bool
forall (b :: BackendType). SourceColumnInfo b -> Bool
_sciUpdatable
        Codec
  Object
  (SourceColumnInfo b)
  (Maybe ColumnValueGenerationStrategy -> SourceColumnInfo b)
-> Codec
     Object (SourceColumnInfo b) (Maybe ColumnValueGenerationStrategy)
-> ObjectCodec (SourceColumnInfo b) (SourceColumnInfo b)
forall a b.
Codec Object (SourceColumnInfo b) (a -> b)
-> Codec Object (SourceColumnInfo b) a
-> Codec Object (SourceColumnInfo b) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text
-> Text
-> ObjectCodec
     (Maybe ColumnValueGenerationStrategy)
     (Maybe ColumnValueGenerationStrategy)
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec (Maybe output) (Maybe output)
optionalFieldOrNull Text
"value_generated" Text
"Whether or not and how the value of the column can be generated by the database" ObjectCodec
  (Maybe ColumnValueGenerationStrategy)
  (Maybe ColumnValueGenerationStrategy)
-> (SourceColumnInfo b -> Maybe ColumnValueGenerationStrategy)
-> Codec
     Object (SourceColumnInfo b) (Maybe ColumnValueGenerationStrategy)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= SourceColumnInfo b -> Maybe ColumnValueGenerationStrategy
forall (b :: BackendType).
SourceColumnInfo b -> Maybe ColumnValueGenerationStrategy
_sciValueGenerated

data ColumnValueGenerationStrategy
  = AutoIncrement
  | UniqueIdentifier
  | DefaultValue
  deriving stock (ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
(ColumnValueGenerationStrategy
 -> ColumnValueGenerationStrategy -> Bool)
-> (ColumnValueGenerationStrategy
    -> ColumnValueGenerationStrategy -> Bool)
-> Eq ColumnValueGenerationStrategy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
== :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
$c/= :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
/= :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
Eq, Eq ColumnValueGenerationStrategy
Eq ColumnValueGenerationStrategy
-> (ColumnValueGenerationStrategy
    -> ColumnValueGenerationStrategy -> Ordering)
-> (ColumnValueGenerationStrategy
    -> ColumnValueGenerationStrategy -> Bool)
-> (ColumnValueGenerationStrategy
    -> ColumnValueGenerationStrategy -> Bool)
-> (ColumnValueGenerationStrategy
    -> ColumnValueGenerationStrategy -> Bool)
-> (ColumnValueGenerationStrategy
    -> ColumnValueGenerationStrategy -> Bool)
-> (ColumnValueGenerationStrategy
    -> ColumnValueGenerationStrategy -> ColumnValueGenerationStrategy)
-> (ColumnValueGenerationStrategy
    -> ColumnValueGenerationStrategy -> ColumnValueGenerationStrategy)
-> Ord ColumnValueGenerationStrategy
ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Ordering
ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> ColumnValueGenerationStrategy
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Ordering
compare :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Ordering
$c< :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
< :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
$c<= :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
<= :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
$c> :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
> :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
$c>= :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
>= :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> Bool
$cmax :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> ColumnValueGenerationStrategy
max :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> ColumnValueGenerationStrategy
$cmin :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> ColumnValueGenerationStrategy
min :: ColumnValueGenerationStrategy
-> ColumnValueGenerationStrategy -> ColumnValueGenerationStrategy
Ord, Int -> ColumnValueGenerationStrategy -> ShowS
[ColumnValueGenerationStrategy] -> ShowS
ColumnValueGenerationStrategy -> String
(Int -> ColumnValueGenerationStrategy -> ShowS)
-> (ColumnValueGenerationStrategy -> String)
-> ([ColumnValueGenerationStrategy] -> ShowS)
-> Show ColumnValueGenerationStrategy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ColumnValueGenerationStrategy -> ShowS
showsPrec :: Int -> ColumnValueGenerationStrategy -> ShowS
$cshow :: ColumnValueGenerationStrategy -> String
show :: ColumnValueGenerationStrategy -> String
$cshowList :: [ColumnValueGenerationStrategy] -> ShowS
showList :: [ColumnValueGenerationStrategy] -> ShowS
Show, (forall x.
 ColumnValueGenerationStrategy
 -> Rep ColumnValueGenerationStrategy x)
-> (forall x.
    Rep ColumnValueGenerationStrategy x
    -> ColumnValueGenerationStrategy)
-> Generic ColumnValueGenerationStrategy
forall x.
Rep ColumnValueGenerationStrategy x
-> ColumnValueGenerationStrategy
forall x.
ColumnValueGenerationStrategy
-> Rep ColumnValueGenerationStrategy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
ColumnValueGenerationStrategy
-> Rep ColumnValueGenerationStrategy x
from :: forall x.
ColumnValueGenerationStrategy
-> Rep ColumnValueGenerationStrategy x
$cto :: forall x.
Rep ColumnValueGenerationStrategy x
-> ColumnValueGenerationStrategy
to :: forall x.
Rep ColumnValueGenerationStrategy x
-> ColumnValueGenerationStrategy
Generic)
  deriving anyclass (ColumnValueGenerationStrategy -> ()
(ColumnValueGenerationStrategy -> ())
-> NFData ColumnValueGenerationStrategy
forall a. (a -> ()) -> NFData a
$crnf :: ColumnValueGenerationStrategy -> ()
rnf :: ColumnValueGenerationStrategy -> ()
NFData, Eq ColumnValueGenerationStrategy
Eq ColumnValueGenerationStrategy
-> (Int -> ColumnValueGenerationStrategy -> Int)
-> (ColumnValueGenerationStrategy -> Int)
-> Hashable ColumnValueGenerationStrategy
Int -> ColumnValueGenerationStrategy -> Int
ColumnValueGenerationStrategy -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> ColumnValueGenerationStrategy -> Int
hashWithSalt :: Int -> ColumnValueGenerationStrategy -> Int
$chash :: ColumnValueGenerationStrategy -> Int
hash :: ColumnValueGenerationStrategy -> Int
Hashable)
  deriving (Value -> Parser [ColumnValueGenerationStrategy]
Value -> Parser ColumnValueGenerationStrategy
(Value -> Parser ColumnValueGenerationStrategy)
-> (Value -> Parser [ColumnValueGenerationStrategy])
-> FromJSON ColumnValueGenerationStrategy
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser ColumnValueGenerationStrategy
parseJSON :: Value -> Parser ColumnValueGenerationStrategy
$cparseJSONList :: Value -> Parser [ColumnValueGenerationStrategy]
parseJSONList :: Value -> Parser [ColumnValueGenerationStrategy]
FromJSON, [ColumnValueGenerationStrategy] -> Value
[ColumnValueGenerationStrategy] -> Encoding
ColumnValueGenerationStrategy -> Value
ColumnValueGenerationStrategy -> Encoding
(ColumnValueGenerationStrategy -> Value)
-> (ColumnValueGenerationStrategy -> Encoding)
-> ([ColumnValueGenerationStrategy] -> Value)
-> ([ColumnValueGenerationStrategy] -> Encoding)
-> ToJSON ColumnValueGenerationStrategy
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: ColumnValueGenerationStrategy -> Value
toJSON :: ColumnValueGenerationStrategy -> Value
$ctoEncoding :: ColumnValueGenerationStrategy -> Encoding
toEncoding :: ColumnValueGenerationStrategy -> Encoding
$ctoJSONList :: [ColumnValueGenerationStrategy] -> Value
toJSONList :: [ColumnValueGenerationStrategy] -> Value
$ctoEncodingList :: [ColumnValueGenerationStrategy] -> Encoding
toEncodingList :: [ColumnValueGenerationStrategy] -> Encoding
ToJSON, Typeable ColumnValueGenerationStrategy
Typeable ColumnValueGenerationStrategy
-> (Proxy ColumnValueGenerationStrategy
    -> Declare (Definitions Schema) NamedSchema)
-> ToSchema ColumnValueGenerationStrategy
Proxy ColumnValueGenerationStrategy
-> Declare (Definitions Schema) NamedSchema
forall a.
Typeable a
-> (Proxy a -> Declare (Definitions Schema) NamedSchema)
-> ToSchema a
$cdeclareNamedSchema :: Proxy ColumnValueGenerationStrategy
-> Declare (Definitions Schema) NamedSchema
declareNamedSchema :: Proxy ColumnValueGenerationStrategy
-> Declare (Definitions Schema) NamedSchema
ToSchema) via Autodocodec ColumnValueGenerationStrategy

-- | We're encoding the different strategies as tagged objects rather than just strings because
-- it is anticipated that additional information may need to be added to each strategy in future.
-- For example, the actual default value (a literal), or what type of unique identifier is being
-- used (eg. a UUID). By using a tagged object, we ensure the addition of such information is not
-- a breaking change to the shape of the JSON.
instance HasCodec ColumnValueGenerationStrategy where
  codec :: JSONCodec ColumnValueGenerationStrategy
codec =
    Text
-> JSONCodec ColumnValueGenerationStrategy
-> JSONCodec ColumnValueGenerationStrategy
forall input output.
Text -> ValueCodec input output -> ValueCodec input output
named Text
"ColumnValueGenerationStrategy" (JSONCodec ColumnValueGenerationStrategy
 -> JSONCodec ColumnValueGenerationStrategy)
-> JSONCodec ColumnValueGenerationStrategy
-> JSONCodec ColumnValueGenerationStrategy
forall a b. (a -> b) -> a -> b
$ Text
-> ObjectCodec
     ColumnValueGenerationStrategy ColumnValueGenerationStrategy
-> JSONCodec ColumnValueGenerationStrategy
forall input output.
Text -> ObjectCodec input output -> ValueCodec input output
object Text
"ColumnValueGenerationStrategy" (ObjectCodec
   ColumnValueGenerationStrategy ColumnValueGenerationStrategy
 -> JSONCodec ColumnValueGenerationStrategy)
-> ObjectCodec
     ColumnValueGenerationStrategy ColumnValueGenerationStrategy
-> JSONCodec ColumnValueGenerationStrategy
forall a b. (a -> b) -> a -> b
$ Text
-> (ColumnValueGenerationStrategy
    -> (Text, ObjectCodec ColumnValueGenerationStrategy ()))
-> HashMap
     Text (Text, ObjectCodec Void ColumnValueGenerationStrategy)
-> ObjectCodec
     ColumnValueGenerationStrategy ColumnValueGenerationStrategy
forall input output.
Text
-> (input -> (Text, ObjectCodec input ()))
-> HashMap Text (Text, ObjectCodec Void output)
-> ObjectCodec input output
discriminatedUnionCodec Text
"type" ColumnValueGenerationStrategy
-> (Text, ObjectCodec ColumnValueGenerationStrategy ())
enc HashMap Text (Text, ObjectCodec Void ColumnValueGenerationStrategy)
dec
    where
      autoIncrementCodec :: Codec Object () ()
autoIncrementCodec = () -> Codec Object () ()
forall a. a -> Codec Object () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
      uniqueIdentifierCodec :: Codec Object () ()
uniqueIdentifierCodec = () -> Codec Object () ()
forall a. a -> Codec Object () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
      defaultCodec :: Codec Object () ()
defaultCodec = () -> Codec Object () ()
forall a. a -> Codec Object () a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
      enc :: ColumnValueGenerationStrategy
-> (Text, ObjectCodec ColumnValueGenerationStrategy ())
enc = \case
        ColumnValueGenerationStrategy
AutoIncrement -> (Text
"auto_increment", ()
-> Codec Object () ()
-> ObjectCodec ColumnValueGenerationStrategy ()
forall b context any a.
b -> Codec context b any -> Codec context a ()
mapToEncoder () Codec Object () ()
autoIncrementCodec)
        ColumnValueGenerationStrategy
UniqueIdentifier -> (Text
"unique_identifier", ()
-> Codec Object () ()
-> ObjectCodec ColumnValueGenerationStrategy ()
forall b context any a.
b -> Codec context b any -> Codec context a ()
mapToEncoder () Codec Object () ()
uniqueIdentifierCodec)
        ColumnValueGenerationStrategy
DefaultValue -> (Text
"default_value", ()
-> Codec Object () ()
-> ObjectCodec ColumnValueGenerationStrategy ()
forall b context any a.
b -> Codec context b any -> Codec context a ()
mapToEncoder () Codec Object () ()
defaultCodec)
      dec :: HashMap Text (Text, ObjectCodec Void ColumnValueGenerationStrategy)
dec =
        [(Text, (Text, ObjectCodec Void ColumnValueGenerationStrategy))]
-> HashMap
     Text (Text, ObjectCodec Void ColumnValueGenerationStrategy)
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
          [ (Text
"auto_increment", (Text
"AutoIncrementGenerationStrategy", (() -> ColumnValueGenerationStrategy)
-> Codec Object () ()
-> ObjectCodec Void ColumnValueGenerationStrategy
forall b a context any.
(b -> a) -> Codec context any b -> Codec context Void a
mapToDecoder (ColumnValueGenerationStrategy
-> () -> ColumnValueGenerationStrategy
forall a b. a -> b -> a
const ColumnValueGenerationStrategy
AutoIncrement) Codec Object () ()
autoIncrementCodec)),
            (Text
"unique_identifier", (Text
"UniqueIdentifierGenerationStrategy", (() -> ColumnValueGenerationStrategy)
-> Codec Object () ()
-> ObjectCodec Void ColumnValueGenerationStrategy
forall b a context any.
(b -> a) -> Codec context any b -> Codec context Void a
mapToDecoder (ColumnValueGenerationStrategy
-> () -> ColumnValueGenerationStrategy
forall a b. a -> b -> a
const ColumnValueGenerationStrategy
UniqueIdentifier) Codec Object () ()
uniqueIdentifierCodec)),
            (Text
"default_value", (Text
"DefaultValueGenerationStrategy", (() -> ColumnValueGenerationStrategy)
-> Codec Object () ()
-> ObjectCodec Void ColumnValueGenerationStrategy
forall b a context any.
(b -> a) -> Codec context any b -> Codec context Void a
mapToDecoder (ColumnValueGenerationStrategy
-> () -> ColumnValueGenerationStrategy
forall a b. a -> b -> a
const ColumnValueGenerationStrategy
DefaultValue) Codec Object () ()
uniqueIdentifierCodec))
          ]

$(makeLenses ''SourceColumnInfo)