{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE ConstraintKinds #-}
module Database.Relational.ProjectableClass (
LiteralSQL (..), showLiteral,
StringSQL,
ShowConstantTermsSQL, showConstantTermsSQL', showConstantTermsSQL,
) where
import GHC.Generics (Generic, Rep, U1 (..), K1 (..), M1 (..), (:*:)(..), from)
import Data.Monoid (mempty, (<>))
import Data.DList (DList, toList)
import Database.Relational.Internal.String (StringSQL)
showLiteral :: LiteralSQL a
=> a
-> [StringSQL]
showLiteral :: forall a. LiteralSQL a => a -> [StringSQL]
showLiteral = forall a. DList a -> [a]
toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. LiteralSQL a => a -> DList StringSQL
showLiteral'
class LiteralSQL a where
showLiteral' :: a -> DList StringSQL
default showLiteral' :: (Generic a, GLiteralSQL (Rep a)) => a -> DList StringSQL
showLiteral' = forall (f :: * -> *) a. GLiteralSQL f => f a -> DList StringSQL
gShowLiteral forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from
class GLiteralSQL f where
gShowLiteral :: f a -> DList StringSQL
instance GLiteralSQL U1 where
gShowLiteral :: forall a. U1 a -> DList StringSQL
gShowLiteral U1 a
U1 = forall a. Monoid a => a
mempty
instance (GLiteralSQL a, GLiteralSQL b) =>
GLiteralSQL (a :*: b) where
gShowLiteral :: forall a. (:*:) a b a -> DList StringSQL
gShowLiteral (a a
a :*: b a
b) = forall (f :: * -> *) a. GLiteralSQL f => f a -> DList StringSQL
gShowLiteral a a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. GLiteralSQL f => f a -> DList StringSQL
gShowLiteral b a
b
instance GLiteralSQL a => GLiteralSQL (M1 i c a) where
gShowLiteral :: forall a. M1 i c a a -> DList StringSQL
gShowLiteral (M1 a a
a) = forall (f :: * -> *) a. GLiteralSQL f => f a -> DList StringSQL
gShowLiteral a a
a
instance ShowConstantTermsSQL a => GLiteralSQL (K1 i a) where
gShowLiteral :: forall a. K1 i a a -> DList StringSQL
gShowLiteral (K1 a
a) = forall a. LiteralSQL a => a -> DList StringSQL
showLiteral' a
a
{-# DEPRECATED ShowConstantTermsSQL "Use `LiteralSQL` instead of this." #-}
type ShowConstantTermsSQL = LiteralSQL
{-# DEPRECATED showConstantTermsSQL' "Use `showLiteral'` instead of this." #-}
showConstantTermsSQL' :: ShowConstantTermsSQL a => a -> DList StringSQL
showConstantTermsSQL' :: forall a. LiteralSQL a => a -> DList StringSQL
showConstantTermsSQL' = forall a. LiteralSQL a => a -> DList StringSQL
showLiteral'
{-# DEPRECATED showConstantTermsSQL "Use `showLiteral` instead of this." #-}
showConstantTermsSQL :: ShowConstantTermsSQL a
=> a
-> [StringSQL]
showConstantTermsSQL :: forall a. LiteralSQL a => a -> [StringSQL]
showConstantTermsSQL = forall a. DList a -> [a]
toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. LiteralSQL a => a -> DList StringSQL
showConstantTermsSQL'