{-# LANGUAGE
DataKinds
, GADTs
, LambdaCase
, OverloadedStrings
, PatternSynonyms
, PolyKinds
, QuantifiedConstraints
, RankNTypes
, TypeOperators
#-}
module Squeal.PostgreSQL.Expression.Default
(
Optional (..)
, mapOptional
, pattern NotDefault
) where
import Data.Kind
import Generics.SOP
import Squeal.PostgreSQL.Render
import Squeal.PostgreSQL.Type.Schema
data Optional (expr :: k -> Type) (ty :: (Optionality, k)) where
Default :: Optional expr ('Def :=> ty)
Set :: expr ty -> Optional expr (def :=> ty)
instance (forall x. RenderSQL (expr x)) => RenderSQL (Optional expr ty) where
renderSQL = \case
Default -> "DEFAULT"
Set x -> renderSQL x
mapOptional
:: (expr x -> expr y)
-> Optional expr (def :=> x)
-> Optional expr (def :=> y)
mapOptional f = \case
Default -> Default
Set x -> Set (f x)
pattern NotDefault :: ty -> Optional I ('Def :=> ty)
pattern NotDefault x = Set (I x)