{-# LANGUAGE
ConstraintKinds
, DeriveGeneric
, DerivingStrategies
, FlexibleContexts
, FlexibleInstances
, GADTs
, GeneralizedNewtypeDeriving
, LambdaCase
, MultiParamTypeClasses
, OverloadedLabels
, OverloadedStrings
, QuantifiedConstraints
, ScopedTypeVariables
, StandaloneDeriving
, TypeApplications
, TypeFamilies
, TypeInType
, TypeOperators
, RankNTypes
, UndecidableInstances
#-}
module Squeal.PostgreSQL.Query.Values
(
values
, values_
) where
import Data.ByteString (ByteString)
import Generics.SOP hiding (from)
import Squeal.PostgreSQL.Type.Alias
import Squeal.PostgreSQL.Expression
import Squeal.PostgreSQL.Query
import Squeal.PostgreSQL.Render
values
:: SListI cols
=> NP (Aliased (Expression 'Ungrouped lat with db params '[] )) cols
-> [NP (Aliased (Expression 'Ungrouped lat with db params '[] )) cols]
-> Query lat with db params cols
values :: NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
-> [NP
(Aliased (Expression 'Ungrouped lat with db params '[])) cols]
-> Query lat with db params cols
values NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
rw [NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols]
rws = ByteString -> Query lat with db params cols
forall (lat :: FromType) (with :: FromType) (db :: SchemasType)
(params :: [NullType]) (row :: RowType).
ByteString -> Query lat with db params row
UnsafeQuery (ByteString -> Query lat with db params cols)
-> ByteString -> Query lat with db params cols
forall a b. (a -> b) -> a -> b
$ ByteString
"SELECT * FROM"
ByteString -> ByteString -> ByteString
<+> ByteString -> ByteString
parenthesized (
ByteString
"VALUES"
ByteString -> ByteString -> ByteString
<+> [ByteString] -> ByteString
commaSeparated
( ByteString -> ByteString
parenthesized
(ByteString -> ByteString)
-> (NP
(Aliased (Expression 'Ungrouped lat with db params '[])) cols
-> ByteString)
-> NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall (x :: (Symbol, NullType)).
Aliased (Expression 'Ungrouped lat with db params '[]) x
-> ByteString)
-> NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
-> ByteString
forall k (xs :: [k]) (expression :: k -> *).
SListI xs =>
(forall (x :: k). expression x -> ByteString)
-> NP expression xs -> ByteString
renderCommaSeparated forall (lat :: FromType) (with :: FromType) (db :: SchemasType)
(params :: [NullType]) (ty :: (Symbol, NullType)).
Aliased (Expression 'Ungrouped lat with db params '[]) ty
-> ByteString
forall (x :: (Symbol, NullType)).
Aliased (Expression 'Ungrouped lat with db params '[]) x
-> ByteString
renderValuePart (NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
-> ByteString)
-> [NP
(Aliased (Expression 'Ungrouped lat with db params '[])) cols]
-> [ByteString]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
rwNP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
-> [NP
(Aliased (Expression 'Ungrouped lat with db params '[])) cols]
-> [NP
(Aliased (Expression 'Ungrouped lat with db params '[])) cols]
forall a. a -> [a] -> [a]
:[NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols]
rws )
) ByteString -> ByteString -> ByteString
<+> ByteString
"AS t"
ByteString -> ByteString -> ByteString
<+> ByteString -> ByteString
parenthesized ((forall (x :: (Symbol, NullType)).
Aliased (Expression 'Ungrouped lat with db params '[]) x
-> ByteString)
-> NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
-> ByteString
forall k (xs :: [k]) (expression :: k -> *).
SListI xs =>
(forall (x :: k). expression x -> ByteString)
-> NP expression xs -> ByteString
renderCommaSeparated forall (lat :: FromType) (with :: FromType) (db :: SchemasType)
(params :: [NullType]) (ty :: (Symbol, NullType)).
Aliased (Expression 'Ungrouped lat with db params '[]) ty
-> ByteString
forall (x :: (Symbol, NullType)).
Aliased (Expression 'Ungrouped lat with db params '[]) x
-> ByteString
renderAliasPart NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
rw)
where
renderAliasPart, renderValuePart
:: Aliased (Expression 'Ungrouped lat with db params '[] ) ty -> ByteString
renderAliasPart :: Aliased (Expression 'Ungrouped lat with db params '[]) ty
-> ByteString
renderAliasPart (Expression 'Ungrouped lat with db params '[] ty
_ `As` Alias alias
name) = Alias alias -> ByteString
forall sql. RenderSQL sql => sql -> ByteString
renderSQL Alias alias
name
renderValuePart :: Aliased (Expression 'Ungrouped lat with db params '[]) ty
-> ByteString
renderValuePart (Expression 'Ungrouped lat with db params '[] ty
value `As` Alias alias
_) = Expression 'Ungrouped lat with db params '[] ty -> ByteString
forall sql. RenderSQL sql => sql -> ByteString
renderSQL Expression 'Ungrouped lat with db params '[] ty
value
values_
:: SListI cols
=> NP (Aliased (Expression 'Ungrouped lat with db params '[] )) cols
-> Query lat with db params cols
values_ :: NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
-> Query lat with db params cols
values_ NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
rw = NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
-> [NP
(Aliased (Expression 'Ungrouped lat with db params '[])) cols]
-> Query lat with db params cols
forall (cols :: RowType) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]).
SListI cols =>
NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
-> [NP
(Aliased (Expression 'Ungrouped lat with db params '[])) cols]
-> Query lat with db params cols
values NP (Aliased (Expression 'Ungrouped lat with db params '[])) cols
rw []