{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeApplications #-}
{-# language DerivingStrategies, GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
module Database.Esqueleto.Internal.Internal where
import Control.Applicative ((<|>))
import Control.Arrow (first, (***))
import Control.Exception (Exception, throw, throwIO)
import Control.Monad (MonadPlus(..), guard, void)
import Control.Monad.IO.Class (MonadIO(..))
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Resource (MonadResource, release)
import Data.Acquire (Acquire, allocateAcquire, with)
import Data.Int (Int64)
import Data.List (intersperse)
import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.List.NonEmpty as NEL
import qualified Data.Maybe as Maybe
#if __GLASGOW_HASKELL__ < 804
import Data.Semigroup
#endif
import qualified Control.Monad.Trans.Reader as R
import qualified Control.Monad.Trans.State as S
import qualified Control.Monad.Trans.Writer as W
import qualified Data.ByteString as B
import Data.Coerce (coerce)
import qualified Data.Conduit as C
import qualified Data.Conduit.List as CL
import qualified Data.HashSet as HS
import Data.Kind (Type)
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import qualified Data.Monoid as Monoid
import Data.Proxy (Proxy(..))
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Builder as TLB
import Data.Typeable (Typeable)
import Database.Esqueleto.Internal.ExprParser (TableAccess(..), parseOnExpr)
import Database.Esqueleto.Internal.PersistentImport
import Database.Persist (EntityNameDB(..), FieldNameDB(..), SymbolToField(..))
import qualified Database.Persist
import Database.Persist.Sql.Util
( entityColumnCount
, isIdField
, keyAndEntityColumnNames
, parseEntityValues
)
import Database.Persist.SqlBackend
import GHC.Records
import GHC.TypeLits
import Text.Blaze.Html (Html)
fromStart
:: forall a.
( PersistEntity a
, BackendCompatible SqlBackend (PersistEntityBackend a)
)
=> SqlQuery (PreprocessedFrom (SqlExpr (Entity a)))
fromStart :: forall a.
(PersistEntity a,
BackendCompatible SqlBackend (PersistEntityBackend a)) =>
SqlQuery (PreprocessedFrom (SqlExpr (Entity a)))
fromStart = do
let ed :: EntityDef
ed = Proxy a -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy a -> EntityDef
entityDef (Proxy a
forall {k} (t :: k). Proxy t
Proxy :: Proxy a)
Ident
ident <- DBName -> SqlQuery Ident
newIdentFor (EntityNameDB -> DBName
forall a b. Coercible a b => a -> b
coerce (EntityNameDB -> DBName) -> EntityNameDB -> DBName
forall a b. (a -> b) -> a -> b
$ EntityDef -> EntityNameDB
getEntityDBName EntityDef
ed)
let ret :: SqlExpr (Entity a)
ret = Ident -> SqlExpr (Entity a)
forall ent. PersistEntity ent => Ident -> SqlExpr (Entity ent)
unsafeSqlEntity Ident
ident
f' :: FromClause
f' = Ident -> EntityDef -> FromClause
FromStart Ident
ident EntityDef
ed
PreprocessedFrom (SqlExpr (Entity a))
-> SqlQuery (PreprocessedFrom (SqlExpr (Entity a)))
forall a. a -> SqlQuery a
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlExpr (Entity a)
-> FromClause -> PreprocessedFrom (SqlExpr (Entity a))
forall a. a -> FromClause -> PreprocessedFrom a
PreprocessedFrom SqlExpr (Entity a)
ret FromClause
f')
newtype DBName = DBName { DBName -> Text
unDBName :: T.Text }
fromStartMaybe
:: ( PersistEntity a
, BackendCompatible SqlBackend (PersistEntityBackend a)
)
=> SqlQuery (PreprocessedFrom (SqlExpr (Maybe (Entity a))))
fromStartMaybe :: forall a.
(PersistEntity a,
BackendCompatible SqlBackend (PersistEntityBackend a)) =>
SqlQuery (PreprocessedFrom (SqlExpr (Maybe (Entity a))))
fromStartMaybe = PreprocessedFrom (SqlExpr (Entity a))
-> PreprocessedFrom (SqlExpr (Maybe (Entity a)))
forall a.
PreprocessedFrom (SqlExpr (Entity a))
-> PreprocessedFrom (SqlExpr (Maybe (Entity a)))
maybelize (PreprocessedFrom (SqlExpr (Entity a))
-> PreprocessedFrom (SqlExpr (Maybe (Entity a))))
-> SqlQuery (PreprocessedFrom (SqlExpr (Entity a)))
-> SqlQuery (PreprocessedFrom (SqlExpr (Maybe (Entity a))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SqlQuery (PreprocessedFrom (SqlExpr (Entity a)))
forall a.
(PersistEntity a,
BackendCompatible SqlBackend (PersistEntityBackend a)) =>
SqlQuery (PreprocessedFrom (SqlExpr (Entity a)))
fromStart
where
maybelize
:: PreprocessedFrom (SqlExpr (Entity a))
-> PreprocessedFrom (SqlExpr (Maybe (Entity a)))
maybelize :: forall a.
PreprocessedFrom (SqlExpr (Entity a))
-> PreprocessedFrom (SqlExpr (Maybe (Entity a)))
maybelize (PreprocessedFrom SqlExpr (Entity a)
e FromClause
f') = SqlExpr (Maybe (Entity a))
-> FromClause -> PreprocessedFrom (SqlExpr (Maybe (Entity a)))
forall a. a -> FromClause -> PreprocessedFrom a
PreprocessedFrom (SqlExpr (Entity a) -> SqlExpr (Maybe (Entity a))
forall a b. Coercible a b => a -> b
coerce SqlExpr (Entity a)
e) FromClause
f'
fromJoin
:: IsJoinKind join
=> PreprocessedFrom a
-> PreprocessedFrom b
-> SqlQuery (PreprocessedFrom (join a b))
fromJoin :: forall (join :: * -> * -> *) a b.
IsJoinKind join =>
PreprocessedFrom a
-> PreprocessedFrom b -> SqlQuery (PreprocessedFrom (join a b))
fromJoin (PreprocessedFrom a
lhsRet FromClause
lhsFrom)
(PreprocessedFrom b
rhsRet FromClause
rhsFrom) = WriterT
SideData (StateT IdentState Identity) (PreprocessedFrom (join a b))
-> SqlQuery (PreprocessedFrom (join a b))
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (WriterT
SideData (StateT IdentState Identity) (PreprocessedFrom (join a b))
-> SqlQuery (PreprocessedFrom (join a b)))
-> WriterT
SideData (StateT IdentState Identity) (PreprocessedFrom (join a b))
-> SqlQuery (PreprocessedFrom (join a b))
forall a b. (a -> b) -> a -> b
$ do
let ret :: join a b
ret = a -> b -> join a b
forall a b. a -> b -> join a b
forall (join :: * -> * -> *) a b.
IsJoinKind join =>
a -> b -> join a b
smartJoin a
lhsRet b
rhsRet
from' :: FromClause
from' =
FromClause
-> JoinKind
-> FromClause
-> Maybe (SqlExpr (Value Bool))
-> FromClause
FromJoin
FromClause
lhsFrom
(join a b -> JoinKind
forall a b. join a b -> JoinKind
forall (join :: * -> * -> *) a b.
IsJoinKind join =>
join a b -> JoinKind
reifyJoinKind join a b
ret)
FromClause
rhsFrom
Maybe (SqlExpr (Value Bool))
forall a. Maybe a
Nothing
PreprocessedFrom (join a b)
-> WriterT
SideData (StateT IdentState Identity) (PreprocessedFrom (join a b))
forall a. a -> WriterT SideData (StateT IdentState Identity) a
forall (m :: * -> *) a. Monad m => a -> m a
return (join a b -> FromClause -> PreprocessedFrom (join a b)
forall a. a -> FromClause -> PreprocessedFrom a
PreprocessedFrom join a b
ret FromClause
from')
fromFinish
:: PreprocessedFrom a
-> SqlQuery a
fromFinish :: forall a. PreprocessedFrom a -> SqlQuery a
fromFinish (PreprocessedFrom a
ret FromClause
f') = WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (WriterT SideData (StateT IdentState Identity) a -> SqlQuery a)
-> WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
forall a b. (a -> b) -> a -> b
$ do
SideData -> WriterT SideData (StateT IdentState Identity) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdFromClause = [f'] }
a -> WriterT SideData (StateT IdentState Identity) a
forall a. a -> WriterT SideData (StateT IdentState Identity) a
forall (m :: * -> *) a. Monad m => a -> m a
return a
ret
where_ :: SqlExpr (Value Bool) -> SqlQuery ()
where_ :: SqlExpr (Value Bool) -> SqlQuery ()
where_ SqlExpr (Value Bool)
expr = WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (WriterT SideData (StateT IdentState Identity) () -> SqlQuery ())
-> WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (StateT IdentState Identity) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdWhereClause = Where expr }
on :: SqlExpr (Value Bool) -> SqlQuery ()
on :: SqlExpr (Value Bool) -> SqlQuery ()
on SqlExpr (Value Bool)
expr = WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (WriterT SideData (StateT IdentState Identity) () -> SqlQuery ())
-> WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (StateT IdentState Identity) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdFromClause = [OnClause expr] }
groupBy :: (ToSomeValues a) => a -> SqlQuery ()
groupBy :: forall a. ToSomeValues a => a -> SqlQuery ()
groupBy a
expr = WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (WriterT SideData (StateT IdentState Identity) () -> SqlQuery ())
-> WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (StateT IdentState Identity) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdGroupByClause = GroupBy $ toSomeValues expr }
groupBy_ :: (ToSomeValues a) => a -> SqlQuery ()
groupBy_ :: forall a. ToSomeValues a => a -> SqlQuery ()
groupBy_ = a -> SqlQuery ()
forall a. ToSomeValues a => a -> SqlQuery ()
groupBy
orderBy :: [SqlExpr OrderBy] -> SqlQuery ()
orderBy :: [SqlExpr OrderBy] -> SqlQuery ()
orderBy [SqlExpr OrderBy]
exprs = WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (WriterT SideData (StateT IdentState Identity) () -> SqlQuery ())
-> WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (StateT IdentState Identity) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdOrderByClause = exprs }
asc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
asc :: forall a. PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
asc = Builder -> SqlExpr (Value a) -> SqlExpr OrderBy
forall a. Builder -> SqlExpr (Value a) -> SqlExpr OrderBy
orderByExpr Builder
" ASC"
desc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
desc :: forall a. PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
desc = Builder -> SqlExpr (Value a) -> SqlExpr OrderBy
forall a. Builder -> SqlExpr (Value a) -> SqlExpr OrderBy
orderByExpr Builder
" DESC"
orderByExpr :: TLB.Builder -> SqlExpr (Value a) -> SqlExpr OrderBy
orderByExpr :: forall a. Builder -> SqlExpr (Value a) -> SqlExpr OrderBy
orderByExpr Builder
orderByType (ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f)
| Just IdentInfo -> [Builder]
fields <- SqlExprMeta -> Maybe (IdentInfo -> [Builder])
sqlExprMetaCompositeFields SqlExprMeta
m =
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr OrderBy
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr OrderBy)
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr OrderBy
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info ->
let fs :: [Builder]
fs = IdentInfo -> [Builder]
fields IdentInfo
info
vals :: [[a]]
vals = [a] -> [[a]]
forall a. a -> [a]
repeat []
in [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas' ([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ [Builder] -> [[PersistValue]] -> [(Builder, [PersistValue])]
forall a b. [a] -> [b] -> [(a, b)]
zip ((Builder -> Builder) -> [Builder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
orderByType) [Builder]
fs) [[PersistValue]]
forall {a}. [[a]]
vals
| Bool
otherwise =
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr OrderBy
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr OrderBy)
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr OrderBy
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info ->
(Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
orderByType) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info
limit :: Int64 -> SqlQuery ()
limit :: Int64 -> SqlQuery ()
limit Int64
n = WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (WriterT SideData (StateT IdentState Identity) () -> SqlQuery ())
-> WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (StateT IdentState Identity) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdLimitClause = Limit (Just n) Nothing }
offset :: Int64 -> SqlQuery ()
offset :: Int64 -> SqlQuery ()
offset Int64
n = WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (WriterT SideData (StateT IdentState Identity) () -> SqlQuery ())
-> WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (StateT IdentState Identity) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdLimitClause = Limit Nothing (Just n) }
distinct :: SqlQuery a -> SqlQuery a
distinct :: forall a. SqlQuery a -> SqlQuery a
distinct SqlQuery a
act = WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (SideData -> WriterT SideData (StateT IdentState Identity) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdDistinctClause = DistinctStandard }) SqlQuery () -> SqlQuery a -> SqlQuery a
forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SqlQuery a
act
distinctOn :: [SqlExpr DistinctOn] -> SqlQuery a -> SqlQuery a
distinctOn :: forall a. [SqlExpr DistinctOn] -> SqlQuery a -> SqlQuery a
distinctOn [SqlExpr DistinctOn]
exprs SqlQuery a
act = WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (SideData -> WriterT SideData (StateT IdentState Identity) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdDistinctClause = DistinctOn exprs }) SqlQuery () -> SqlQuery a -> SqlQuery a
forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SqlQuery a
act
don :: SqlExpr (Value a) -> SqlExpr DistinctOn
don :: forall a. SqlExpr (Value a) -> SqlExpr DistinctOn
don = SqlExpr (Value a) -> SqlExpr DistinctOn
forall a b. Coercible a b => a -> b
coerce
distinctOnOrderBy :: [SqlExpr OrderBy] -> SqlQuery a -> SqlQuery a
distinctOnOrderBy :: forall a. [SqlExpr OrderBy] -> SqlQuery a -> SqlQuery a
distinctOnOrderBy [SqlExpr OrderBy]
exprs SqlQuery a
act =
[SqlExpr DistinctOn] -> SqlQuery a -> SqlQuery a
forall a. [SqlExpr DistinctOn] -> SqlQuery a -> SqlQuery a
distinctOn (SqlExpr OrderBy -> SqlExpr DistinctOn
toDistinctOn (SqlExpr OrderBy -> SqlExpr DistinctOn)
-> [SqlExpr OrderBy] -> [SqlExpr DistinctOn]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [SqlExpr OrderBy]
exprs) (SqlQuery a -> SqlQuery a) -> SqlQuery a -> SqlQuery a
forall a b. (a -> b) -> a -> b
$ do
[SqlExpr OrderBy] -> SqlQuery ()
orderBy [SqlExpr OrderBy]
exprs
SqlQuery a
act
where
toDistinctOn :: SqlExpr OrderBy -> SqlExpr DistinctOn
toDistinctOn :: SqlExpr OrderBy -> SqlExpr DistinctOn
toDistinctOn (ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr DistinctOn
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
m ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr DistinctOn)
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr DistinctOn
forall a b. (a -> b) -> a -> b
$ \NeedParens
p IdentInfo
info ->
let (Builder
b, [PersistValue]
vals) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
p IdentInfo
info
in ( Text -> Builder
TLB.fromLazyText
(Text -> Builder) -> Text -> Builder
forall a b. (a -> b) -> a -> b
$ HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
TL.replace Text
" DESC" Text
""
(Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ HasCallStack => Text -> Text -> Text -> Text
Text -> Text -> Text -> Text
TL.replace Text
" ASC" Text
""
(Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Builder -> Text
TLB.toLazyText Builder
b
, [PersistValue]
vals )
rand :: SqlExpr OrderBy
rand :: SqlExpr OrderBy
rand = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr OrderBy
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr OrderBy)
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr OrderBy
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
_ -> (Builder
"RANDOM()", [])
having :: SqlExpr (Value Bool) -> SqlQuery ()
having :: SqlExpr (Value Bool) -> SqlQuery ()
having SqlExpr (Value Bool)
expr = WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (WriterT SideData (StateT IdentState Identity) () -> SqlQuery ())
-> WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (StateT IdentState Identity) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdHavingClause = Where expr }
locking :: LockingKind -> SqlQuery ()
locking :: LockingKind -> SqlQuery ()
locking LockingKind
kind = LockingClause -> SqlQuery ()
putLocking (LockingClause -> SqlQuery ()) -> LockingClause -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ LockingKind -> LockingClause
LegacyLockingClause LockingKind
kind
putLocking :: LockingClause -> SqlQuery ()
putLocking :: LockingClause -> SqlQuery ()
putLocking LockingClause
clause = WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (WriterT SideData (StateT IdentState Identity) () -> SqlQuery ())
-> WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (StateT IdentState Identity) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdLockingClause = clause }
{-#
DEPRECATED
sub_select
"sub_select \n \
sub_select is an unsafe function to use. If used with a SqlQuery that \n \
returns 0 results, then it may return NULL despite not mentioning Maybe \n \
in the return type. If it returns more than 1 result, then it will throw a \n \
SQL error.\n\n Instead, consider using one of the following alternatives: \n \
- subSelect: attaches a LIMIT 1 and the Maybe return type, totally safe. \n \
- subSelectMaybe: Attaches a LIMIT 1, useful for a query that already \n \
has a Maybe in the return type. \n \
- subSelectCount: Performs a count of the query - this is always safe. \n \
- subSelectUnsafe: Performs no checks or guarantees. Safe to use with \n \
countRows and friends."
#-}
sub_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
sub_select :: forall a.
PersistField a =>
SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
sub_select = Mode -> SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
forall a.
PersistField a =>
Mode -> SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
sub Mode
SELECT
subSelect
:: PersistField a
=> SqlQuery (SqlExpr (Value a))
-> SqlExpr (Value (Maybe a))
subSelect :: forall a.
PersistField a =>
SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value (Maybe a))
subSelect SqlQuery (SqlExpr (Value a))
query = SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
forall typ. SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))
just (SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
forall a.
PersistField a =>
SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
subSelectUnsafe (SqlQuery (SqlExpr (Value a))
query SqlQuery (SqlExpr (Value a))
-> SqlQuery () -> SqlQuery (SqlExpr (Value a))
forall a b. SqlQuery a -> SqlQuery b -> SqlQuery a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Int64 -> SqlQuery ()
limit Int64
1))
subSelectMaybe
:: PersistField a
=> SqlQuery (SqlExpr (Value (Maybe a)))
-> SqlExpr (Value (Maybe a))
subSelectMaybe :: forall a.
PersistField a =>
SqlQuery (SqlExpr (Value (Maybe a))) -> SqlExpr (Value (Maybe a))
subSelectMaybe = SqlExpr (Value (Maybe (Maybe a))) -> SqlExpr (Value (Maybe a))
forall typ.
SqlExpr (Value (Maybe (Maybe typ))) -> SqlExpr (Value (Maybe typ))
joinV (SqlExpr (Value (Maybe (Maybe a))) -> SqlExpr (Value (Maybe a)))
-> (SqlQuery (SqlExpr (Value (Maybe a)))
-> SqlExpr (Value (Maybe (Maybe a))))
-> SqlQuery (SqlExpr (Value (Maybe a)))
-> SqlExpr (Value (Maybe a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlQuery (SqlExpr (Value (Maybe a)))
-> SqlExpr (Value (Maybe (Maybe a)))
forall a.
PersistField a =>
SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value (Maybe a))
subSelect
subSelectCount
:: (Num a, PersistField a)
=> SqlQuery ignored
-> SqlExpr (Value a)
subSelectCount :: forall a ignored.
(Num a, PersistField a) =>
SqlQuery ignored -> SqlExpr (Value a)
subSelectCount SqlQuery ignored
query =
SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
forall a.
PersistField a =>
SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
subSelectUnsafe (SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a))
-> SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
forall a b. (a -> b) -> a -> b
$ do
ignored
_ <- SqlQuery ignored
query
SqlExpr (Value a) -> SqlQuery (SqlExpr (Value a))
forall a. a -> SqlQuery a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SqlExpr (Value a)
forall a. Num a => SqlExpr (Value a)
countRows
subSelectList
:: PersistField a
=> SqlQuery (SqlExpr (Value a))
-> SqlExpr (ValueList a)
subSelectList :: forall a.
PersistField a =>
SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)
subSelectList = SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)
forall a.
PersistField a =>
SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)
subList_select
subSelectForeign
::
( BackendCompatible SqlBackend (PersistEntityBackend val1)
, PersistEntity val1, PersistEntity val2, PersistField a
)
=> SqlExpr (Entity val2)
-> EntityField val2 (Key val1)
-> (SqlExpr (Entity val1) -> SqlExpr (Value a))
-> SqlExpr (Value a)
subSelectForeign :: forall val1 val2 a.
(BackendCompatible SqlBackend (PersistEntityBackend val1),
PersistEntity val1, PersistEntity val2, PersistField a) =>
SqlExpr (Entity val2)
-> EntityField val2 (Key val1)
-> (SqlExpr (Entity val1) -> SqlExpr (Value a))
-> SqlExpr (Value a)
subSelectForeign SqlExpr (Entity val2)
expr EntityField val2 (Key val1)
foreignKey SqlExpr (Entity val1) -> SqlExpr (Value a)
k =
SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
forall a.
PersistField a =>
SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
subSelectUnsafe (SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a))
-> SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
forall a b. (a -> b) -> a -> b
$
(SqlExpr (Entity val1) -> SqlQuery (SqlExpr (Value a)))
-> SqlQuery (SqlExpr (Value a))
forall a b. From a => (a -> SqlQuery b) -> SqlQuery b
from ((SqlExpr (Entity val1) -> SqlQuery (SqlExpr (Value a)))
-> SqlQuery (SqlExpr (Value a)))
-> (SqlExpr (Entity val1) -> SqlQuery (SqlExpr (Value a)))
-> SqlQuery (SqlExpr (Value a))
forall a b. (a -> b) -> a -> b
$ \SqlExpr (Entity val1)
table -> do
SqlExpr (Value Bool) -> SqlQuery ()
where_ (SqlExpr (Value Bool) -> SqlQuery ())
-> SqlExpr (Value Bool) -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SqlExpr (Entity val2)
expr SqlExpr (Entity val2)
-> EntityField val2 (Key val1) -> SqlExpr (Value (Key val1))
forall typ val.
(PersistEntity val, PersistField typ) =>
SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
^. EntityField val2 (Key val1)
foreignKey SqlExpr (Value (Key val1))
-> SqlExpr (Value (Key val1)) -> SqlExpr (Value Bool)
forall typ.
PersistField typ =>
SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
==. SqlExpr (Entity val1)
table SqlExpr (Entity val1)
-> EntityField val1 (Key val1) -> SqlExpr (Value (Key val1))
forall typ val.
(PersistEntity val, PersistField typ) =>
SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
^. EntityField val1 (Key val1)
forall record.
PersistEntity record =>
EntityField record (Key record)
persistIdField
SqlExpr (Value a) -> SqlQuery (SqlExpr (Value a))
forall a. a -> SqlQuery a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SqlExpr (Entity val1) -> SqlExpr (Value a)
k SqlExpr (Entity val1)
table)
subSelectUnsafe :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
subSelectUnsafe :: forall a.
PersistField a =>
SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
subSelectUnsafe = Mode -> SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
forall a.
PersistField a =>
Mode -> SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
sub Mode
SELECT
(^.) :: forall typ val . (PersistEntity val, PersistField typ)
=> SqlExpr (Entity val)
-> EntityField val typ
-> SqlExpr (Value typ)
ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f ^. :: forall typ val.
(PersistEntity val, PersistField typ) =>
SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
^. EntityField val typ
field
| EntityField val typ -> Bool
forall record typ.
PersistEntity record =>
EntityField record typ -> Bool
isIdField EntityField val typ
field = SqlExpr (Value typ)
idFieldValue
| Just Ident
alias <- SqlExprMeta -> Maybe Ident
sqlExprMetaAlias SqlExprMeta
m =
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info ->
NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info (Builder, [PersistValue])
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a. Semigroup a => a -> a -> a
<> (Builder
"." Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> IdentInfo -> Ident -> Builder
useIdent IdentInfo
info (Ident -> FieldDef -> Ident
aliasedEntityColumnIdent Ident
alias FieldDef
fieldDef), [])
| Bool
otherwise = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info -> (IdentInfo -> FieldDef -> Builder
dot IdentInfo
info (FieldDef -> Builder) -> FieldDef -> Builder
forall a b. (a -> b) -> a -> b
$ EntityField val typ -> FieldDef
forall record typ.
PersistEntity record =>
EntityField record typ -> FieldDef
forall typ. EntityField val typ -> FieldDef
persistFieldDef EntityField val typ
field, [])
where
fieldDef :: FieldDef
fieldDef =
if EntityField val typ -> Bool
forall record typ.
PersistEntity record =>
EntityField record typ -> Bool
isIdField EntityField val typ
field then
NonEmpty FieldDef -> FieldDef
forall a. NonEmpty a -> a
NEL.head (NonEmpty FieldDef -> FieldDef) -> NonEmpty FieldDef -> FieldDef
forall a b. (a -> b) -> a -> b
$ EntityDef -> NonEmpty FieldDef
getEntityKeyFields EntityDef
ed
else
EntityField val typ -> FieldDef
forall record typ.
PersistEntity record =>
EntityField record typ -> FieldDef
forall typ. EntityField val typ -> FieldDef
persistFieldDef EntityField val typ
field
idFieldValue :: SqlExpr (Value typ)
idFieldValue =
case EntityDef -> NonEmpty FieldDef
getEntityKeyFields EntityDef
ed of
FieldDef
idField :| [] ->
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info -> (IdentInfo -> FieldDef -> Builder
dot IdentInfo
info FieldDef
idField, [])
NonEmpty FieldDef
idFields ->
let renderedFields :: IdentInfo -> [Builder]
renderedFields IdentInfo
info = IdentInfo -> FieldDef -> Builder
dot IdentInfo
info (FieldDef -> Builder) -> [FieldDef] -> [Builder]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty FieldDef -> [FieldDef]
forall a. NonEmpty a -> [a]
NEL.toList NonEmpty FieldDef
idFields
in SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta{ sqlExprMetaCompositeFields = Just renderedFields} ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ)
forall a b. (a -> b) -> a -> b
$
\NeedParens
p IdentInfo
info -> (NeedParens -> Builder -> Builder
parensM NeedParens
p (Builder -> Builder) -> Builder -> Builder
forall a b. (a -> b) -> a -> b
$ [Builder] -> Builder
uncommas ([Builder] -> Builder) -> [Builder] -> Builder
forall a b. (a -> b) -> a -> b
$ IdentInfo -> [Builder]
renderedFields IdentInfo
info, [])
ed :: EntityDef
ed = Proxy val -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy val -> EntityDef
entityDef (Proxy val -> EntityDef) -> Proxy val -> EntityDef
forall a b. (a -> b) -> a -> b
$ Proxy (SqlExpr (Entity val)) -> Proxy val
forall a. Proxy (SqlExpr (Entity a)) -> Proxy a
getEntityVal (Proxy (SqlExpr (Entity val))
forall {k} (t :: k). Proxy t
Proxy :: Proxy (SqlExpr (Entity val)))
dot :: IdentInfo -> FieldDef -> Builder
dot IdentInfo
info FieldDef
fieldDef' =
IdentInfo -> Builder
sourceIdent IdentInfo
info Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"." Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
fieldIdent
where
sourceIdent :: IdentInfo -> Builder
sourceIdent = ((Builder, [PersistValue]) -> Builder)
-> (IdentInfo -> (Builder, [PersistValue])) -> IdentInfo -> Builder
forall a b. (a -> b) -> (IdentInfo -> a) -> IdentInfo -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Builder, [PersistValue]) -> Builder
forall a b. (a, b) -> a
fst ((IdentInfo -> (Builder, [PersistValue])) -> IdentInfo -> Builder)
-> (IdentInfo -> (Builder, [PersistValue])) -> IdentInfo -> Builder
forall a b. (a -> b) -> a -> b
$ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never
fieldIdent :: Builder
fieldIdent
| Just Ident
baseI <- SqlExprMeta -> Maybe Ident
sqlExprMetaAlias SqlExprMeta
m =
IdentInfo -> Ident -> Builder
useIdent IdentInfo
info (Ident -> Builder) -> Ident -> Builder
forall a b. (a -> b) -> a -> b
$ Ident -> FieldDef -> Ident
aliasedEntityColumnIdent Ident
baseI FieldDef
fieldDef'
| Bool
otherwise =
IdentInfo -> DBName -> Builder
fromDBName IdentInfo
info (FieldNameDB -> DBName
forall a b. Coercible a b => a -> b
coerce (FieldNameDB -> DBName) -> FieldNameDB -> DBName
forall a b. (a -> b) -> a -> b
$ FieldDef -> FieldNameDB
fieldDB FieldDef
fieldDef')
withNonNull
:: PersistField typ
=> SqlExpr (Value (Maybe typ))
-> (SqlExpr (Value typ) -> SqlQuery a)
-> SqlQuery a
withNonNull :: forall typ a.
PersistField typ =>
SqlExpr (Value (Maybe typ))
-> (SqlExpr (Value typ) -> SqlQuery a) -> SqlQuery a
withNonNull SqlExpr (Value (Maybe typ))
field SqlExpr (Value typ) -> SqlQuery a
f = do
SqlExpr (Value Bool) -> SqlQuery ()
where_ (SqlExpr (Value Bool) -> SqlQuery ())
-> SqlExpr (Value Bool) -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SqlExpr (Value Bool) -> SqlExpr (Value Bool)
not_ (SqlExpr (Value Bool) -> SqlExpr (Value Bool))
-> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
forall a b. (a -> b) -> a -> b
$ SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
forall typ.
PersistField typ =>
SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
isNothing SqlExpr (Value (Maybe typ))
field
SqlExpr (Value typ) -> SqlQuery a
f (SqlExpr (Value typ) -> SqlQuery a)
-> SqlExpr (Value typ) -> SqlQuery a
forall a b. (a -> b) -> a -> b
$ SqlExpr (Value (Maybe typ)) -> SqlExpr (Value typ)
forall a b. SqlExpr (Value a) -> SqlExpr (Value b)
veryUnsafeCoerceSqlExprValue SqlExpr (Value (Maybe typ))
field
(?.) :: ( PersistEntity val , PersistField typ)
=> SqlExpr (Maybe (Entity val))
-> EntityField val typ
-> SqlExpr (Value (Maybe typ))
ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f ?. :: forall val typ.
(PersistEntity val, PersistField typ) =>
SqlExpr (Maybe (Entity val))
-> EntityField val typ -> SqlExpr (Value (Maybe typ))
?. EntityField val typ
field = SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))
forall typ. SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))
just (SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Entity val)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
forall typ val.
(PersistEntity val, PersistField typ) =>
SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
^. EntityField val typ
field)
val :: PersistField typ => typ -> SqlExpr (Value typ)
val :: forall typ. PersistField typ => typ -> SqlExpr (Value typ)
val typ
v = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value typ)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
_ -> (Builder
"?", [typ -> PersistValue
forall a. PersistField a => a -> PersistValue
toPersistValue typ
v])
isNothing :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
isNothing :: forall typ.
PersistField typ =>
SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
isNothing SqlExpr (Value (Maybe typ))
v =
case SqlExpr (Value (Maybe typ))
v of
ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f ->
case SqlExprMeta -> Maybe (IdentInfo -> [Builder])
sqlExprMetaCompositeFields SqlExprMeta
m of
Just IdentInfo -> [Builder]
fields ->
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a b. (a -> b) -> a -> b
$ \NeedParens
p IdentInfo
info ->
(Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (NeedParens -> Builder -> Builder
parensM NeedParens
p) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> ([Builder] -> (Builder, [PersistValue]))
-> [Builder]
-> (Builder, [PersistValue])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Builder -> [PersistValue] -> (Builder, [PersistValue]))
-> [PersistValue] -> Builder -> (Builder, [PersistValue])
forall a b c. (a -> b -> c) -> b -> a -> c
flip (,) [] (Builder -> (Builder, [PersistValue]))
-> ([Builder] -> Builder) -> [Builder] -> (Builder, [PersistValue])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Builder -> [Builder] -> Builder
intersperseB Builder
" AND " ([Builder] -> Builder)
-> ([Builder] -> [Builder]) -> [Builder] -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Builder -> Builder) -> [Builder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" IS NULL")) ([Builder] -> (Builder, [PersistValue]))
-> [Builder] -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ IdentInfo -> [Builder]
fields IdentInfo
info
Maybe (IdentInfo -> [Builder])
Nothing ->
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a b. (a -> b) -> a -> b
$ \NeedParens
p IdentInfo
info ->
(Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (NeedParens -> Builder -> Builder
parensM NeedParens
p) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue])
-> (Builder, [PersistValue])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a. (Builder, a) -> (Builder, a)
isNullExpr ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info
where
isNullExpr :: (TLB.Builder, a) -> (TLB.Builder, a)
isNullExpr :: forall a. (Builder, a) -> (Builder, a)
isNullExpr = (Builder -> Builder) -> (Builder, a) -> (Builder, a)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first ((Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" IS NULL"))
isNothing_ :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
isNothing_ :: forall typ.
PersistField typ =>
SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
isNothing_ = SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
forall typ.
PersistField typ =>
SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)
isNothing
just :: SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))
just :: forall typ. SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))
just = SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))
forall a b. SqlExpr (Value a) -> SqlExpr (Value b)
veryUnsafeCoerceSqlExprValue
nothing :: SqlExpr (Value (Maybe typ))
nothing :: forall typ. SqlExpr (Value (Maybe typ))
nothing = Builder -> SqlExpr (Value (Maybe typ))
forall a. Builder -> SqlExpr (Value a)
unsafeSqlValue Builder
"NULL"
joinV :: SqlExpr (Value (Maybe (Maybe typ))) -> SqlExpr (Value (Maybe typ))
joinV :: forall typ.
SqlExpr (Value (Maybe (Maybe typ))) -> SqlExpr (Value (Maybe typ))
joinV = SqlExpr (Value (Maybe (Maybe typ))) -> SqlExpr (Value (Maybe typ))
forall a b. SqlExpr (Value a) -> SqlExpr (Value b)
veryUnsafeCoerceSqlExprValue
countHelper :: Num a => TLB.Builder -> TLB.Builder -> SqlExpr (Value typ) -> SqlExpr (Value a)
countHelper :: forall a typ.
Num a =>
Builder -> Builder -> SqlExpr (Value typ) -> SqlExpr (Value a)
countHelper Builder
open Builder
close SqlExpr (Value typ)
v =
case SqlExpr (Value typ)
v of
ERaw SqlExprMeta
meta NeedParens -> IdentInfo -> (Builder, [PersistValue])
f ->
if SqlExprMeta -> Bool
hasCompositeKeyMeta SqlExprMeta
meta then
SqlExpr (Value a)
forall a. Num a => SqlExpr (Value a)
countRows
else
(IdentInfo -> (Builder, [PersistValue])) -> SqlExpr (Value a)
forall a.
(IdentInfo -> (Builder, [PersistValue])) -> SqlExpr (Value a)
countRawSql (NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never)
where
countRawSql :: (IdentInfo -> (TLB.Builder, [PersistValue])) -> SqlExpr (Value a)
countRawSql :: forall a.
(IdentInfo -> (Builder, [PersistValue])) -> SqlExpr (Value a)
countRawSql IdentInfo -> (Builder, [PersistValue])
x = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ -> (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (\Builder
b -> Builder
"COUNT" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
open Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parens Builder
b Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
close) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (IdentInfo -> (Builder, [PersistValue]))
-> IdentInfo
-> (Builder, [PersistValue])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdentInfo -> (Builder, [PersistValue])
x
countRows :: Num a => SqlExpr (Value a)
countRows :: forall a. Num a => SqlExpr (Value a)
countRows = Builder -> SqlExpr (Value a)
forall a. Builder -> SqlExpr (Value a)
unsafeSqlValue Builder
"COUNT(*)"
count :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a)
count :: forall a typ. Num a => SqlExpr (Value typ) -> SqlExpr (Value a)
count = Builder -> Builder -> SqlExpr (Value typ) -> SqlExpr (Value a)
forall a typ.
Num a =>
Builder -> Builder -> SqlExpr (Value typ) -> SqlExpr (Value a)
countHelper Builder
"" Builder
""
countDistinct :: Num a => SqlExpr (Value typ) -> SqlExpr (Value a)
countDistinct :: forall a typ. Num a => SqlExpr (Value typ) -> SqlExpr (Value a)
countDistinct = Builder -> Builder -> SqlExpr (Value typ) -> SqlExpr (Value a)
forall a typ.
Num a =>
Builder -> Builder -> SqlExpr (Value typ) -> SqlExpr (Value a)
countHelper Builder
"(DISTINCT " Builder
")"
not_ :: SqlExpr (Value Bool) -> SqlExpr (Value Bool)
not_ :: SqlExpr (Value Bool) -> SqlExpr (Value Bool)
not_ SqlExpr (Value Bool)
v = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a b. (a -> b) -> a -> b
$ \NeedParens
p IdentInfo
info -> (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Builder
"NOT " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ NeedParens -> IdentInfo -> (Builder, [PersistValue])
x NeedParens
p IdentInfo
info
where
x :: NeedParens -> IdentInfo -> (Builder, [PersistValue])
x NeedParens
p IdentInfo
info =
case SqlExpr (Value Bool)
v of
ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f ->
if SqlExprMeta -> Bool
hasCompositeKeyMeta SqlExprMeta
m then
EsqueletoError -> (Builder, [PersistValue])
forall a e. Exception e => e -> a
throw (CompositeKeyError -> EsqueletoError
CompositeKeyErr CompositeKeyError
NotError)
else
let (Builder
b, [PersistValue]
vals) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info
in (NeedParens -> Builder -> Builder
parensM NeedParens
p Builder
b, [PersistValue]
vals)
(==.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
==. :: forall typ.
PersistField typ =>
SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
(==.) = Builder
-> Builder
-> SqlExpr (Value typ)
-> SqlExpr (Value typ)
-> SqlExpr (Value Bool)
forall a b c.
Builder
-> Builder
-> SqlExpr (Value a)
-> SqlExpr (Value b)
-> SqlExpr (Value c)
unsafeSqlBinOpComposite Builder
" = " Builder
" AND "
(>=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
>=. :: forall typ.
PersistField typ =>
SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
(>=.) = Builder
-> SqlExpr (Value typ)
-> SqlExpr (Value typ)
-> SqlExpr (Value Bool)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" >= "
(>.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
>. :: forall typ.
PersistField typ =>
SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
(>.) = Builder
-> SqlExpr (Value typ)
-> SqlExpr (Value typ)
-> SqlExpr (Value Bool)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" > "
(<=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
<=. :: forall typ.
PersistField typ =>
SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
(<=.) = Builder
-> SqlExpr (Value typ)
-> SqlExpr (Value typ)
-> SqlExpr (Value Bool)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" <= "
(<.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
<. :: forall typ.
PersistField typ =>
SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
(<.) = Builder
-> SqlExpr (Value typ)
-> SqlExpr (Value typ)
-> SqlExpr (Value Bool)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" < "
(!=.) :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
!=. :: forall typ.
PersistField typ =>
SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
(!=.) = Builder
-> Builder
-> SqlExpr (Value typ)
-> SqlExpr (Value typ)
-> SqlExpr (Value Bool)
forall a b c.
Builder
-> Builder
-> SqlExpr (Value a)
-> SqlExpr (Value b)
-> SqlExpr (Value c)
unsafeSqlBinOpComposite Builder
" != " Builder
" OR "
(&&.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
&&. :: SqlExpr (Value Bool)
-> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
(&&.) = Builder
-> SqlExpr (Value Bool)
-> SqlExpr (Value Bool)
-> SqlExpr (Value Bool)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" AND "
(||.) :: SqlExpr (Value Bool) -> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
||. :: SqlExpr (Value Bool)
-> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
(||.) = Builder
-> SqlExpr (Value Bool)
-> SqlExpr (Value Bool)
-> SqlExpr (Value Bool)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" OR "
(+.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
+. :: forall a.
PersistField a =>
SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
(+.) = Builder
-> SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" + "
(-.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
-. :: forall a.
PersistField a =>
SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
(-.) = Builder
-> SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" - "
(/.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
/. :: forall a.
PersistField a =>
SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
(/.) = Builder
-> SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" / "
(*.) :: PersistField a => SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
*. :: forall a.
PersistField a =>
SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
(*.) = Builder
-> SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" * "
between :: PersistField a => SqlExpr (Value a) -> (SqlExpr (Value a), SqlExpr (Value a)) -> SqlExpr (Value Bool)
SqlExpr (Value a)
a between :: forall a.
PersistField a =>
SqlExpr (Value a)
-> (SqlExpr (Value a), SqlExpr (Value a)) -> SqlExpr (Value Bool)
`between` (SqlExpr (Value a)
b, SqlExpr (Value a)
c) = SqlExpr (Value a)
a SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value Bool)
forall typ.
PersistField typ =>
SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
>=. SqlExpr (Value a)
b SqlExpr (Value Bool)
-> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
&&. SqlExpr (Value a)
a SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value Bool)
forall typ.
PersistField typ =>
SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool)
<=. SqlExpr (Value a)
c
random_ :: (PersistField a, Num a) => SqlExpr (Value a)
random_ :: forall a. (PersistField a, Num a) => SqlExpr (Value a)
random_ = Builder -> SqlExpr (Value a)
forall a. Builder -> SqlExpr (Value a)
unsafeSqlValue Builder
"RANDOM()"
round_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
round_ :: forall a b.
(PersistField a, Num a, PersistField b, Num b) =>
SqlExpr (Value a) -> SqlExpr (Value b)
round_ = Builder -> SqlExpr (Value a) -> SqlExpr (Value b)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"ROUND"
ceiling_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
ceiling_ :: forall a b.
(PersistField a, Num a, PersistField b, Num b) =>
SqlExpr (Value a) -> SqlExpr (Value b)
ceiling_ = Builder -> SqlExpr (Value a) -> SqlExpr (Value b)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"CEILING"
floor_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
floor_ :: forall a b.
(PersistField a, Num a, PersistField b, Num b) =>
SqlExpr (Value a) -> SqlExpr (Value b)
floor_ = Builder -> SqlExpr (Value a) -> SqlExpr (Value b)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"FLOOR"
sum_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
sum_ :: forall a b.
(PersistField a, PersistField b) =>
SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
sum_ = Builder -> SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"SUM"
min_ :: (PersistField a) => SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
min_ :: forall a.
PersistField a =>
SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
min_ = Builder -> SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"MIN"
max_ :: (PersistField a) => SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
max_ :: forall a.
PersistField a =>
SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
max_ = Builder -> SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"MAX"
avg_ :: (PersistField a, PersistField b) => SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
avg_ :: forall a b.
(PersistField a, PersistField b) =>
SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
avg_ = Builder -> SqlExpr (Value a) -> SqlExpr (Value (Maybe b))
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"AVG"
castNum :: (Num a, Num b) => SqlExpr (Value a) -> SqlExpr (Value b)
castNum :: forall a b.
(Num a, Num b) =>
SqlExpr (Value a) -> SqlExpr (Value b)
castNum = SqlExpr (Value a) -> SqlExpr (Value b)
forall a b. SqlExpr (Value a) -> SqlExpr (Value b)
veryUnsafeCoerceSqlExprValue
castNumM :: (Num a, Num b) => SqlExpr (Value (Maybe a)) -> SqlExpr (Value (Maybe b))
castNumM :: forall a b.
(Num a, Num b) =>
SqlExpr (Value (Maybe a)) -> SqlExpr (Value (Maybe b))
castNumM = SqlExpr (Value (Maybe a)) -> SqlExpr (Value (Maybe b))
forall a b. SqlExpr (Value a) -> SqlExpr (Value b)
veryUnsafeCoerceSqlExprValue
coalesce :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value (Maybe a))
coalesce :: forall a.
PersistField a =>
[SqlExpr (Value (Maybe a))] -> SqlExpr (Value (Maybe a))
coalesce = Builder -> [SqlExpr (Value (Maybe a))] -> SqlExpr (Value (Maybe a))
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunctionParens Builder
"COALESCE"
coalesceDefault :: PersistField a => [SqlExpr (Value (Maybe a))] -> SqlExpr (Value a) -> SqlExpr (Value a)
coalesceDefault :: forall a.
PersistField a =>
[SqlExpr (Value (Maybe a))]
-> SqlExpr (Value a) -> SqlExpr (Value a)
coalesceDefault [SqlExpr (Value (Maybe a))]
exprs = Builder -> [SqlExpr (Value (Maybe a))] -> SqlExpr (Value a)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunctionParens Builder
"COALESCE" ([SqlExpr (Value (Maybe a))] -> SqlExpr (Value a))
-> (SqlExpr (Value a) -> [SqlExpr (Value (Maybe a))])
-> SqlExpr (Value a)
-> SqlExpr (Value a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([SqlExpr (Value (Maybe a))]
exprs [SqlExpr (Value (Maybe a))]
-> [SqlExpr (Value (Maybe a))] -> [SqlExpr (Value (Maybe a))]
forall a. [a] -> [a] -> [a]
++) ([SqlExpr (Value (Maybe a))] -> [SqlExpr (Value (Maybe a))])
-> (SqlExpr (Value a) -> [SqlExpr (Value (Maybe a))])
-> SqlExpr (Value a)
-> [SqlExpr (Value (Maybe a))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlExpr (Value (Maybe a)) -> [SqlExpr (Value (Maybe a))]
forall a. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlExpr (Value (Maybe a)) -> [SqlExpr (Value (Maybe a))])
-> (SqlExpr (Value a) -> SqlExpr (Value (Maybe a)))
-> SqlExpr (Value a)
-> [SqlExpr (Value (Maybe a))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlExpr (Value a) -> SqlExpr (Value (Maybe a))
forall typ. SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))
just
lower_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
lower_ :: forall s. SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
lower_ = Builder -> SqlExpr (Value s) -> SqlExpr (Value s)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"LOWER"
upper_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
upper_ :: forall s. SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
upper_ = Builder -> SqlExpr (Value s) -> SqlExpr (Value s)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"UPPER"
trim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
trim_ :: forall s. SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
trim_ = Builder -> SqlExpr (Value s) -> SqlExpr (Value s)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"TRIM"
rtrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
rtrim_ :: forall s. SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
rtrim_ = Builder -> SqlExpr (Value s) -> SqlExpr (Value s)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"RTRIM"
ltrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
ltrim_ :: forall s. SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
ltrim_ = Builder -> SqlExpr (Value s) -> SqlExpr (Value s)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"LTRIM"
length_ :: (SqlString s, Num a) => SqlExpr (Value s) -> SqlExpr (Value a)
length_ :: forall s a.
(SqlString s, Num a) =>
SqlExpr (Value s) -> SqlExpr (Value a)
length_ = Builder -> SqlExpr (Value s) -> SqlExpr (Value a)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"LENGTH"
left_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)
left_ :: forall s a.
(SqlString s, Num a) =>
(SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)
left_ = Builder
-> (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"LEFT"
right_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)
right_ :: forall s a.
(SqlString s, Num a) =>
(SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)
right_ = Builder
-> (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"RIGHT"
like :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
like :: forall s.
SqlString s =>
SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
like = Builder
-> SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" LIKE "
ilike :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
ilike :: forall s.
SqlString s =>
SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
ilike = Builder
-> SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" ILIKE "
(%) :: SqlString s => SqlExpr (Value s)
% :: forall s. SqlString s => SqlExpr (Value s)
(%) = Builder -> SqlExpr (Value s)
forall a. Builder -> SqlExpr (Value a)
unsafeSqlValue Builder
"'%'"
concat_ :: SqlString s => [SqlExpr (Value s)] -> SqlExpr (Value s)
concat_ :: forall s. SqlString s => [SqlExpr (Value s)] -> SqlExpr (Value s)
concat_ = Builder -> [SqlExpr (Value s)] -> SqlExpr (Value s)
forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
"CONCAT"
(++.) :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s)
++. :: forall s.
SqlString s =>
SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s)
(++.) = Builder
-> SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
" || "
castString :: (SqlString s, SqlString r) => SqlExpr (Value s) -> SqlExpr (Value r)
castString :: forall s r.
(SqlString s, SqlString r) =>
SqlExpr (Value s) -> SqlExpr (Value r)
castString = SqlExpr (Value s) -> SqlExpr (Value r)
forall a b. SqlExpr (Value a) -> SqlExpr (Value b)
veryUnsafeCoerceSqlExprValue
subList_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)
subList_select :: forall a.
PersistField a =>
SqlQuery (SqlExpr (Value a)) -> SqlExpr (ValueList a)
subList_select SqlQuery (SqlExpr (Value a))
query = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (ValueList a)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (ValueList a))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (ValueList a)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info -> (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Builder -> Builder
parens ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ Mode
-> IdentInfo
-> SqlQuery (SqlExpr (Value a))
-> (Builder, [PersistValue])
forall a r backend.
(SqlSelect a r, BackendCompatible SqlBackend backend) =>
Mode
-> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])
toRawSql Mode
SELECT IdentInfo
info SqlQuery (SqlExpr (Value a))
query
valList :: PersistField typ => [typ] -> SqlExpr (ValueList typ)
valList :: forall typ. PersistField typ => [typ] -> SqlExpr (ValueList typ)
valList [] = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (ValueList typ)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (ValueList typ))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (ValueList typ)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
_ -> (Builder
"()", [])
valList [typ]
vals = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (ValueList typ)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (ValueList typ))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (ValueList typ)
forall a b. (a -> b) -> a -> b
$ \NeedParens
p -> (Builder, [PersistValue]) -> IdentInfo -> (Builder, [PersistValue])
forall a b. a -> b -> a
const (NeedParens -> Builder -> Builder
parensM NeedParens
p ([Builder] -> Builder
uncommas (Builder
"?" Builder -> [typ] -> [Builder]
forall a b. a -> [b] -> [a]
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [typ]
vals)), (typ -> PersistValue) -> [typ] -> [PersistValue]
forall a b. (a -> b) -> [a] -> [b]
map typ -> PersistValue
forall a. PersistField a => a -> PersistValue
toPersistValue [typ]
vals )
justList :: SqlExpr (ValueList typ) -> SqlExpr (ValueList (Maybe typ))
justList :: forall typ.
SqlExpr (ValueList typ) -> SqlExpr (ValueList (Maybe typ))
justList (ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (ValueList (Maybe typ))
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f
in_ :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool)
(ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
v) in_ :: forall typ.
PersistField typ =>
SqlExpr (Value typ)
-> SqlExpr (ValueList typ) -> SqlExpr (Value Bool)
`in_` (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
list) =
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info ->
let (Builder
b1, [PersistValue]
vals1) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
v NeedParens
Parens IdentInfo
info
(Builder
b2, [PersistValue]
vals2) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
list NeedParens
Parens IdentInfo
info
in
if Builder
b2 Builder -> Builder -> Bool
forall a. Eq a => a -> a -> Bool
== Builder
"()" then
(Builder
"FALSE", [])
else
(Builder
b1 Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" IN " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
b2, [PersistValue]
vals1 [PersistValue] -> [PersistValue] -> [PersistValue]
forall a. Semigroup a => a -> a -> a
<> [PersistValue]
vals2)
notIn :: PersistField typ => SqlExpr (Value typ) -> SqlExpr (ValueList typ) -> SqlExpr (Value Bool)
(ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
v) notIn :: forall typ.
PersistField typ =>
SqlExpr (Value typ)
-> SqlExpr (ValueList typ) -> SqlExpr (Value Bool)
`notIn` (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
list) =
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info ->
let (Builder
b1, [PersistValue]
vals1) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
v NeedParens
Parens IdentInfo
info
(Builder
b2, [PersistValue]
vals2) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
list NeedParens
Parens IdentInfo
info
in
if Builder
b2 Builder -> Builder -> Bool
forall a. Eq a => a -> a -> Bool
== Builder
"()" then
(Builder
"TRUE", [])
else
(Builder
b1 Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" NOT IN " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
b2, [PersistValue]
vals1 [PersistValue] -> [PersistValue] -> [PersistValue]
forall a. Semigroup a => a -> a -> a
<> [PersistValue]
vals2)
exists :: SqlQuery () -> SqlExpr (Value Bool)
exists :: SqlQuery () -> SqlExpr (Value Bool)
exists SqlQuery ()
q = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a b. (a -> b) -> a -> b
$ \NeedParens
p IdentInfo
info ->
let ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f = SqlQuery () -> SqlExpr (Value Bool)
existsHelper SqlQuery ()
q
(Builder
b, [PersistValue]
vals) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info
in ( NeedParens -> Builder -> Builder
parensM NeedParens
p (Builder -> Builder) -> Builder -> Builder
forall a b. (a -> b) -> a -> b
$ Builder
"EXISTS " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
b, [PersistValue]
vals)
notExists :: SqlQuery () -> SqlExpr (Value Bool)
notExists :: SqlQuery () -> SqlExpr (Value Bool)
notExists SqlQuery ()
q = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value Bool)
forall a b. (a -> b) -> a -> b
$ \NeedParens
p IdentInfo
info ->
let ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f = SqlQuery () -> SqlExpr (Value Bool)
existsHelper SqlQuery ()
q
(Builder
b, [PersistValue]
vals) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info
in ( NeedParens -> Builder -> Builder
parensM NeedParens
p (Builder -> Builder) -> Builder -> Builder
forall a b. (a -> b) -> a -> b
$ Builder
"NOT EXISTS " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
b, [PersistValue]
vals)
set :: PersistEntity val => SqlExpr (Entity val) -> [SqlExpr (Entity val) -> SqlExpr Update] -> SqlQuery ()
set :: forall val.
PersistEntity val =>
SqlExpr (Entity val)
-> [SqlExpr (Entity val) -> SqlExpr Update] -> SqlQuery ()
set SqlExpr (Entity val)
ent [SqlExpr (Entity val) -> SqlExpr Update]
upds = WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (WriterT SideData (StateT IdentState Identity) () -> SqlQuery ())
-> WriterT SideData (StateT IdentState Identity) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (StateT IdentState Identity) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdSetClause = map apply upds }
where
apply :: (SqlExpr (Entity val) -> SqlExpr Update) -> SetClause
apply SqlExpr (Entity val) -> SqlExpr Update
f = SqlExpr Update -> SetClause
SetClause (SqlExpr (Entity val) -> SqlExpr Update
f SqlExpr (Entity val)
ent)
(=.) :: (PersistEntity val, PersistField typ) => EntityField val typ -> SqlExpr (Value typ) -> (SqlExpr (Entity val) -> SqlExpr Update )
EntityField val typ
field =. :: forall val typ.
(PersistEntity val, PersistField typ) =>
EntityField val typ
-> SqlExpr (Value typ) -> SqlExpr (Entity val) -> SqlExpr Update
=. SqlExpr (Value typ)
expr = EntityField val typ
-> (SqlExpr (Entity val) -> SqlExpr (Value typ))
-> SqlExpr (Entity val)
-> SqlExpr Update
forall val typ.
(PersistEntity val, PersistField typ) =>
EntityField val typ
-> (SqlExpr (Entity val) -> SqlExpr (Value typ))
-> SqlExpr (Entity val)
-> SqlExpr Update
setAux EntityField val typ
field (SqlExpr (Value typ) -> SqlExpr (Entity val) -> SqlExpr (Value typ)
forall a b. a -> b -> a
const SqlExpr (Value typ)
expr)
(+=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> (SqlExpr (Entity val) -> SqlExpr Update)
EntityField val a
field +=. :: forall val typ.
(PersistEntity val, PersistField typ) =>
EntityField val typ
-> SqlExpr (Value typ) -> SqlExpr (Entity val) -> SqlExpr Update
+=. SqlExpr (Value a)
expr = EntityField val a
-> (SqlExpr (Entity val) -> SqlExpr (Value a))
-> SqlExpr (Entity val)
-> SqlExpr Update
forall val typ.
(PersistEntity val, PersistField typ) =>
EntityField val typ
-> (SqlExpr (Entity val) -> SqlExpr (Value typ))
-> SqlExpr (Entity val)
-> SqlExpr Update
setAux EntityField val a
field (\SqlExpr (Entity val)
ent -> SqlExpr (Entity val)
ent SqlExpr (Entity val) -> EntityField val a -> SqlExpr (Value a)
forall typ val.
(PersistEntity val, PersistField typ) =>
SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
^. EntityField val a
field SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
forall a.
PersistField a =>
SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
+. SqlExpr (Value a)
expr)
(-=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> (SqlExpr (Entity val) -> SqlExpr Update)
EntityField val a
field -=. :: forall val typ.
(PersistEntity val, PersistField typ) =>
EntityField val typ
-> SqlExpr (Value typ) -> SqlExpr (Entity val) -> SqlExpr Update
-=. SqlExpr (Value a)
expr = EntityField val a
-> (SqlExpr (Entity val) -> SqlExpr (Value a))
-> SqlExpr (Entity val)
-> SqlExpr Update
forall val typ.
(PersistEntity val, PersistField typ) =>
EntityField val typ
-> (SqlExpr (Entity val) -> SqlExpr (Value typ))
-> SqlExpr (Entity val)
-> SqlExpr Update
setAux EntityField val a
field (\SqlExpr (Entity val)
ent -> SqlExpr (Entity val)
ent SqlExpr (Entity val) -> EntityField val a -> SqlExpr (Value a)
forall typ val.
(PersistEntity val, PersistField typ) =>
SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
^. EntityField val a
field SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
forall a.
PersistField a =>
SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
-. SqlExpr (Value a)
expr)
(*=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> (SqlExpr (Entity val) -> SqlExpr Update)
EntityField val a
field *=. :: forall val typ.
(PersistEntity val, PersistField typ) =>
EntityField val typ
-> SqlExpr (Value typ) -> SqlExpr (Entity val) -> SqlExpr Update
*=. SqlExpr (Value a)
expr = EntityField val a
-> (SqlExpr (Entity val) -> SqlExpr (Value a))
-> SqlExpr (Entity val)
-> SqlExpr Update
forall val typ.
(PersistEntity val, PersistField typ) =>
EntityField val typ
-> (SqlExpr (Entity val) -> SqlExpr (Value typ))
-> SqlExpr (Entity val)
-> SqlExpr Update
setAux EntityField val a
field (\SqlExpr (Entity val)
ent -> SqlExpr (Entity val)
ent SqlExpr (Entity val) -> EntityField val a -> SqlExpr (Value a)
forall typ val.
(PersistEntity val, PersistField typ) =>
SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
^. EntityField val a
field SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
forall a.
PersistField a =>
SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
*. SqlExpr (Value a)
expr)
(/=.) :: (PersistEntity val, PersistField a) => EntityField val a -> SqlExpr (Value a) -> (SqlExpr (Entity val) -> SqlExpr Update)
EntityField val a
field /=. :: forall val typ.
(PersistEntity val, PersistField typ) =>
EntityField val typ
-> SqlExpr (Value typ) -> SqlExpr (Entity val) -> SqlExpr Update
/=. SqlExpr (Value a)
expr = EntityField val a
-> (SqlExpr (Entity val) -> SqlExpr (Value a))
-> SqlExpr (Entity val)
-> SqlExpr Update
forall val typ.
(PersistEntity val, PersistField typ) =>
EntityField val typ
-> (SqlExpr (Entity val) -> SqlExpr (Value typ))
-> SqlExpr (Entity val)
-> SqlExpr Update
setAux EntityField val a
field (\SqlExpr (Entity val)
ent -> SqlExpr (Entity val)
ent SqlExpr (Entity val) -> EntityField val a -> SqlExpr (Value a)
forall typ val.
(PersistEntity val, PersistField typ) =>
SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
^. EntityField val a
field SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
forall a.
PersistField a =>
SqlExpr (Value a) -> SqlExpr (Value a) -> SqlExpr (Value a)
/. SqlExpr (Value a)
expr)
(<#) :: (a -> b) -> SqlExpr (Value a) -> SqlExpr (Insertion b)
<# :: forall a b. (a -> b) -> SqlExpr (Value a) -> SqlExpr (Insertion b)
(<#) a -> b
_ (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Insertion b)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta NeedParens -> IdentInfo -> (Builder, [PersistValue])
f
(<&>) :: SqlExpr (Insertion (a -> b)) -> SqlExpr (Value a) -> SqlExpr (Insertion b)
(ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) <&> :: forall a b.
SqlExpr (Insertion (a -> b))
-> SqlExpr (Value a) -> SqlExpr (Insertion b)
<&> (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
g) =
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Insertion b)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Insertion b))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Insertion b)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info ->
let (Builder
fb, [PersistValue]
fv) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info
(Builder
gb, [PersistValue]
gv) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
g NeedParens
Never IdentInfo
info
in (Builder
fb Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
", " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
gb, [PersistValue]
fv [PersistValue] -> [PersistValue] -> [PersistValue]
forall a. [a] -> [a] -> [a]
++ [PersistValue]
gv)
case_ :: PersistField a => [(SqlExpr (Value Bool), SqlExpr (Value a))] -> SqlExpr (Value a) -> SqlExpr (Value a)
case_ :: forall a.
PersistField a =>
[(SqlExpr (Value Bool), SqlExpr (Value a))]
-> SqlExpr (Value a) -> SqlExpr (Value a)
case_ = [(SqlExpr (Value Bool), SqlExpr (Value a))]
-> SqlExpr (Value a) -> SqlExpr (Value a)
forall a.
PersistField a =>
[(SqlExpr (Value Bool), SqlExpr (Value a))]
-> SqlExpr (Value a) -> SqlExpr (Value a)
unsafeSqlCase
toBaseId :: ToBaseId ent => SqlExpr (Value (Key ent)) -> SqlExpr (Value (Key (BaseEnt ent)))
toBaseId :: forall ent.
ToBaseId ent =>
SqlExpr (Value (Key ent)) -> SqlExpr (Value (Key (BaseEnt ent)))
toBaseId = SqlExpr (Value (Key ent)) -> SqlExpr (Value (Key (BaseEnt ent)))
forall a b. SqlExpr (Value a) -> SqlExpr (Value b)
veryUnsafeCoerceSqlExprValue
{-# DEPRECATED random_ "Since 2.6.0: `random_` is not uniform across all databases! Please use a specific one such as 'Database.Esqueleto.PostgreSQL.random_', 'Database.Esqueleto.MySQL.random_', or 'Database.Esqueleto.SQLite.random_'" #-}
{-# DEPRECATED rand "Since 2.6.0: `rand` ordering function is not uniform across all databases! To avoid accidental partiality it will be removed in the next major version." #-}
infixl 9 ^.
infixl 7 *., /.
infixl 6 +., -.
infixr 5 ++.
infix 4 ==., >=., >., <=., <., !=.
infixr 3 &&., =., +=., -=., *=., /=.
infixr 2 ||., `like`, `ilike`
infixl 2 `InnerJoin`, `CrossJoin`, `LeftOuterJoin`, `RightOuterJoin`, `FullOuterJoin`
when_ :: expr (Value Bool) -> () -> expr a -> (expr (Value Bool), expr a)
when_ :: forall (expr :: * -> *) a.
expr (Value Bool) -> () -> expr a -> (expr (Value Bool), expr a)
when_ expr (Value Bool)
cond ()
_ expr a
expr = (expr (Value Bool)
cond, expr a
expr)
then_ :: ()
then_ :: ()
then_ = ()
else_ :: expr a -> expr a
else_ :: forall (expr :: * -> *) a. expr a -> expr a
else_ = expr a -> expr a
forall a. a -> a
id
newtype Value a = Value { forall a. Value a -> a
unValue :: a } deriving (Value a -> Value a -> Bool
(Value a -> Value a -> Bool)
-> (Value a -> Value a -> Bool) -> Eq (Value a)
forall a. Eq a => Value a -> Value a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Value a -> Value a -> Bool
== :: Value a -> Value a -> Bool
$c/= :: forall a. Eq a => Value a -> Value a -> Bool
/= :: Value a -> Value a -> Bool
Eq, Eq (Value a)
Eq (Value a) =>
(Value a -> Value a -> Ordering)
-> (Value a -> Value a -> Bool)
-> (Value a -> Value a -> Bool)
-> (Value a -> Value a -> Bool)
-> (Value a -> Value a -> Bool)
-> (Value a -> Value a -> Value a)
-> (Value a -> Value a -> Value a)
-> Ord (Value a)
Value a -> Value a -> Bool
Value a -> Value a -> Ordering
Value a -> Value a -> Value a
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
forall a. Ord a => Eq (Value a)
forall a. Ord a => Value a -> Value a -> Bool
forall a. Ord a => Value a -> Value a -> Ordering
forall a. Ord a => Value a -> Value a -> Value a
$ccompare :: forall a. Ord a => Value a -> Value a -> Ordering
compare :: Value a -> Value a -> Ordering
$c< :: forall a. Ord a => Value a -> Value a -> Bool
< :: Value a -> Value a -> Bool
$c<= :: forall a. Ord a => Value a -> Value a -> Bool
<= :: Value a -> Value a -> Bool
$c> :: forall a. Ord a => Value a -> Value a -> Bool
> :: Value a -> Value a -> Bool
$c>= :: forall a. Ord a => Value a -> Value a -> Bool
>= :: Value a -> Value a -> Bool
$cmax :: forall a. Ord a => Value a -> Value a -> Value a
max :: Value a -> Value a -> Value a
$cmin :: forall a. Ord a => Value a -> Value a -> Value a
min :: Value a -> Value a -> Value a
Ord, Int -> Value a -> ShowS
[Value a] -> ShowS
Value a -> String
(Int -> Value a -> ShowS)
-> (Value a -> String) -> ([Value a] -> ShowS) -> Show (Value a)
forall a. Show a => Int -> Value a -> ShowS
forall a. Show a => [Value a] -> ShowS
forall a. Show a => Value a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Value a -> ShowS
showsPrec :: Int -> Value a -> ShowS
$cshow :: forall a. Show a => Value a -> String
show :: Value a -> String
$cshowList :: forall a. Show a => [Value a] -> ShowS
showList :: [Value a] -> ShowS
Show, Typeable)
instance Functor Value where
fmap :: forall a b. (a -> b) -> Value a -> Value b
fmap a -> b
f (Value a
a) = b -> Value b
forall a. a -> Value a
Value (a -> b
f a
a)
instance Applicative Value where
<*> :: forall a b. Value (a -> b) -> Value a -> Value b
(<*>) (Value a -> b
f) (Value a
a) = b -> Value b
forall a. a -> Value a
Value (a -> b
f a
a)
pure :: forall a. a -> Value a
pure = a -> Value a
forall a. a -> Value a
Value
instance Monad Value where
>>= :: forall a b. Value a -> (a -> Value b) -> Value b
(>>=) Value a
x a -> Value b
f = Value (Value b) -> Value b
forall a. Value a -> a
valueJoin (Value (Value b) -> Value b) -> Value (Value b) -> Value b
forall a b. (a -> b) -> a -> b
$ (a -> Value b) -> Value a -> Value (Value b)
forall a b. (a -> b) -> Value a -> Value b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Value b
f Value a
x
where valueJoin :: Value a -> a
valueJoin (Value a
v) = a
v
newtype ValueList a = ValueList a deriving (ValueList a -> ValueList a -> Bool
(ValueList a -> ValueList a -> Bool)
-> (ValueList a -> ValueList a -> Bool) -> Eq (ValueList a)
forall a. Eq a => ValueList a -> ValueList a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => ValueList a -> ValueList a -> Bool
== :: ValueList a -> ValueList a -> Bool
$c/= :: forall a. Eq a => ValueList a -> ValueList a -> Bool
/= :: ValueList a -> ValueList a -> Bool
Eq, Eq (ValueList a)
Eq (ValueList a) =>
(ValueList a -> ValueList a -> Ordering)
-> (ValueList a -> ValueList a -> Bool)
-> (ValueList a -> ValueList a -> Bool)
-> (ValueList a -> ValueList a -> Bool)
-> (ValueList a -> ValueList a -> Bool)
-> (ValueList a -> ValueList a -> ValueList a)
-> (ValueList a -> ValueList a -> ValueList a)
-> Ord (ValueList a)
ValueList a -> ValueList a -> Bool
ValueList a -> ValueList a -> Ordering
ValueList a -> ValueList a -> ValueList a
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
forall a. Ord a => Eq (ValueList a)
forall a. Ord a => ValueList a -> ValueList a -> Bool
forall a. Ord a => ValueList a -> ValueList a -> Ordering
forall a. Ord a => ValueList a -> ValueList a -> ValueList a
$ccompare :: forall a. Ord a => ValueList a -> ValueList a -> Ordering
compare :: ValueList a -> ValueList a -> Ordering
$c< :: forall a. Ord a => ValueList a -> ValueList a -> Bool
< :: ValueList a -> ValueList a -> Bool
$c<= :: forall a. Ord a => ValueList a -> ValueList a -> Bool
<= :: ValueList a -> ValueList a -> Bool
$c> :: forall a. Ord a => ValueList a -> ValueList a -> Bool
> :: ValueList a -> ValueList a -> Bool
$c>= :: forall a. Ord a => ValueList a -> ValueList a -> Bool
>= :: ValueList a -> ValueList a -> Bool
$cmax :: forall a. Ord a => ValueList a -> ValueList a -> ValueList a
max :: ValueList a -> ValueList a -> ValueList a
$cmin :: forall a. Ord a => ValueList a -> ValueList a -> ValueList a
min :: ValueList a -> ValueList a -> ValueList a
Ord, Int -> ValueList a -> ShowS
[ValueList a] -> ShowS
ValueList a -> String
(Int -> ValueList a -> ShowS)
-> (ValueList a -> String)
-> ([ValueList a] -> ShowS)
-> Show (ValueList a)
forall a. Show a => Int -> ValueList a -> ShowS
forall a. Show a => [ValueList a] -> ShowS
forall a. Show a => ValueList a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> ValueList a -> ShowS
showsPrec :: Int -> ValueList a -> ShowS
$cshow :: forall a. Show a => ValueList a -> String
show :: ValueList a -> String
$cshowList :: forall a. Show a => [ValueList a] -> ShowS
showList :: [ValueList a] -> ShowS
Show, Typeable)
data SomeValue where
SomeValue :: SqlExpr (Value a) -> SomeValue
class ToSomeValues a where
toSomeValues :: a -> [SomeValue]
instance
( ToSomeValues a
, ToSomeValues b
)
=>
ToSomeValues (a, b)
where
toSomeValues :: (a, b) -> [SomeValue]
toSomeValues (a
a,b
b) = a -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues a
a [SomeValue] -> [SomeValue] -> [SomeValue]
forall a. [a] -> [a] -> [a]
++ b -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues b
b
instance
( ToSomeValues a
, ToSomeValues b
, ToSomeValues c
)
=>
ToSomeValues (a, b, c)
where
toSomeValues :: (a, b, c) -> [SomeValue]
toSomeValues (a
a,b
b,c
c) = a -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues a
a [SomeValue] -> [SomeValue] -> [SomeValue]
forall a. [a] -> [a] -> [a]
++ b -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues b
b [SomeValue] -> [SomeValue] -> [SomeValue]
forall a. [a] -> [a] -> [a]
++ c -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues c
c
instance
( ToSomeValues a
, ToSomeValues b
, ToSomeValues c
, ToSomeValues d
)
=>
ToSomeValues (a, b, c, d)
where
toSomeValues :: (a, b, c, d) -> [SomeValue]
toSomeValues (a
a,b
b,c
c,d
d) =
a -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues a
a [SomeValue] -> [SomeValue] -> [SomeValue]
forall a. [a] -> [a] -> [a]
++ b -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues b
b [SomeValue] -> [SomeValue] -> [SomeValue]
forall a. [a] -> [a] -> [a]
++ c -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues c
c [SomeValue] -> [SomeValue] -> [SomeValue]
forall a. [a] -> [a] -> [a]
++ d -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues d
d
instance
( ToSomeValues a
, ToSomeValues b
, ToSomeValues c
, ToSomeValues d
, ToSomeValues e
)
=>
ToSomeValues (a, b, c, d, e)
where
toSomeValues :: (a, b, c, d, e) -> [SomeValue]
toSomeValues (a
a,b
b,c
c,d
d,e
e) = [[SomeValue]] -> [SomeValue]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ a -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues a
a, b -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues b
b, c -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues c
c , d -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues d
d
, e -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues e
e
]
instance
( ToSomeValues a
, ToSomeValues b
, ToSomeValues c
, ToSomeValues d
, ToSomeValues e
, ToSomeValues f
)
=>
ToSomeValues (a, b, c, d, e, f)
where
toSomeValues :: (a, b, c, d, e, f) -> [SomeValue]
toSomeValues (a
a,b
b,c
c,d
d,e
e,f
f) = [[SomeValue]] -> [SomeValue]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ a -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues a
a, b -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues b
b, c -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues c
c, d -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues d
d
, e -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues e
e , f -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues f
f
]
instance
( ToSomeValues a
, ToSomeValues b
, ToSomeValues c
, ToSomeValues d
, ToSomeValues e
, ToSomeValues f
, ToSomeValues g
)
=>
ToSomeValues (a, b, c, d, e, f, g)
where
toSomeValues :: (a, b, c, d, e, f, g) -> [SomeValue]
toSomeValues (a
a,b
b,c
c,d
d,e
e,f
f,g
g) = [[SomeValue]] -> [SomeValue]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ a -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues a
a, b -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues b
b, c -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues c
c, d -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues d
d
, e -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues e
e, f -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues f
f, g -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues g
g
]
instance
( ToSomeValues a
, ToSomeValues b
, ToSomeValues c
, ToSomeValues d
, ToSomeValues e
, ToSomeValues f
, ToSomeValues g
, ToSomeValues h
)
=>
ToSomeValues (a, b, c, d, e, f, g, h)
where
toSomeValues :: (a, b, c, d, e, f, g, h) -> [SomeValue]
toSomeValues (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h) = [[SomeValue]] -> [SomeValue]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ a -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues a
a, b -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues b
b, c -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues c
c, d -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues d
d
, e -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues e
e, f -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues f
f, g -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues g
g, h -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues h
h
]
type family KnowResult a where
KnowResult (i -> o) = KnowResult o
KnowResult a = a
class FinalResult a where
finalR :: a -> KnowResult a
instance FinalResult (Unique val) where
finalR :: Unique val -> KnowResult (Unique val)
finalR = Unique val -> Unique val
Unique val -> KnowResult (Unique val)
forall a. a -> a
id
instance (FinalResult b) => FinalResult (a -> b) where
finalR :: (a -> b) -> KnowResult (a -> b)
finalR a -> b
f = b -> KnowResult b
forall a. FinalResult a => a -> KnowResult a
finalR (a -> b
f a
forall a. HasCallStack => a
undefined)
toUniqueDef
:: forall a val.
( KnowResult a ~ Unique val
, PersistEntity val
, FinalResult a
)
=> a
-> UniqueDef
toUniqueDef :: forall a val.
(KnowResult a ~ Unique val, PersistEntity val, FinalResult a) =>
a -> UniqueDef
toUniqueDef a
uniqueConstructor = UniqueDef
uniqueDef
where
proxy :: Proxy val
proxy :: Proxy val
proxy = Proxy val
forall {k} (t :: k). Proxy t
Proxy
unique :: Unique val
unique :: Unique val
unique = a -> KnowResult a
forall a. FinalResult a => a -> KnowResult a
finalR a
uniqueConstructor
filterF :: UniqueDef -> Bool
filterF = NonEmpty (FieldNameHS, FieldNameDB)
-> NonEmpty (FieldNameHS, FieldNameDB) -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Unique val -> NonEmpty (FieldNameHS, FieldNameDB)
forall record.
PersistEntity record =>
Unique record -> NonEmpty (FieldNameHS, FieldNameDB)
persistUniqueToFieldNames Unique val
unique) (NonEmpty (FieldNameHS, FieldNameDB) -> Bool)
-> (UniqueDef -> NonEmpty (FieldNameHS, FieldNameDB))
-> UniqueDef
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UniqueDef -> NonEmpty (FieldNameHS, FieldNameDB)
uniqueFields
uniqueDef :: UniqueDef
uniqueDef = [UniqueDef] -> UniqueDef
forall a. HasCallStack => [a] -> a
head ([UniqueDef] -> UniqueDef)
-> (Proxy val -> [UniqueDef]) -> Proxy val -> UniqueDef
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UniqueDef -> Bool) -> [UniqueDef] -> [UniqueDef]
forall a. (a -> Bool) -> [a] -> [a]
filter UniqueDef -> Bool
filterF ([UniqueDef] -> [UniqueDef])
-> (Proxy val -> [UniqueDef]) -> Proxy val -> [UniqueDef]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EntityDef -> [UniqueDef]
getEntityUniques (EntityDef -> [UniqueDef])
-> (Proxy val -> EntityDef) -> Proxy val -> [UniqueDef]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy val -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy val -> EntityDef
entityDef (Proxy val -> UniqueDef) -> Proxy val -> UniqueDef
forall a b. (a -> b) -> a -> b
$ Proxy val
proxy
renderUpdates
:: (BackendCompatible SqlBackend backend)
=> backend
-> [SqlExpr (Entity val) -> SqlExpr Update]
-> (TLB.Builder, [PersistValue])
renderUpdates :: forall backend val.
BackendCompatible SqlBackend backend =>
backend
-> [SqlExpr (Entity val) -> SqlExpr Update]
-> (Builder, [PersistValue])
renderUpdates backend
conn = [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas' ([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> ([SqlExpr (Entity val) -> SqlExpr Update]
-> [(Builder, [PersistValue])])
-> [SqlExpr (Entity val) -> SqlExpr Update]
-> (Builder, [PersistValue])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((SqlExpr (Entity val) -> SqlExpr Update)
-> [(Builder, [PersistValue])])
-> [SqlExpr (Entity val) -> SqlExpr Update]
-> [(Builder, [PersistValue])]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (SqlExpr (Entity val) -> SqlExpr Update)
-> [(Builder, [PersistValue])]
forall val.
(SqlExpr (Entity val) -> SqlExpr Update)
-> [(Builder, [PersistValue])]
renderUpdate
where
mk :: SqlExpr Update -> [(TLB.Builder, [PersistValue])]
mk :: SqlExpr Update -> [(Builder, [PersistValue])]
mk (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) = [NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info]
renderUpdate :: (SqlExpr (Entity val) -> SqlExpr Update) -> [(TLB.Builder, [PersistValue])]
renderUpdate :: forall val.
(SqlExpr (Entity val) -> SqlExpr Update)
-> [(Builder, [PersistValue])]
renderUpdate SqlExpr (Entity val) -> SqlExpr Update
f = SqlExpr Update -> [(Builder, [PersistValue])]
mk (SqlExpr (Entity val) -> SqlExpr Update
f SqlExpr (Entity val)
forall a. HasCallStack => a
undefined)
info :: IdentInfo
info = (backend -> SqlBackend
forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend backend
conn, IdentState
initialIdentState)
data InnerJoin a b = a `InnerJoin` b
data CrossJoin a b = a `CrossJoin` b
data LeftOuterJoin a b = a `LeftOuterJoin` b
data RightOuterJoin a b = a `RightOuterJoin` b
data FullOuterJoin a b = a `FullOuterJoin` b
data JoinKind
= InnerJoinKind
| CrossJoinKind
| LeftOuterJoinKind
| RightOuterJoinKind
| FullOuterJoinKind
deriving (JoinKind -> JoinKind -> Bool
(JoinKind -> JoinKind -> Bool)
-> (JoinKind -> JoinKind -> Bool) -> Eq JoinKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JoinKind -> JoinKind -> Bool
== :: JoinKind -> JoinKind -> Bool
$c/= :: JoinKind -> JoinKind -> Bool
/= :: JoinKind -> JoinKind -> Bool
Eq, Int -> JoinKind -> ShowS
[JoinKind] -> ShowS
JoinKind -> String
(Int -> JoinKind -> ShowS)
-> (JoinKind -> String) -> ([JoinKind] -> ShowS) -> Show JoinKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JoinKind -> ShowS
showsPrec :: Int -> JoinKind -> ShowS
$cshow :: JoinKind -> String
show :: JoinKind -> String
$cshowList :: [JoinKind] -> ShowS
showList :: [JoinKind] -> ShowS
Show)
class IsJoinKind join where
smartJoin :: a -> b -> join a b
reifyJoinKind :: join a b -> JoinKind
instance IsJoinKind InnerJoin where
smartJoin :: forall a b. a -> b -> InnerJoin a b
smartJoin a
a b
b = a
a a -> b -> InnerJoin a b
forall a b. a -> b -> InnerJoin a b
`InnerJoin` b
b
reifyJoinKind :: forall a b. InnerJoin a b -> JoinKind
reifyJoinKind InnerJoin a b
_ = JoinKind
InnerJoinKind
instance IsJoinKind CrossJoin where
smartJoin :: forall a b. a -> b -> CrossJoin a b
smartJoin a
a b
b = a
a a -> b -> CrossJoin a b
forall a b. a -> b -> CrossJoin a b
`CrossJoin` b
b
reifyJoinKind :: forall a b. CrossJoin a b -> JoinKind
reifyJoinKind CrossJoin a b
_ = JoinKind
CrossJoinKind
instance IsJoinKind LeftOuterJoin where
smartJoin :: forall a b. a -> b -> LeftOuterJoin a b
smartJoin a
a b
b = a
a a -> b -> LeftOuterJoin a b
forall a b. a -> b -> LeftOuterJoin a b
`LeftOuterJoin` b
b
reifyJoinKind :: forall a b. LeftOuterJoin a b -> JoinKind
reifyJoinKind LeftOuterJoin a b
_ = JoinKind
LeftOuterJoinKind
instance IsJoinKind RightOuterJoin where
smartJoin :: forall a b. a -> b -> RightOuterJoin a b
smartJoin a
a b
b = a
a a -> b -> RightOuterJoin a b
forall a b. a -> b -> RightOuterJoin a b
`RightOuterJoin` b
b
reifyJoinKind :: forall a b. RightOuterJoin a b -> JoinKind
reifyJoinKind RightOuterJoin a b
_ = JoinKind
RightOuterJoinKind
instance IsJoinKind FullOuterJoin where
smartJoin :: forall a b. a -> b -> FullOuterJoin a b
smartJoin a
a b
b = a
a a -> b -> FullOuterJoin a b
forall a b. a -> b -> FullOuterJoin a b
`FullOuterJoin` b
b
reifyJoinKind :: forall a b. FullOuterJoin a b -> JoinKind
reifyJoinKind FullOuterJoin a b
_ = JoinKind
FullOuterJoinKind
data OnClauseWithoutMatchingJoinException =
OnClauseWithoutMatchingJoinException String
deriving (OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
(OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool)
-> (OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool)
-> Eq OnClauseWithoutMatchingJoinException
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
== :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
$c/= :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
/= :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
Eq, Eq OnClauseWithoutMatchingJoinException
Eq OnClauseWithoutMatchingJoinException =>
(OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Ordering)
-> (OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool)
-> (OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool)
-> (OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool)
-> (OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool)
-> (OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException)
-> (OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException)
-> Ord OnClauseWithoutMatchingJoinException
OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Ordering
OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
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 :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Ordering
compare :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Ordering
$c< :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
< :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
$c<= :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
<= :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
$c> :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
> :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
$c>= :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
>= :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
$cmax :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
max :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
$cmin :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
min :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
Ord, Int -> OnClauseWithoutMatchingJoinException -> ShowS
[OnClauseWithoutMatchingJoinException] -> ShowS
OnClauseWithoutMatchingJoinException -> String
(Int -> OnClauseWithoutMatchingJoinException -> ShowS)
-> (OnClauseWithoutMatchingJoinException -> String)
-> ([OnClauseWithoutMatchingJoinException] -> ShowS)
-> Show OnClauseWithoutMatchingJoinException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OnClauseWithoutMatchingJoinException -> ShowS
showsPrec :: Int -> OnClauseWithoutMatchingJoinException -> ShowS
$cshow :: OnClauseWithoutMatchingJoinException -> String
show :: OnClauseWithoutMatchingJoinException -> String
$cshowList :: [OnClauseWithoutMatchingJoinException] -> ShowS
showList :: [OnClauseWithoutMatchingJoinException] -> ShowS
Show, Typeable)
instance Exception OnClauseWithoutMatchingJoinException
data OrderBy
data DistinctOn
data Update
data Insertion a
data (:&) a b = a :& b
deriving ((a :& b) -> (a :& b) -> Bool
((a :& b) -> (a :& b) -> Bool)
-> ((a :& b) -> (a :& b) -> Bool) -> Eq (a :& b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b. (Eq a, Eq b) => (a :& b) -> (a :& b) -> Bool
$c== :: forall a b. (Eq a, Eq b) => (a :& b) -> (a :& b) -> Bool
== :: (a :& b) -> (a :& b) -> Bool
$c/= :: forall a b. (Eq a, Eq b) => (a :& b) -> (a :& b) -> Bool
/= :: (a :& b) -> (a :& b) -> Bool
Eq, Int -> (a :& b) -> ShowS
[a :& b] -> ShowS
(a :& b) -> String
(Int -> (a :& b) -> ShowS)
-> ((a :& b) -> String) -> ([a :& b] -> ShowS) -> Show (a :& b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> (a :& b) -> ShowS
forall a b. (Show a, Show b) => [a :& b] -> ShowS
forall a b. (Show a, Show b) => (a :& b) -> String
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> (a :& b) -> ShowS
showsPrec :: Int -> (a :& b) -> ShowS
$cshow :: forall a b. (Show a, Show b) => (a :& b) -> String
show :: (a :& b) -> String
$cshowList :: forall a b. (Show a, Show b) => [a :& b] -> ShowS
showList :: [a :& b] -> ShowS
Show)
infixl 2 :&
data LockingKind
= ForUpdate
| ForUpdateSkipLocked
| ForShare
| LockInShareMode
data PostgresLockingKind =
PostgresLockingKind
{
PostgresLockingKind -> PostgresRowLevelLockStrength
postgresRowLevelLockStrength :: PostgresRowLevelLockStrength
, PostgresLockingKind -> Maybe LockingOfClause
postgresLockingOfClause :: Maybe LockingOfClause
, PostgresLockingKind -> OnLockedBehavior
postgresOnLockedBehavior :: OnLockedBehavior
}
data PostgresRowLevelLockStrength =
PostgresForUpdate
| PostgresForShare
deriving (Eq PostgresRowLevelLockStrength
Eq PostgresRowLevelLockStrength =>
(PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Ordering)
-> (PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool)
-> (PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool)
-> (PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool)
-> (PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool)
-> (PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> PostgresRowLevelLockStrength)
-> (PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> PostgresRowLevelLockStrength)
-> Ord PostgresRowLevelLockStrength
PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Ordering
PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> PostgresRowLevelLockStrength
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 :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Ordering
compare :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Ordering
$c< :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
< :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
$c<= :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
<= :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
$c> :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
> :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
$c>= :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
>= :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
$cmax :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> PostgresRowLevelLockStrength
max :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> PostgresRowLevelLockStrength
$cmin :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> PostgresRowLevelLockStrength
min :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> PostgresRowLevelLockStrength
Ord, PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
(PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool)
-> (PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool)
-> Eq PostgresRowLevelLockStrength
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
== :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
$c/= :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
/= :: PostgresRowLevelLockStrength
-> PostgresRowLevelLockStrength -> Bool
Eq)
data LockingOfClause where
LockingOfClause :: LockableEntity a => a -> LockingOfClause
data OnLockedBehavior =
NoWait
| SkipLocked
| Wait
deriving (Eq OnLockedBehavior
Eq OnLockedBehavior =>
(OnLockedBehavior -> OnLockedBehavior -> Ordering)
-> (OnLockedBehavior -> OnLockedBehavior -> Bool)
-> (OnLockedBehavior -> OnLockedBehavior -> Bool)
-> (OnLockedBehavior -> OnLockedBehavior -> Bool)
-> (OnLockedBehavior -> OnLockedBehavior -> Bool)
-> (OnLockedBehavior -> OnLockedBehavior -> OnLockedBehavior)
-> (OnLockedBehavior -> OnLockedBehavior -> OnLockedBehavior)
-> Ord OnLockedBehavior
OnLockedBehavior -> OnLockedBehavior -> Bool
OnLockedBehavior -> OnLockedBehavior -> Ordering
OnLockedBehavior -> OnLockedBehavior -> OnLockedBehavior
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 :: OnLockedBehavior -> OnLockedBehavior -> Ordering
compare :: OnLockedBehavior -> OnLockedBehavior -> Ordering
$c< :: OnLockedBehavior -> OnLockedBehavior -> Bool
< :: OnLockedBehavior -> OnLockedBehavior -> Bool
$c<= :: OnLockedBehavior -> OnLockedBehavior -> Bool
<= :: OnLockedBehavior -> OnLockedBehavior -> Bool
$c> :: OnLockedBehavior -> OnLockedBehavior -> Bool
> :: OnLockedBehavior -> OnLockedBehavior -> Bool
$c>= :: OnLockedBehavior -> OnLockedBehavior -> Bool
>= :: OnLockedBehavior -> OnLockedBehavior -> Bool
$cmax :: OnLockedBehavior -> OnLockedBehavior -> OnLockedBehavior
max :: OnLockedBehavior -> OnLockedBehavior -> OnLockedBehavior
$cmin :: OnLockedBehavior -> OnLockedBehavior -> OnLockedBehavior
min :: OnLockedBehavior -> OnLockedBehavior -> OnLockedBehavior
Ord, OnLockedBehavior -> OnLockedBehavior -> Bool
(OnLockedBehavior -> OnLockedBehavior -> Bool)
-> (OnLockedBehavior -> OnLockedBehavior -> Bool)
-> Eq OnLockedBehavior
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OnLockedBehavior -> OnLockedBehavior -> Bool
== :: OnLockedBehavior -> OnLockedBehavior -> Bool
$c/= :: OnLockedBehavior -> OnLockedBehavior -> Bool
/= :: OnLockedBehavior -> OnLockedBehavior -> Bool
Eq, Int -> OnLockedBehavior -> ShowS
[OnLockedBehavior] -> ShowS
OnLockedBehavior -> String
(Int -> OnLockedBehavior -> ShowS)
-> (OnLockedBehavior -> String)
-> ([OnLockedBehavior] -> ShowS)
-> Show OnLockedBehavior
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OnLockedBehavior -> ShowS
showsPrec :: Int -> OnLockedBehavior -> ShowS
$cshow :: OnLockedBehavior -> String
show :: OnLockedBehavior -> String
$cshowList :: [OnLockedBehavior] -> ShowS
showList :: [OnLockedBehavior] -> ShowS
Show)
class LockableEntity a where
flattenLockableEntity :: a -> NonEmpty LockableSqlExpr
makeLockableEntity :: LockableEntity a => IdentInfo -> a -> (TLB.Builder, [PersistValue])
makeLockableEntity :: forall a.
LockableEntity a =>
IdentInfo -> a -> (Builder, [PersistValue])
makeLockableEntity IdentInfo
info a
lockableEntity =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas' ([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ Set (Builder, [PersistValue]) -> [(Builder, [PersistValue])]
forall a. Set a -> [a]
Set.toList (Set (Builder, [PersistValue]) -> [(Builder, [PersistValue])])
-> ([(Builder, [PersistValue])] -> Set (Builder, [PersistValue]))
-> [(Builder, [PersistValue])]
-> [(Builder, [PersistValue])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Builder, [PersistValue])] -> Set (Builder, [PersistValue])
forall a. Ord a => [a] -> Set a
Set.fromList ([(Builder, [PersistValue])] -> [(Builder, [PersistValue])])
-> [(Builder, [PersistValue])] -> [(Builder, [PersistValue])]
forall a b. (a -> b) -> a -> b
$ (\(LockableSqlExpr (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f)) -> NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info) (LockableSqlExpr -> (Builder, [PersistValue]))
-> [LockableSqlExpr] -> [(Builder, [PersistValue])]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty LockableSqlExpr -> [LockableSqlExpr]
forall a. NonEmpty a -> [a]
NEL.toList (a -> NonEmpty LockableSqlExpr
forall a. LockableEntity a => a -> NonEmpty LockableSqlExpr
flattenLockableEntity a
lockableEntity)
instance PersistEntity val => LockableEntity (SqlExpr (Entity val)) where
flattenLockableEntity :: SqlExpr (Entity val) -> NonEmpty LockableSqlExpr
flattenLockableEntity SqlExpr (Entity val)
e = SqlExpr (Entity val) -> LockableSqlExpr
forall a. PersistEntity a => SqlExpr (Entity a) -> LockableSqlExpr
LockableSqlExpr SqlExpr (Entity val)
e LockableSqlExpr -> [LockableSqlExpr] -> NonEmpty LockableSqlExpr
forall a. a -> [a] -> NonEmpty a
:| []
instance (LockableEntity a, LockableEntity b) => LockableEntity (a :& b) where
flattenLockableEntity :: (a :& b) -> NonEmpty LockableSqlExpr
flattenLockableEntity (a
a :& b
b) = a -> NonEmpty LockableSqlExpr
forall a. LockableEntity a => a -> NonEmpty LockableSqlExpr
flattenLockableEntity a
a NonEmpty LockableSqlExpr
-> NonEmpty LockableSqlExpr -> NonEmpty LockableSqlExpr
forall a. Semigroup a => a -> a -> a
<> b -> NonEmpty LockableSqlExpr
forall a. LockableEntity a => a -> NonEmpty LockableSqlExpr
flattenLockableEntity b
b
data LockableSqlExpr where
LockableSqlExpr :: PersistEntity val => (SqlExpr (Entity val)) -> LockableSqlExpr
class PersistField a => SqlString a where
instance (a ~ Char) => SqlString [a] where
instance SqlString T.Text where
instance SqlString TL.Text where
instance SqlString B.ByteString where
instance SqlString Html where
instance SqlString a => SqlString (Maybe a) where
class ToBaseId ent where
type BaseEnt ent :: Type
toBaseIdWitness :: Key (BaseEnt ent) -> Key ent
from :: From a => (a -> SqlQuery b) -> SqlQuery b
from :: forall a b. From a => (a -> SqlQuery b) -> SqlQuery b
from = (SqlQuery a
forall a. From a => SqlQuery a
from_ SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=)
class From a where
from_ :: SqlQuery a
instance
( FromPreprocess (SqlExpr (Entity val))
)
=>
From (SqlExpr (Entity val))
where
from_ :: SqlQuery (SqlExpr (Entity val))
from_ = SqlQuery (PreprocessedFrom (SqlExpr (Entity val)))
forall a. FromPreprocess a => SqlQuery (PreprocessedFrom a)
fromPreprocess SqlQuery (PreprocessedFrom (SqlExpr (Entity val)))
-> (PreprocessedFrom (SqlExpr (Entity val))
-> SqlQuery (SqlExpr (Entity val)))
-> SqlQuery (SqlExpr (Entity val))
forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= PreprocessedFrom (SqlExpr (Entity val))
-> SqlQuery (SqlExpr (Entity val))
forall a. PreprocessedFrom a -> SqlQuery a
fromFinish
instance
( FromPreprocess (SqlExpr (Maybe (Entity val)))
)
=>
From (SqlExpr (Maybe (Entity val)))
where
from_ :: SqlQuery (SqlExpr (Maybe (Entity val)))
from_ = SqlQuery (PreprocessedFrom (SqlExpr (Maybe (Entity val))))
forall a. FromPreprocess a => SqlQuery (PreprocessedFrom a)
fromPreprocess SqlQuery (PreprocessedFrom (SqlExpr (Maybe (Entity val))))
-> (PreprocessedFrom (SqlExpr (Maybe (Entity val)))
-> SqlQuery (SqlExpr (Maybe (Entity val))))
-> SqlQuery (SqlExpr (Maybe (Entity val)))
forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= PreprocessedFrom (SqlExpr (Maybe (Entity val)))
-> SqlQuery (SqlExpr (Maybe (Entity val)))
forall a. PreprocessedFrom a -> SqlQuery a
fromFinish
instance
( FromPreprocess (InnerJoin a b)
)
=>
From (InnerJoin a b)
where
from_ :: SqlQuery (InnerJoin a b)
from_ = SqlQuery (PreprocessedFrom (InnerJoin a b))
forall a. FromPreprocess a => SqlQuery (PreprocessedFrom a)
fromPreprocess SqlQuery (PreprocessedFrom (InnerJoin a b))
-> (PreprocessedFrom (InnerJoin a b) -> SqlQuery (InnerJoin a b))
-> SqlQuery (InnerJoin a b)
forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= PreprocessedFrom (InnerJoin a b) -> SqlQuery (InnerJoin a b)
forall a. PreprocessedFrom a -> SqlQuery a
fromFinish
instance
( FromPreprocess (CrossJoin a b)
)
=>
From (CrossJoin a b)
where
from_ :: SqlQuery (CrossJoin a b)
from_ = SqlQuery (PreprocessedFrom (CrossJoin a b))
forall a. FromPreprocess a => SqlQuery (PreprocessedFrom a)
fromPreprocess SqlQuery (PreprocessedFrom (CrossJoin a b))
-> (PreprocessedFrom (CrossJoin a b) -> SqlQuery (CrossJoin a b))
-> SqlQuery (CrossJoin a b)
forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= PreprocessedFrom (CrossJoin a b) -> SqlQuery (CrossJoin a b)
forall a. PreprocessedFrom a -> SqlQuery a
fromFinish
instance (FromPreprocess (LeftOuterJoin a b)) => From (LeftOuterJoin a b) where
from_ :: SqlQuery (LeftOuterJoin a b)
from_ = SqlQuery (PreprocessedFrom (LeftOuterJoin a b))
forall a. FromPreprocess a => SqlQuery (PreprocessedFrom a)
fromPreprocess SqlQuery (PreprocessedFrom (LeftOuterJoin a b))
-> (PreprocessedFrom (LeftOuterJoin a b)
-> SqlQuery (LeftOuterJoin a b))
-> SqlQuery (LeftOuterJoin a b)
forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= PreprocessedFrom (LeftOuterJoin a b)
-> SqlQuery (LeftOuterJoin a b)
forall a. PreprocessedFrom a -> SqlQuery a
fromFinish
instance (FromPreprocess (RightOuterJoin a b)) => From (RightOuterJoin a b) where
from_ :: SqlQuery (RightOuterJoin a b)
from_ = SqlQuery (PreprocessedFrom (RightOuterJoin a b))
forall a. FromPreprocess a => SqlQuery (PreprocessedFrom a)
fromPreprocess SqlQuery (PreprocessedFrom (RightOuterJoin a b))
-> (PreprocessedFrom (RightOuterJoin a b)
-> SqlQuery (RightOuterJoin a b))
-> SqlQuery (RightOuterJoin a b)
forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= PreprocessedFrom (RightOuterJoin a b)
-> SqlQuery (RightOuterJoin a b)
forall a. PreprocessedFrom a -> SqlQuery a
fromFinish
instance (FromPreprocess (FullOuterJoin a b)) => From (FullOuterJoin a b) where
from_ :: SqlQuery (FullOuterJoin a b)
from_ = SqlQuery (PreprocessedFrom (FullOuterJoin a b))
forall a. FromPreprocess a => SqlQuery (PreprocessedFrom a)
fromPreprocess SqlQuery (PreprocessedFrom (FullOuterJoin a b))
-> (PreprocessedFrom (FullOuterJoin a b)
-> SqlQuery (FullOuterJoin a b))
-> SqlQuery (FullOuterJoin a b)
forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= PreprocessedFrom (FullOuterJoin a b)
-> SqlQuery (FullOuterJoin a b)
forall a. PreprocessedFrom a -> SqlQuery a
fromFinish
instance (From a, From b) => From (a, b) where
from_ :: SqlQuery (a, b)
from_ = (,) (a -> b -> (a, b)) -> SqlQuery a -> SqlQuery (b -> (a, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SqlQuery a
forall a. From a => SqlQuery a
from_ SqlQuery (b -> (a, b)) -> SqlQuery b -> SqlQuery (a, b)
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery b
forall a. From a => SqlQuery a
from_
instance (From a, From b, From c) => From (a, b, c) where
from_ :: SqlQuery (a, b, c)
from_ = (,,) (a -> b -> c -> (a, b, c))
-> SqlQuery a -> SqlQuery (b -> c -> (a, b, c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SqlQuery a
forall a. From a => SqlQuery a
from_ SqlQuery (b -> c -> (a, b, c))
-> SqlQuery b -> SqlQuery (c -> (a, b, c))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery b
forall a. From a => SqlQuery a
from_ SqlQuery (c -> (a, b, c)) -> SqlQuery c -> SqlQuery (a, b, c)
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery c
forall a. From a => SqlQuery a
from_
instance (From a, From b, From c, From d) => From (a, b, c, d) where
from_ :: SqlQuery (a, b, c, d)
from_ = (,,,) (a -> b -> c -> d -> (a, b, c, d))
-> SqlQuery a -> SqlQuery (b -> c -> d -> (a, b, c, d))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SqlQuery a
forall a. From a => SqlQuery a
from_ SqlQuery (b -> c -> d -> (a, b, c, d))
-> SqlQuery b -> SqlQuery (c -> d -> (a, b, c, d))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery b
forall a. From a => SqlQuery a
from_ SqlQuery (c -> d -> (a, b, c, d))
-> SqlQuery c -> SqlQuery (d -> (a, b, c, d))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery c
forall a. From a => SqlQuery a
from_ SqlQuery (d -> (a, b, c, d)) -> SqlQuery d -> SqlQuery (a, b, c, d)
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery d
forall a. From a => SqlQuery a
from_
instance (From a, From b, From c, From d, From e) => From (a, b, c, d, e) where
from_ :: SqlQuery (a, b, c, d, e)
from_ = (,,,,) (a -> b -> c -> d -> e -> (a, b, c, d, e))
-> SqlQuery a -> SqlQuery (b -> c -> d -> e -> (a, b, c, d, e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SqlQuery a
forall a. From a => SqlQuery a
from_ SqlQuery (b -> c -> d -> e -> (a, b, c, d, e))
-> SqlQuery b -> SqlQuery (c -> d -> e -> (a, b, c, d, e))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery b
forall a. From a => SqlQuery a
from_ SqlQuery (c -> d -> e -> (a, b, c, d, e))
-> SqlQuery c -> SqlQuery (d -> e -> (a, b, c, d, e))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery c
forall a. From a => SqlQuery a
from_ SqlQuery (d -> e -> (a, b, c, d, e))
-> SqlQuery d -> SqlQuery (e -> (a, b, c, d, e))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery d
forall a. From a => SqlQuery a
from_ SqlQuery (e -> (a, b, c, d, e))
-> SqlQuery e -> SqlQuery (a, b, c, d, e)
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery e
forall a. From a => SqlQuery a
from_
instance
(From a, From b, From c, From d, From e, From f)
=>
From (a, b, c, d, e, f)
where
from_ :: SqlQuery (a, b, c, d, e, f)
from_ = (,,,,,) (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> SqlQuery a
-> SqlQuery (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SqlQuery a
forall a. From a => SqlQuery a
from_ SqlQuery (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> SqlQuery b -> SqlQuery (c -> d -> e -> f -> (a, b, c, d, e, f))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery b
forall a. From a => SqlQuery a
from_ SqlQuery (c -> d -> e -> f -> (a, b, c, d, e, f))
-> SqlQuery c -> SqlQuery (d -> e -> f -> (a, b, c, d, e, f))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery c
forall a. From a => SqlQuery a
from_ SqlQuery (d -> e -> f -> (a, b, c, d, e, f))
-> SqlQuery d -> SqlQuery (e -> f -> (a, b, c, d, e, f))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery d
forall a. From a => SqlQuery a
from_ SqlQuery (e -> f -> (a, b, c, d, e, f))
-> SqlQuery e -> SqlQuery (f -> (a, b, c, d, e, f))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery e
forall a. From a => SqlQuery a
from_ SqlQuery (f -> (a, b, c, d, e, f))
-> SqlQuery f -> SqlQuery (a, b, c, d, e, f)
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery f
forall a. From a => SqlQuery a
from_
instance
(From a, From b, From c, From d, From e, From f, From g)
=>
From (a, b, c, d, e, f, g)
where
from_ :: SqlQuery (a, b, c, d, e, f, g)
from_ =
(,,,,,,) (a -> b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> SqlQuery a
-> SqlQuery (b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SqlQuery a
forall a. From a => SqlQuery a
from_ SqlQuery (b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> SqlQuery b
-> SqlQuery (c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery b
forall a. From a => SqlQuery a
from_ SqlQuery (c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> SqlQuery c
-> SqlQuery (d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery c
forall a. From a => SqlQuery a
from_ SqlQuery (d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> SqlQuery d -> SqlQuery (e -> f -> g -> (a, b, c, d, e, f, g))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery d
forall a. From a => SqlQuery a
from_ SqlQuery (e -> f -> g -> (a, b, c, d, e, f, g))
-> SqlQuery e -> SqlQuery (f -> g -> (a, b, c, d, e, f, g))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery e
forall a. From a => SqlQuery a
from_ SqlQuery (f -> g -> (a, b, c, d, e, f, g))
-> SqlQuery f -> SqlQuery (g -> (a, b, c, d, e, f, g))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery f
forall a. From a => SqlQuery a
from_ SqlQuery (g -> (a, b, c, d, e, f, g))
-> SqlQuery g -> SqlQuery (a, b, c, d, e, f, g)
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery g
forall a. From a => SqlQuery a
from_
instance
(From a, From b, From c, From d, From e, From f, From g, From h)
=>
From (a, b, c, d, e, f, g, h)
where
from_ :: SqlQuery (a, b, c, d, e, f, g, h)
from_ =
(,,,,,,,) (a -> b -> c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> SqlQuery a
-> SqlQuery
(b -> c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SqlQuery a
forall a. From a => SqlQuery a
from_ SqlQuery
(b -> c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> SqlQuery b
-> SqlQuery
(c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery b
forall a. From a => SqlQuery a
from_ SqlQuery (c -> d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> SqlQuery c
-> SqlQuery (d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery c
forall a. From a => SqlQuery a
from_ SqlQuery (d -> e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> SqlQuery d
-> SqlQuery (e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery d
forall a. From a => SqlQuery a
from_ SqlQuery (e -> f -> g -> h -> (a, b, c, d, e, f, g, h))
-> SqlQuery e -> SqlQuery (f -> g -> h -> (a, b, c, d, e, f, g, h))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery e
forall a. From a => SqlQuery a
from_ SqlQuery (f -> g -> h -> (a, b, c, d, e, f, g, h))
-> SqlQuery f -> SqlQuery (g -> h -> (a, b, c, d, e, f, g, h))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery f
forall a. From a => SqlQuery a
from_ SqlQuery (g -> h -> (a, b, c, d, e, f, g, h))
-> SqlQuery g -> SqlQuery (h -> (a, b, c, d, e, f, g, h))
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery g
forall a. From a => SqlQuery a
from_ SqlQuery (h -> (a, b, c, d, e, f, g, h))
-> SqlQuery h -> SqlQuery (a, b, c, d, e, f, g, h)
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SqlQuery h
forall a. From a => SqlQuery a
from_
class FromPreprocess a where
fromPreprocess :: SqlQuery (PreprocessedFrom a)
instance
(PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val))
=>
FromPreprocess (SqlExpr (Entity val))
where
fromPreprocess :: SqlQuery (PreprocessedFrom (SqlExpr (Entity val)))
fromPreprocess = SqlQuery (PreprocessedFrom (SqlExpr (Entity val)))
forall a.
(PersistEntity a,
BackendCompatible SqlBackend (PersistEntityBackend a)) =>
SqlQuery (PreprocessedFrom (SqlExpr (Entity a)))
fromStart
instance
(PersistEntity val, BackendCompatible SqlBackend (PersistEntityBackend val))
=>
FromPreprocess (SqlExpr (Maybe (Entity val)))
where
fromPreprocess :: SqlQuery (PreprocessedFrom (SqlExpr (Maybe (Entity val))))
fromPreprocess = SqlQuery (PreprocessedFrom (SqlExpr (Maybe (Entity val))))
forall a.
(PersistEntity a,
BackendCompatible SqlBackend (PersistEntityBackend a)) =>
SqlQuery (PreprocessedFrom (SqlExpr (Maybe (Entity a))))
fromStartMaybe
instance
(FromPreprocess a, FromPreprocess b, IsJoinKind join)
=>
FromPreprocess (join a b)
where
fromPreprocess :: SqlQuery (PreprocessedFrom (join a b))
fromPreprocess = do
PreprocessedFrom a
a <- SqlQuery (PreprocessedFrom a)
forall a. FromPreprocess a => SqlQuery (PreprocessedFrom a)
fromPreprocess
PreprocessedFrom b
b <- SqlQuery (PreprocessedFrom b)
forall a. FromPreprocess a => SqlQuery (PreprocessedFrom a)
fromPreprocess
PreprocessedFrom a
-> PreprocessedFrom b -> SqlQuery (PreprocessedFrom (join a b))
forall (join :: * -> * -> *) a b.
IsJoinKind join =>
PreprocessedFrom a
-> PreprocessedFrom b -> SqlQuery (PreprocessedFrom (join a b))
fromJoin PreprocessedFrom a
a PreprocessedFrom b
b
data EsqueletoError
= CompositeKeyErr CompositeKeyError
| AliasedValueErr UnexpectedValueError
| UnexpectedCaseErr UnexpectedCaseError
| SqlBinOpCompositeErr SqlBinOpCompositeError
deriving (Int -> EsqueletoError -> ShowS
[EsqueletoError] -> ShowS
EsqueletoError -> String
(Int -> EsqueletoError -> ShowS)
-> (EsqueletoError -> String)
-> ([EsqueletoError] -> ShowS)
-> Show EsqueletoError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EsqueletoError -> ShowS
showsPrec :: Int -> EsqueletoError -> ShowS
$cshow :: EsqueletoError -> String
show :: EsqueletoError -> String
$cshowList :: [EsqueletoError] -> ShowS
showList :: [EsqueletoError] -> ShowS
Show)
instance Exception EsqueletoError
data UnexpectedValueError
= NotError
| ToInsertionError
| CombineInsertionError
| FoldHelpError
| SqlCaseError
| SqlCastAsError
| SqlFunctionError
| MakeOnClauseError
| MakeExcError
| MakeSetError
| MakeWhereError
| MakeHavingError
| FilterWhereAggError
| FilterWhereClauseError
deriving (Int -> CompositeKeyError -> ShowS
[CompositeKeyError] -> ShowS
CompositeKeyError -> String
(Int -> CompositeKeyError -> ShowS)
-> (CompositeKeyError -> String)
-> ([CompositeKeyError] -> ShowS)
-> Show CompositeKeyError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CompositeKeyError -> ShowS
showsPrec :: Int -> CompositeKeyError -> ShowS
$cshow :: CompositeKeyError -> String
show :: CompositeKeyError -> String
$cshowList :: [CompositeKeyError] -> ShowS
showList :: [CompositeKeyError] -> ShowS
Show)
type CompositeKeyError = UnexpectedValueError
data UnexpectedCaseError
= EmptySqlExprValueList
| MakeFromError
| UnsupportedSqlInsertIntoType
| InsertionFinalError
| NewIdentForError
| UnsafeSqlCaseError
| OperationNotSupported
| NotImplemented
deriving (Int -> UnexpectedCaseError -> ShowS
[UnexpectedCaseError] -> ShowS
UnexpectedCaseError -> String
(Int -> UnexpectedCaseError -> ShowS)
-> (UnexpectedCaseError -> String)
-> ([UnexpectedCaseError] -> ShowS)
-> Show UnexpectedCaseError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UnexpectedCaseError -> ShowS
showsPrec :: Int -> UnexpectedCaseError -> ShowS
$cshow :: UnexpectedCaseError -> String
show :: UnexpectedCaseError -> String
$cshowList :: [UnexpectedCaseError] -> ShowS
showList :: [UnexpectedCaseError] -> ShowS
Show)
data SqlBinOpCompositeError
= MismatchingLengthsError
| NullPlaceholdersError
| DeconstructionError
deriving (Int -> SqlBinOpCompositeError -> ShowS
[SqlBinOpCompositeError] -> ShowS
SqlBinOpCompositeError -> String
(Int -> SqlBinOpCompositeError -> ShowS)
-> (SqlBinOpCompositeError -> String)
-> ([SqlBinOpCompositeError] -> ShowS)
-> Show SqlBinOpCompositeError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SqlBinOpCompositeError -> ShowS
showsPrec :: Int -> SqlBinOpCompositeError -> ShowS
$cshow :: SqlBinOpCompositeError -> String
show :: SqlBinOpCompositeError -> String
$cshowList :: [SqlBinOpCompositeError] -> ShowS
showList :: [SqlBinOpCompositeError] -> ShowS
Show)
newtype SqlQuery a = Q { forall a.
SqlQuery a -> WriterT SideData (StateT IdentState Identity) a
unQ :: W.WriterT SideData (S.State IdentState) a }
deriving newtype ((forall a b. (a -> b) -> SqlQuery a -> SqlQuery b)
-> (forall a b. a -> SqlQuery b -> SqlQuery a) -> Functor SqlQuery
forall a b. a -> SqlQuery b -> SqlQuery a
forall a b. (a -> b) -> SqlQuery a -> SqlQuery b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> SqlQuery a -> SqlQuery b
fmap :: forall a b. (a -> b) -> SqlQuery a -> SqlQuery b
$c<$ :: forall a b. a -> SqlQuery b -> SqlQuery a
<$ :: forall a b. a -> SqlQuery b -> SqlQuery a
Functor, Functor SqlQuery
Functor SqlQuery =>
(forall a. a -> SqlQuery a)
-> (forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b)
-> (forall a b c.
(a -> b -> c) -> SqlQuery a -> SqlQuery b -> SqlQuery c)
-> (forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b)
-> (forall a b. SqlQuery a -> SqlQuery b -> SqlQuery a)
-> Applicative SqlQuery
forall a. a -> SqlQuery a
forall a b. SqlQuery a -> SqlQuery b -> SqlQuery a
forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b
forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
forall a b c.
(a -> b -> c) -> SqlQuery a -> SqlQuery b -> SqlQuery c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall a. a -> SqlQuery a
pure :: forall a. a -> SqlQuery a
$c<*> :: forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
<*> :: forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
$cliftA2 :: forall a b c.
(a -> b -> c) -> SqlQuery a -> SqlQuery b -> SqlQuery c
liftA2 :: forall a b c.
(a -> b -> c) -> SqlQuery a -> SqlQuery b -> SqlQuery c
$c*> :: forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b
*> :: forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b
$c<* :: forall a b. SqlQuery a -> SqlQuery b -> SqlQuery a
<* :: forall a b. SqlQuery a -> SqlQuery b -> SqlQuery a
Applicative, Applicative SqlQuery
Applicative SqlQuery =>
(forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b)
-> (forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b)
-> (forall a. a -> SqlQuery a)
-> Monad SqlQuery
forall a. a -> SqlQuery a
forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b
forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
>>= :: forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
$c>> :: forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b
>> :: forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b
$creturn :: forall a. a -> SqlQuery a
return :: forall a. a -> SqlQuery a
Monad)
type SqlEntity ent = (PersistEntity ent, PersistEntityBackend ent ~ SqlBackend)
data SideData = SideData
{ SideData -> DistinctClause
sdDistinctClause :: !DistinctClause
, SideData -> [FromClause]
sdFromClause :: ![FromClause]
, SideData -> [SetClause]
sdSetClause :: ![SetClause]
, SideData -> WhereClause
sdWhereClause :: !WhereClause
, SideData -> GroupByClause
sdGroupByClause :: !GroupByClause
, SideData -> WhereClause
sdHavingClause :: !HavingClause
, SideData -> [SqlExpr OrderBy]
sdOrderByClause :: ![OrderByClause]
, SideData -> LimitClause
sdLimitClause :: !LimitClause
, SideData -> LockingClause
sdLockingClause :: !LockingClause
, SideData -> [CommonTableExpressionClause]
sdCteClause :: ![CommonTableExpressionClause]
}
instance Semigroup SideData where
SideData DistinctClause
d [FromClause]
f [SetClause]
s WhereClause
w GroupByClause
g WhereClause
h [SqlExpr OrderBy]
o LimitClause
l LockingClause
k [CommonTableExpressionClause]
c <> :: SideData -> SideData -> SideData
<> SideData DistinctClause
d' [FromClause]
f' [SetClause]
s' WhereClause
w' GroupByClause
g' WhereClause
h' [SqlExpr OrderBy]
o' LimitClause
l' LockingClause
k' [CommonTableExpressionClause]
c' =
DistinctClause
-> [FromClause]
-> [SetClause]
-> WhereClause
-> GroupByClause
-> WhereClause
-> [SqlExpr OrderBy]
-> LimitClause
-> LockingClause
-> [CommonTableExpressionClause]
-> SideData
SideData (DistinctClause
d DistinctClause -> DistinctClause -> DistinctClause
forall a. Semigroup a => a -> a -> a
<> DistinctClause
d') ([FromClause]
f [FromClause] -> [FromClause] -> [FromClause]
forall a. Semigroup a => a -> a -> a
<> [FromClause]
f') ([SetClause]
s [SetClause] -> [SetClause] -> [SetClause]
forall a. Semigroup a => a -> a -> a
<> [SetClause]
s') (WhereClause
w WhereClause -> WhereClause -> WhereClause
forall a. Semigroup a => a -> a -> a
<> WhereClause
w') (GroupByClause
g GroupByClause -> GroupByClause -> GroupByClause
forall a. Semigroup a => a -> a -> a
<> GroupByClause
g') (WhereClause
h WhereClause -> WhereClause -> WhereClause
forall a. Semigroup a => a -> a -> a
<> WhereClause
h') ([SqlExpr OrderBy]
o [SqlExpr OrderBy] -> [SqlExpr OrderBy] -> [SqlExpr OrderBy]
forall a. Semigroup a => a -> a -> a
<> [SqlExpr OrderBy]
o') (LimitClause
l LimitClause -> LimitClause -> LimitClause
forall a. Semigroup a => a -> a -> a
<> LimitClause
l') (LockingClause
k LockingClause -> LockingClause -> LockingClause
forall a. Semigroup a => a -> a -> a
<> LockingClause
k') ([CommonTableExpressionClause]
c [CommonTableExpressionClause]
-> [CommonTableExpressionClause] -> [CommonTableExpressionClause]
forall a. Semigroup a => a -> a -> a
<> [CommonTableExpressionClause]
c')
instance Monoid SideData where
mempty :: SideData
mempty = DistinctClause
-> [FromClause]
-> [SetClause]
-> WhereClause
-> GroupByClause
-> WhereClause
-> [SqlExpr OrderBy]
-> LimitClause
-> LockingClause
-> [CommonTableExpressionClause]
-> SideData
SideData DistinctClause
forall a. Monoid a => a
mempty [FromClause]
forall a. Monoid a => a
mempty [SetClause]
forall a. Monoid a => a
mempty WhereClause
forall a. Monoid a => a
mempty GroupByClause
forall a. Monoid a => a
mempty WhereClause
forall a. Monoid a => a
mempty [SqlExpr OrderBy]
forall a. Monoid a => a
mempty LimitClause
forall a. Monoid a => a
mempty LockingClause
forall a. Monoid a => a
mempty [CommonTableExpressionClause]
forall a. Monoid a => a
mempty
mappend :: SideData -> SideData -> SideData
mappend = SideData -> SideData -> SideData
forall a. Semigroup a => a -> a -> a
(<>)
data DistinctClause
= DistinctAll
| DistinctStandard
| DistinctOn [SqlExpr DistinctOn]
instance Semigroup DistinctClause where
DistinctOn [SqlExpr DistinctOn]
a <> :: DistinctClause -> DistinctClause -> DistinctClause
<> DistinctOn [SqlExpr DistinctOn]
b = [SqlExpr DistinctOn] -> DistinctClause
DistinctOn ([SqlExpr DistinctOn]
a [SqlExpr DistinctOn]
-> [SqlExpr DistinctOn] -> [SqlExpr DistinctOn]
forall a. Semigroup a => a -> a -> a
<> [SqlExpr DistinctOn]
b)
DistinctOn [SqlExpr DistinctOn]
a <> DistinctClause
_ = [SqlExpr DistinctOn] -> DistinctClause
DistinctOn [SqlExpr DistinctOn]
a
DistinctClause
DistinctStandard <> DistinctClause
_ = DistinctClause
DistinctStandard
DistinctClause
DistinctAll <> DistinctClause
b = DistinctClause
b
instance Monoid DistinctClause where
mempty :: DistinctClause
mempty = DistinctClause
DistinctAll
mappend :: DistinctClause -> DistinctClause -> DistinctClause
mappend = DistinctClause -> DistinctClause -> DistinctClause
forall a. Semigroup a => a -> a -> a
(<>)
data FromClause
= FromStart Ident EntityDef
| FromJoin FromClause JoinKind FromClause (Maybe (SqlExpr (Value Bool)))
| OnClause (SqlExpr (Value Bool))
| FromRaw (NeedParens -> IdentInfo -> (TLB.Builder, [PersistValue]))
data CommonTableExpressionKind
= RecursiveCommonTableExpression
| NormalCommonTableExpression
deriving CommonTableExpressionKind -> CommonTableExpressionKind -> Bool
(CommonTableExpressionKind -> CommonTableExpressionKind -> Bool)
-> (CommonTableExpressionKind -> CommonTableExpressionKind -> Bool)
-> Eq CommonTableExpressionKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CommonTableExpressionKind -> CommonTableExpressionKind -> Bool
== :: CommonTableExpressionKind -> CommonTableExpressionKind -> Bool
$c/= :: CommonTableExpressionKind -> CommonTableExpressionKind -> Bool
/= :: CommonTableExpressionKind -> CommonTableExpressionKind -> Bool
Eq
data CommonTableExpressionClause =
CommonTableExpressionClause CommonTableExpressionKind Ident (IdentInfo -> (TLB.Builder, [PersistValue]))
data SubQueryType
= NormalSubQuery
| LateralSubQuery
deriving Int -> SubQueryType -> ShowS
[SubQueryType] -> ShowS
SubQueryType -> String
(Int -> SubQueryType -> ShowS)
-> (SubQueryType -> String)
-> ([SubQueryType] -> ShowS)
-> Show SubQueryType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SubQueryType -> ShowS
showsPrec :: Int -> SubQueryType -> ShowS
$cshow :: SubQueryType -> String
show :: SubQueryType -> String
$cshowList :: [SubQueryType] -> ShowS
showList :: [SubQueryType] -> ShowS
Show
collectIdents :: FromClause -> Set Ident
collectIdents :: FromClause -> Set Ident
collectIdents FromClause
fc = case FromClause
fc of
FromStart Ident
i EntityDef
_ -> Ident -> Set Ident
forall a. a -> Set a
Set.singleton Ident
i
FromJoin FromClause
lhs JoinKind
_ FromClause
rhs Maybe (SqlExpr (Value Bool))
_ -> FromClause -> Set Ident
collectIdents FromClause
lhs Set Ident -> Set Ident -> Set Ident
forall a. Semigroup a => a -> a -> a
<> FromClause -> Set Ident
collectIdents FromClause
rhs
OnClause SqlExpr (Value Bool)
_ -> Set Ident
forall a. Monoid a => a
mempty
FromRaw NeedParens -> IdentInfo -> (Builder, [PersistValue])
_ -> Set Ident
forall a. Monoid a => a
mempty
instance Show FromClause where
show :: FromClause -> String
show FromClause
fc = case FromClause
fc of
FromStart Ident
i EntityDef
_ ->
String
"(FromStart " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Ident -> String
forall a. Show a => a -> String
show Ident
i String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
")"
FromJoin FromClause
lhs JoinKind
jk FromClause
rhs Maybe (SqlExpr (Value Bool))
mexpr ->
[String] -> String
forall a. Monoid a => [a] -> a
mconcat
[ String
"(FromJoin "
, FromClause -> String
forall a. Show a => a -> String
show FromClause
lhs
, String
" "
, JoinKind -> String
forall a. Show a => a -> String
show JoinKind
jk
, String
" "
, case Maybe (SqlExpr (Value Bool))
mexpr of
Maybe (SqlExpr (Value Bool))
Nothing -> String
"(no on clause)"
Just SqlExpr (Value Bool)
expr -> String
"(" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> SqlExpr (Value Bool) -> String
render' SqlExpr (Value Bool)
expr String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
")"
, String
" "
, FromClause -> String
forall a. Show a => a -> String
show FromClause
rhs
, String
")"
]
OnClause SqlExpr (Value Bool)
expr ->
String
"(OnClause " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> SqlExpr (Value Bool) -> String
render' SqlExpr (Value Bool)
expr String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
")"
FromRaw NeedParens -> IdentInfo -> (Builder, [PersistValue])
_ ->
String
"(FromRaw _)"
where
dummy :: SqlBackend
dummy = MkSqlBackendArgs -> SqlBackend
mkSqlBackend MkSqlBackendArgs
{ connEscapeRawName :: Text -> Text
connEscapeRawName = Text -> Text
forall a. a -> a
id
, connPrepare :: Text -> IO Statement
connPrepare = Text -> IO Statement
forall a. HasCallStack => a
undefined
, connInsertSql :: EntityDef -> [PersistValue] -> InsertSqlResult
connInsertSql = EntityDef -> [PersistValue] -> InsertSqlResult
forall a. HasCallStack => a
undefined
, connStmtMap :: IORef (Map Text Statement)
connStmtMap = IORef (Map Text Statement)
forall a. HasCallStack => a
undefined
, connClose :: IO ()
connClose = IO ()
forall a. HasCallStack => a
undefined
, connMigrateSql :: [EntityDef]
-> (Text -> IO Statement)
-> EntityDef
-> IO (Either [Text] [(Bool, Text)])
connMigrateSql = [EntityDef]
-> (Text -> IO Statement)
-> EntityDef
-> IO (Either [Text] [(Bool, Text)])
forall a. HasCallStack => a
undefined
, connBegin :: (Text -> IO Statement) -> Maybe IsolationLevel -> IO ()
connBegin = (Text -> IO Statement) -> Maybe IsolationLevel -> IO ()
forall a. HasCallStack => a
undefined
, connCommit :: (Text -> IO Statement) -> IO ()
connCommit = (Text -> IO Statement) -> IO ()
forall a. HasCallStack => a
undefined
, connRollback :: (Text -> IO Statement) -> IO ()
connRollback = (Text -> IO Statement) -> IO ()
forall a. HasCallStack => a
undefined
, connEscapeFieldName :: FieldNameDB -> Text
connEscapeFieldName = FieldNameDB -> Text
forall a. HasCallStack => a
undefined
, connEscapeTableName :: EntityDef -> Text
connEscapeTableName = EntityDef -> Text
forall a. HasCallStack => a
undefined
, connNoLimit :: Text
connNoLimit = Text
forall a. HasCallStack => a
undefined
, connRDBMS :: Text
connRDBMS = Text
forall a. HasCallStack => a
undefined
, connLimitOffset :: (Int, Int) -> Text -> Text
connLimitOffset = (Int, Int) -> Text -> Text
forall a. HasCallStack => a
undefined
, connLogFunc :: LogFunc
connLogFunc = LogFunc
forall a. HasCallStack => a
undefined
}
render' :: SqlExpr (Value Bool) -> String
render' = Text -> String
T.unpack (Text -> String)
-> (SqlExpr (Value Bool) -> Text) -> SqlExpr (Value Bool) -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlBackend -> SqlExpr (Value Bool) -> Text
renderExpr SqlBackend
dummy
newtype SetClause = SetClause (SqlExpr Update)
collectOnClauses
:: SqlBackend
-> [FromClause]
-> Either (SqlExpr (Value Bool)) [FromClause]
collectOnClauses :: SqlBackend
-> [FromClause] -> Either (SqlExpr (Value Bool)) [FromClause]
collectOnClauses SqlBackend
sqlBackend = Set Ident
-> [FromClause]
-> [FromClause]
-> Either (SqlExpr (Value Bool)) [FromClause]
go Set Ident
forall a. Set a
Set.empty []
where
go :: Set Ident
-> [FromClause]
-> [FromClause]
-> Either (SqlExpr (Value Bool)) [FromClause]
go Set Ident
is [] (f :: FromClause
f@(FromStart Ident
i EntityDef
_) : [FromClause]
fs) =
([FromClause] -> [FromClause])
-> Either (SqlExpr (Value Bool)) [FromClause]
-> Either (SqlExpr (Value Bool)) [FromClause]
forall a b.
(a -> b)
-> Either (SqlExpr (Value Bool)) a
-> Either (SqlExpr (Value Bool)) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (FromClause
fFromClause -> [FromClause] -> [FromClause]
forall a. a -> [a] -> [a]
:) (Set Ident
-> [FromClause]
-> [FromClause]
-> Either (SqlExpr (Value Bool)) [FromClause]
go (Ident -> Set Ident -> Set Ident
forall a. Ord a => a -> Set a -> Set a
Set.insert Ident
i Set Ident
is) [] [FromClause]
fs)
go Set Ident
idents [FromClause]
acc (OnClause SqlExpr (Value Bool)
expr : [FromClause]
fs) = do
(Set Ident
idents', [FromClause]
a) <- Set Ident
-> [FromClause]
-> SqlExpr (Value Bool)
-> Either (SqlExpr (Value Bool)) (Set Ident, [FromClause])
findMatching Set Ident
idents [FromClause]
acc SqlExpr (Value Bool)
expr
Set Ident
-> [FromClause]
-> [FromClause]
-> Either (SqlExpr (Value Bool)) [FromClause]
go Set Ident
idents' [FromClause]
a [FromClause]
fs
go Set Ident
idents [FromClause]
acc (FromClause
f:[FromClause]
fs) =
Set Ident
-> [FromClause]
-> [FromClause]
-> Either (SqlExpr (Value Bool)) [FromClause]
go Set Ident
idents (FromClause
fFromClause -> [FromClause] -> [FromClause]
forall a. a -> [a] -> [a]
:[FromClause]
acc) [FromClause]
fs
go Set Ident
_ [FromClause]
acc [] =
[FromClause] -> Either (SqlExpr (Value Bool)) [FromClause]
forall a. a -> Either (SqlExpr (Value Bool)) a
forall (m :: * -> *) a. Monad m => a -> m a
return ([FromClause] -> Either (SqlExpr (Value Bool)) [FromClause])
-> [FromClause] -> Either (SqlExpr (Value Bool)) [FromClause]
forall a b. (a -> b) -> a -> b
$ [FromClause] -> [FromClause]
forall a. [a] -> [a]
reverse [FromClause]
acc
findMatching
:: Set Ident
-> [FromClause]
-> SqlExpr (Value Bool)
-> Either (SqlExpr (Value Bool)) (Set Ident, [FromClause])
findMatching :: Set Ident
-> [FromClause]
-> SqlExpr (Value Bool)
-> Either (SqlExpr (Value Bool)) (Set Ident, [FromClause])
findMatching Set Ident
idents [FromClause]
fromClauses SqlExpr (Value Bool)
expr =
case [FromClause]
fromClauses of
FromClause
f : [FromClause]
acc ->
let idents' :: Set Ident
idents' =
Set Ident
idents
Set Ident -> Set Ident -> Set Ident
forall a. Semigroup a => a -> a -> a
<> [Ident] -> Set Ident
forall a. Ord a => [a] -> Set a
Set.fromList
([Maybe Ident] -> [Ident]
forall a. [Maybe a] -> [a]
Maybe.catMaybes [FromClause -> Maybe Ident
findLeftmostIdent FromClause
f, FromClause -> Maybe Ident
findRightmostIdent FromClause
f])
in
case Set Ident
-> SqlExpr (Value Bool)
-> FromClause
-> Maybe (Set Ident, FromClause)
tryMatch Set Ident
idents' SqlExpr (Value Bool)
expr FromClause
f of
Just (Set Ident
idents'', FromClause
f') ->
(Set Ident, [FromClause])
-> Either (SqlExpr (Value Bool)) (Set Ident, [FromClause])
forall a. a -> Either (SqlExpr (Value Bool)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Set Ident
idents'', FromClause
f' FromClause -> [FromClause] -> [FromClause]
forall a. a -> [a] -> [a]
: [FromClause]
acc)
Maybe (Set Ident, FromClause)
Nothing ->
([FromClause] -> [FromClause])
-> (Set Ident, [FromClause]) -> (Set Ident, [FromClause])
forall a b. (a -> b) -> (Set Ident, a) -> (Set Ident, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (FromClause
fFromClause -> [FromClause] -> [FromClause]
forall a. a -> [a] -> [a]
:) ((Set Ident, [FromClause]) -> (Set Ident, [FromClause]))
-> Either (SqlExpr (Value Bool)) (Set Ident, [FromClause])
-> Either (SqlExpr (Value Bool)) (Set Ident, [FromClause])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Set Ident
-> [FromClause]
-> SqlExpr (Value Bool)
-> Either (SqlExpr (Value Bool)) (Set Ident, [FromClause])
findMatching Set Ident
idents' [FromClause]
acc SqlExpr (Value Bool)
expr
[] ->
SqlExpr (Value Bool)
-> Either (SqlExpr (Value Bool)) (Set Ident, [FromClause])
forall a b. a -> Either a b
Left SqlExpr (Value Bool)
expr
findRightmostIdent :: FromClause -> Maybe Ident
findRightmostIdent (FromStart Ident
i EntityDef
_) = Ident -> Maybe Ident
forall a. a -> Maybe a
Just Ident
i
findRightmostIdent (FromJoin FromClause
_ JoinKind
_ FromClause
r Maybe (SqlExpr (Value Bool))
_) = FromClause -> Maybe Ident
findRightmostIdent FromClause
r
findRightmostIdent (OnClause {}) = Maybe Ident
forall a. Maybe a
Nothing
findRightmostIdent (FromRaw NeedParens -> IdentInfo -> (Builder, [PersistValue])
_) = Maybe Ident
forall a. Maybe a
Nothing
findLeftmostIdent :: FromClause -> Maybe Ident
findLeftmostIdent (FromStart Ident
i EntityDef
_) = Ident -> Maybe Ident
forall a. a -> Maybe a
Just Ident
i
findLeftmostIdent (FromJoin FromClause
l JoinKind
_ FromClause
_ Maybe (SqlExpr (Value Bool))
_) = FromClause -> Maybe Ident
findLeftmostIdent FromClause
l
findLeftmostIdent (OnClause {}) = Maybe Ident
forall a. Maybe a
Nothing
findLeftmostIdent (FromRaw NeedParens -> IdentInfo -> (Builder, [PersistValue])
_) = Maybe Ident
forall a. Maybe a
Nothing
tryMatch
:: Set Ident
-> SqlExpr (Value Bool)
-> FromClause
-> Maybe (Set Ident, FromClause)
tryMatch :: Set Ident
-> SqlExpr (Value Bool)
-> FromClause
-> Maybe (Set Ident, FromClause)
tryMatch Set Ident
idents SqlExpr (Value Bool)
expr FromClause
fromClause =
case FromClause
fromClause of
FromJoin FromClause
l JoinKind
k FromClause
r Maybe (SqlExpr (Value Bool))
onClause ->
Maybe (Set Ident, FromClause)
matchTable Maybe (Set Ident, FromClause)
-> Maybe (Set Ident, FromClause) -> Maybe (Set Ident, FromClause)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe (Set Ident, FromClause)
matchR Maybe (Set Ident, FromClause)
-> Maybe (Set Ident, FromClause) -> Maybe (Set Ident, FromClause)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe (Set Ident, FromClause)
matchC Maybe (Set Ident, FromClause)
-> Maybe (Set Ident, FromClause) -> Maybe (Set Ident, FromClause)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe (Set Ident, FromClause)
matchL Maybe (Set Ident, FromClause)
-> Maybe (Set Ident, FromClause) -> Maybe (Set Ident, FromClause)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe (Set Ident, FromClause)
matchPartial
where
matchR :: Maybe (Set Ident, FromClause)
matchR = (FromClause -> FromClause)
-> (Set Ident, FromClause) -> (Set Ident, FromClause)
forall a b. (a -> b) -> (Set Ident, a) -> (Set Ident, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\FromClause
r' -> FromClause
-> JoinKind
-> FromClause
-> Maybe (SqlExpr (Value Bool))
-> FromClause
FromJoin FromClause
l JoinKind
k FromClause
r' Maybe (SqlExpr (Value Bool))
onClause)
((Set Ident, FromClause) -> (Set Ident, FromClause))
-> Maybe (Set Ident, FromClause) -> Maybe (Set Ident, FromClause)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Set Ident
-> SqlExpr (Value Bool)
-> FromClause
-> Maybe (Set Ident, FromClause)
tryMatch Set Ident
idents SqlExpr (Value Bool)
expr FromClause
r
matchL :: Maybe (Set Ident, FromClause)
matchL = (FromClause -> FromClause)
-> (Set Ident, FromClause) -> (Set Ident, FromClause)
forall a b. (a -> b) -> (Set Ident, a) -> (Set Ident, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\FromClause
l' -> FromClause
-> JoinKind
-> FromClause
-> Maybe (SqlExpr (Value Bool))
-> FromClause
FromJoin FromClause
l' JoinKind
k FromClause
r Maybe (SqlExpr (Value Bool))
onClause)
((Set Ident, FromClause) -> (Set Ident, FromClause))
-> Maybe (Set Ident, FromClause) -> Maybe (Set Ident, FromClause)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Set Ident
-> SqlExpr (Value Bool)
-> FromClause
-> Maybe (Set Ident, FromClause)
tryMatch Set Ident
idents SqlExpr (Value Bool)
expr FromClause
l
matchPartial :: Maybe (Set Ident, FromClause)
matchPartial = do
Ident
i1 <- FromClause -> Maybe Ident
findLeftmostIdent FromClause
l
Ident
i2 <- FromClause -> Maybe Ident
findLeftmostIdent FromClause
r
let leftIdents :: Set Ident
leftIdents = FromClause -> Set Ident
collectIdents FromClause
l
Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$
Set Ident -> Set Ident -> Bool
forall a. Ord a => Set a -> Set a -> Bool
Set.isSubsetOf
Set Ident
identsInOnClause
([Ident] -> Set Ident
forall a. Ord a => [a] -> Set a
Set.fromList [Ident
i1, Ident
i2] Set Ident -> Set Ident -> Set Ident
forall a. Semigroup a => a -> a -> a
<> Set Ident
leftIdents)
Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ JoinKind
k JoinKind -> JoinKind -> Bool
forall a. Eq a => a -> a -> Bool
/= JoinKind
CrossJoinKind
Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Maybe (SqlExpr (Value Bool)) -> Bool
forall a. Maybe a -> Bool
Maybe.isNothing Maybe (SqlExpr (Value Bool))
onClause
(Set Ident, FromClause) -> Maybe (Set Ident, FromClause)
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Set Ident
idents, FromClause
-> JoinKind
-> FromClause
-> Maybe (SqlExpr (Value Bool))
-> FromClause
FromJoin FromClause
l JoinKind
k FromClause
r (SqlExpr (Value Bool) -> Maybe (SqlExpr (Value Bool))
forall a. a -> Maybe a
Just SqlExpr (Value Bool)
expr))
matchC :: Maybe (Set Ident, FromClause)
matchC =
case Maybe (SqlExpr (Value Bool))
onClause of
Maybe (SqlExpr (Value Bool))
Nothing
| Text
"?" Text -> Text -> Bool
`T.isInfixOf` Text
renderedExpr ->
(Set Ident, FromClause) -> Maybe (Set Ident, FromClause)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Set Ident
idents, FromClause
-> JoinKind
-> FromClause
-> Maybe (SqlExpr (Value Bool))
-> FromClause
FromJoin FromClause
l JoinKind
k FromClause
r (SqlExpr (Value Bool) -> Maybe (SqlExpr (Value Bool))
forall a. a -> Maybe a
Just SqlExpr (Value Bool)
expr))
| Set Ident -> Bool
forall a. Set a -> Bool
Set.null Set Ident
identsInOnClause ->
(Set Ident, FromClause) -> Maybe (Set Ident, FromClause)
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return (Set Ident
idents, FromClause
-> JoinKind
-> FromClause
-> Maybe (SqlExpr (Value Bool))
-> FromClause
FromJoin FromClause
l JoinKind
k FromClause
r (SqlExpr (Value Bool) -> Maybe (SqlExpr (Value Bool))
forall a. a -> Maybe a
Just SqlExpr (Value Bool)
expr))
| Bool
otherwise ->
Maybe (Set Ident, FromClause)
forall a. Maybe a
Nothing
Just SqlExpr (Value Bool)
_ ->
Maybe (Set Ident, FromClause)
forall a. Maybe a
Nothing
matchTable :: Maybe (Set Ident, FromClause)
matchTable = do
Ident
i1 <- FromClause -> Maybe Ident
findLeftmostIdent FromClause
r
Ident
i2 <- FromClause -> Maybe Ident
findRightmostIdent FromClause
l
Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ [Ident] -> Set Ident
forall a. Ord a => [a] -> Set a
Set.fromList [Ident
i1, Ident
i2] Set Ident -> Set Ident -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set Ident
identsInOnClause
Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ JoinKind
k JoinKind -> JoinKind -> Bool
forall a. Eq a => a -> a -> Bool
/= JoinKind
CrossJoinKind
Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Maybe (SqlExpr (Value Bool)) -> Bool
forall a. Maybe a -> Bool
Maybe.isNothing Maybe (SqlExpr (Value Bool))
onClause
(Set Ident, FromClause) -> Maybe (Set Ident, FromClause)
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([Ident] -> Set Ident
forall a. Ord a => [a] -> Set a
Set.fromList [Ident
i1, Ident
i2] Set Ident -> Set Ident -> Set Ident
forall a. Semigroup a => a -> a -> a
<> Set Ident
idents, FromClause
-> JoinKind
-> FromClause
-> Maybe (SqlExpr (Value Bool))
-> FromClause
FromJoin FromClause
l JoinKind
k FromClause
r (SqlExpr (Value Bool) -> Maybe (SqlExpr (Value Bool))
forall a. a -> Maybe a
Just SqlExpr (Value Bool)
expr))
FromClause
_ ->
Maybe (Set Ident, FromClause)
forall a. Maybe a
Nothing
where
identsInOnClause :: Set Ident
identsInOnClause =
Set Ident
onExprToTableIdentifiers
renderedExpr :: Text
renderedExpr =
SqlBackend -> SqlExpr (Value Bool) -> Text
renderExpr SqlBackend
sqlBackend SqlExpr (Value Bool)
expr
onExprToTableIdentifiers :: Set Ident
onExprToTableIdentifiers =
(TableAccess -> Ident) -> Set TableAccess -> Set Ident
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map (Text -> Ident
I (Text -> Ident) -> (TableAccess -> Text) -> TableAccess -> Ident
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TableAccess -> Text
tableAccessTable)
(Set TableAccess -> Set Ident)
-> (Text -> Set TableAccess) -> Text -> Set Ident
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> Set TableAccess)
-> (Set TableAccess -> Set TableAccess)
-> Either String (Set TableAccess)
-> Set TableAccess
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either String -> Set TableAccess
forall a. HasCallStack => String -> a
error Set TableAccess -> Set TableAccess
forall a. a -> a
id
(Either String (Set TableAccess) -> Set TableAccess)
-> (Text -> Either String (Set TableAccess))
-> Text
-> Set TableAccess
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlBackend -> Text -> Either String (Set TableAccess)
parseOnExpr SqlBackend
sqlBackend
(Text -> Set Ident) -> Text -> Set Ident
forall a b. (a -> b) -> a -> b
$ Text
renderedExpr
data WhereClause = Where (SqlExpr (Value Bool))
| NoWhere
instance Semigroup WhereClause where
WhereClause
NoWhere <> :: WhereClause -> WhereClause -> WhereClause
<> WhereClause
w = WhereClause
w
WhereClause
w <> WhereClause
NoWhere = WhereClause
w
Where SqlExpr (Value Bool)
e1 <> Where SqlExpr (Value Bool)
e2 = SqlExpr (Value Bool) -> WhereClause
Where (SqlExpr (Value Bool)
e1 SqlExpr (Value Bool)
-> SqlExpr (Value Bool) -> SqlExpr (Value Bool)
&&. SqlExpr (Value Bool)
e2)
instance Monoid WhereClause where
mempty :: WhereClause
mempty = WhereClause
NoWhere
mappend :: WhereClause -> WhereClause -> WhereClause
mappend = WhereClause -> WhereClause -> WhereClause
forall a. Semigroup a => a -> a -> a
(<>)
newtype GroupByClause = GroupBy [SomeValue]
instance Semigroup GroupByClause where
GroupBy [SomeValue]
fs <> :: GroupByClause -> GroupByClause -> GroupByClause
<> GroupBy [SomeValue]
fs' = [SomeValue] -> GroupByClause
GroupBy ([SomeValue]
fs [SomeValue] -> [SomeValue] -> [SomeValue]
forall a. Semigroup a => a -> a -> a
<> [SomeValue]
fs')
instance Monoid GroupByClause where
mempty :: GroupByClause
mempty = [SomeValue] -> GroupByClause
GroupBy []
mappend :: GroupByClause -> GroupByClause -> GroupByClause
mappend = GroupByClause -> GroupByClause -> GroupByClause
forall a. Semigroup a => a -> a -> a
(<>)
type HavingClause = WhereClause
type OrderByClause = SqlExpr OrderBy
data LimitClause = Limit (Maybe Int64) (Maybe Int64)
deriving LimitClause -> LimitClause -> Bool
(LimitClause -> LimitClause -> Bool)
-> (LimitClause -> LimitClause -> Bool) -> Eq LimitClause
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LimitClause -> LimitClause -> Bool
== :: LimitClause -> LimitClause -> Bool
$c/= :: LimitClause -> LimitClause -> Bool
/= :: LimitClause -> LimitClause -> Bool
Eq
instance Semigroup LimitClause where
Limit Maybe Int64
l1 Maybe Int64
o1 <> :: LimitClause -> LimitClause -> LimitClause
<> Limit Maybe Int64
l2 Maybe Int64
o2 =
Maybe Int64 -> Maybe Int64 -> LimitClause
Limit (Maybe Int64
l2 Maybe Int64 -> Maybe Int64 -> Maybe Int64
forall a. Maybe a -> Maybe a -> Maybe a
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` Maybe Int64
l1) (Maybe Int64
o2 Maybe Int64 -> Maybe Int64 -> Maybe Int64
forall a. Maybe a -> Maybe a -> Maybe a
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` Maybe Int64
o1)
instance Monoid LimitClause where
mempty :: LimitClause
mempty = Maybe Int64 -> Maybe Int64 -> LimitClause
Limit Maybe Int64
forall a. Maybe a
forall (m :: * -> *) a. MonadPlus m => m a
mzero Maybe Int64
forall a. Maybe a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
data LockingClause =
LegacyLockingClause LockingKind
| PostgresLockingClauses [PostgresLockingKind]
| NoLockingClause
instance Semigroup LockingClause where
<> :: LockingClause -> LockingClause -> LockingClause
(<>) (PostgresLockingClauses [PostgresLockingKind]
pleft) (PostgresLockingClauses [PostgresLockingKind]
pright) = [PostgresLockingKind] -> LockingClause
PostgresLockingClauses ([PostgresLockingKind]
pleft [PostgresLockingKind]
-> [PostgresLockingKind] -> [PostgresLockingKind]
forall a. Semigroup a => a -> a -> a
<> [PostgresLockingKind]
pright)
(<>) LockingClause
mleft LockingClause
NoLockingClause = LockingClause
mleft
(<>) LockingClause
_ LockingClause
mright = LockingClause
mright
instance Monoid LockingClause where
mempty :: LockingClause
mempty = LockingClause
NoLockingClause
mappend :: LockingClause -> LockingClause -> LockingClause
mappend = LockingClause -> LockingClause -> LockingClause
forall a. Semigroup a => a -> a -> a
(<>)
newtype Ident = I T.Text
deriving (Ident -> Ident -> Bool
(Ident -> Ident -> Bool) -> (Ident -> Ident -> Bool) -> Eq Ident
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Ident -> Ident -> Bool
== :: Ident -> Ident -> Bool
$c/= :: Ident -> Ident -> Bool
/= :: Ident -> Ident -> Bool
Eq, Eq Ident
Eq Ident =>
(Ident -> Ident -> Ordering)
-> (Ident -> Ident -> Bool)
-> (Ident -> Ident -> Bool)
-> (Ident -> Ident -> Bool)
-> (Ident -> Ident -> Bool)
-> (Ident -> Ident -> Ident)
-> (Ident -> Ident -> Ident)
-> Ord Ident
Ident -> Ident -> Bool
Ident -> Ident -> Ordering
Ident -> Ident -> Ident
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 :: Ident -> Ident -> Ordering
compare :: Ident -> Ident -> Ordering
$c< :: Ident -> Ident -> Bool
< :: Ident -> Ident -> Bool
$c<= :: Ident -> Ident -> Bool
<= :: Ident -> Ident -> Bool
$c> :: Ident -> Ident -> Bool
> :: Ident -> Ident -> Bool
$c>= :: Ident -> Ident -> Bool
>= :: Ident -> Ident -> Bool
$cmax :: Ident -> Ident -> Ident
max :: Ident -> Ident -> Ident
$cmin :: Ident -> Ident -> Ident
min :: Ident -> Ident -> Ident
Ord, Int -> Ident -> ShowS
[Ident] -> ShowS
Ident -> String
(Int -> Ident -> ShowS)
-> (Ident -> String) -> ([Ident] -> ShowS) -> Show Ident
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Ident -> ShowS
showsPrec :: Int -> Ident -> ShowS
$cshow :: Ident -> String
show :: Ident -> String
$cshowList :: [Ident] -> ShowS
showList :: [Ident] -> ShowS
Show)
newtype IdentState = IdentState { IdentState -> HashSet Text
inUse :: HS.HashSet T.Text }
initialIdentState :: IdentState
initialIdentState :: IdentState
initialIdentState = HashSet Text -> IdentState
IdentState HashSet Text
forall a. Monoid a => a
mempty
newIdentFor :: DBName -> SqlQuery Ident
newIdentFor :: DBName -> SqlQuery Ident
newIdentFor (DBName Text
original) = WriterT SideData (StateT IdentState Identity) Ident
-> SqlQuery Ident
forall a.
WriterT SideData (StateT IdentState Identity) a -> SqlQuery a
Q (WriterT SideData (StateT IdentState Identity) Ident
-> SqlQuery Ident)
-> WriterT SideData (StateT IdentState Identity) Ident
-> SqlQuery Ident
forall a b. (a -> b) -> a -> b
$ State IdentState Ident
-> WriterT SideData (StateT IdentState Identity) Ident
forall (m :: * -> *) a. Monad m => m a -> WriterT SideData m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State IdentState Ident
-> WriterT SideData (StateT IdentState Identity) Ident)
-> State IdentState Ident
-> WriterT SideData (StateT IdentState Identity) Ident
forall a b. (a -> b) -> a -> b
$ Maybe Int -> State IdentState Ident
findFree Maybe Int
forall a. Maybe a
Nothing
where
findFree :: Maybe Int -> State IdentState Ident
findFree Maybe Int
msuffix = do
let
withSuffix :: Text
withSuffix =
(Text -> Text)
-> (Int -> Text -> Text) -> Maybe Int -> Text -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text -> Text
forall a. a -> a
id (\Int
suffix -> (Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
suffix))) Maybe Int
msuffix Text
original
Bool
isInUse <- (IdentState -> Bool) -> StateT IdentState Identity Bool
forall (m :: * -> *) s a. Monad m => (s -> a) -> StateT s m a
S.gets (Text -> HashSet Text -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
HS.member Text
withSuffix (HashSet Text -> Bool)
-> (IdentState -> HashSet Text) -> IdentState -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdentState -> HashSet Text
inUse)
if Bool
isInUse
then Maybe Int -> State IdentState Ident
findFree (Int -> Int
forall a. Enum a => a -> a
succ (Int -> Int) -> Maybe Int -> Maybe Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Maybe Int
msuffix Maybe Int -> Maybe Int -> Maybe Int
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Maybe Int
forall a. a -> Maybe a
Just (Int
1 :: Int)))
else do
(IdentState -> IdentState) -> StateT IdentState Identity ()
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
S.modify (\IdentState
s -> IdentState
s { inUse = HS.insert withSuffix (inUse s) })
Ident -> State IdentState Ident
forall a. a -> StateT IdentState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Ident
I Text
withSuffix)
type IdentInfo = (SqlBackend, IdentState)
useIdent :: IdentInfo -> Ident -> TLB.Builder
useIdent :: IdentInfo -> Ident -> Builder
useIdent IdentInfo
info (I Text
ident) = IdentInfo -> DBName -> Builder
fromDBName IdentInfo
info (DBName -> Builder) -> DBName -> Builder
forall a b. (a -> b) -> a -> b
$ Text -> DBName
DBName Text
ident
data SqlExprMeta = SqlExprMeta
{
SqlExprMeta -> Maybe (IdentInfo -> [Builder])
sqlExprMetaCompositeFields :: Maybe (IdentInfo -> [TLB.Builder])
, SqlExprMeta -> Maybe Ident
sqlExprMetaAlias :: Maybe Ident
, SqlExprMeta -> Bool
sqlExprMetaIsReference :: Bool
}
noMeta :: SqlExprMeta
noMeta :: SqlExprMeta
noMeta = SqlExprMeta
{ sqlExprMetaCompositeFields :: Maybe (IdentInfo -> [Builder])
sqlExprMetaCompositeFields = Maybe (IdentInfo -> [Builder])
forall a. Maybe a
Nothing
, sqlExprMetaAlias :: Maybe Ident
sqlExprMetaAlias = Maybe Ident
forall a. Maybe a
Nothing
, sqlExprMetaIsReference :: Bool
sqlExprMetaIsReference = Bool
False
}
hasCompositeKeyMeta :: SqlExprMeta -> Bool
hasCompositeKeyMeta :: SqlExprMeta -> Bool
hasCompositeKeyMeta = Maybe (IdentInfo -> [Builder]) -> Bool
forall a. Maybe a -> Bool
Maybe.isJust (Maybe (IdentInfo -> [Builder]) -> Bool)
-> (SqlExprMeta -> Maybe (IdentInfo -> [Builder]))
-> SqlExprMeta
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlExprMeta -> Maybe (IdentInfo -> [Builder])
sqlExprMetaCompositeFields
entityAsValue
:: SqlExpr (Entity val)
-> SqlExpr (Value (Entity val))
entityAsValue :: forall val. SqlExpr (Entity val) -> SqlExpr (Value (Entity val))
entityAsValue = SqlExpr (Entity val) -> SqlExpr (Value (Entity val))
forall a b. Coercible a b => a -> b
coerce
entityAsValueMaybe
:: SqlExpr (Maybe (Entity val))
-> SqlExpr (Value (Maybe (Entity val)))
entityAsValueMaybe :: forall val.
SqlExpr (Maybe (Entity val))
-> SqlExpr (Value (Maybe (Entity val)))
entityAsValueMaybe = SqlExpr (Maybe (Entity val))
-> SqlExpr (Value (Maybe (Entity val)))
forall a b. Coercible a b => a -> b
coerce
data SqlExpr a = ERaw SqlExprMeta (NeedParens -> IdentInfo -> (TLB.Builder, [PersistValue]))
instance TypeError SqlExprFunctorMessage => Functor SqlExpr where
fmap :: forall a b. (a -> b) -> SqlExpr a -> SqlExpr b
fmap = String -> (a -> b) -> SqlExpr a -> SqlExpr b
forall a. HasCallStack => String -> a
error String
"impossible"
type SqlExprFunctorMessage =
'Text "You're trying to treat `SqlExpr` like a `Functor`, but it cannot be one."
':$$: 'Text "We would need to send arbitrary functions to the database for interpretation to support that instance."
':$$: 'Text "See the docs for the fake instance of `Functor SqlExpr` for more information."
':$$: 'Text "Consider using a SQL function with `unsafeSqlFunction` and a good type signature."
instance
(PersistEntity rec, PersistField typ, SymbolToField sym rec typ)
=>
HasField sym (SqlExpr (Entity rec)) (SqlExpr (Value typ))
where
getField :: SqlExpr (Entity rec) -> SqlExpr (Value typ)
getField SqlExpr (Entity rec)
expr = SqlExpr (Entity rec)
expr SqlExpr (Entity rec) -> EntityField rec typ -> SqlExpr (Value typ)
forall typ val.
(PersistEntity val, PersistField typ) =>
SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ)
^. forall (sym :: Symbol) rec typ.
SymbolToField sym rec typ =>
EntityField rec typ
symbolToField @sym
instance
(PersistEntity rec, PersistField typ, SymbolToField sym rec typ)
=>
HasField sym (SqlExpr (Maybe (Entity rec))) (SqlExpr (Value (Maybe typ)))
where
getField :: SqlExpr (Maybe (Entity rec)) -> SqlExpr (Value (Maybe typ))
getField SqlExpr (Maybe (Entity rec))
expr = SqlExpr (Maybe (Entity rec))
expr SqlExpr (Maybe (Entity rec))
-> EntityField rec typ -> SqlExpr (Value (Maybe typ))
forall val typ.
(PersistEntity val, PersistField typ) =>
SqlExpr (Maybe (Entity val))
-> EntityField val typ -> SqlExpr (Value (Maybe typ))
?. forall (sym :: Symbol) rec typ.
SymbolToField sym rec typ =>
EntityField rec typ
symbolToField @sym
data PreprocessedFrom a = PreprocessedFrom a FromClause
data InsertFinal
data NeedParens = Parens | Never
deriving NeedParens -> NeedParens -> Bool
(NeedParens -> NeedParens -> Bool)
-> (NeedParens -> NeedParens -> Bool) -> Eq NeedParens
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NeedParens -> NeedParens -> Bool
== :: NeedParens -> NeedParens -> Bool
$c/= :: NeedParens -> NeedParens -> Bool
/= :: NeedParens -> NeedParens -> Bool
Eq
parensM :: NeedParens -> TLB.Builder -> TLB.Builder
parensM :: NeedParens -> Builder -> Builder
parensM NeedParens
Never = Builder -> Builder
forall a. a -> a
id
parensM NeedParens
Parens = Builder -> Builder
parens
data OrderByType = ASC | DESC
instance ToSomeValues (SqlExpr (Value a)) where
toSomeValues :: SqlExpr (Value a) -> [SomeValue]
toSomeValues SqlExpr (Value a)
a = [SqlExpr (Value a) -> SomeValue
forall a. SqlExpr (Value a) -> SomeValue
SomeValue SqlExpr (Value a)
a]
fieldName
:: (PersistEntity val, PersistField typ)
=> IdentInfo -> EntityField val typ -> TLB.Builder
fieldName :: forall val typ.
(PersistEntity val, PersistField typ) =>
IdentInfo -> EntityField val typ -> Builder
fieldName IdentInfo
info = IdentInfo -> DBName -> Builder
fromDBName IdentInfo
info (DBName -> Builder)
-> (EntityField val typ -> DBName)
-> EntityField val typ
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldNameDB -> DBName
forall a b. Coercible a b => a -> b
coerce (FieldNameDB -> DBName)
-> (EntityField val typ -> FieldNameDB)
-> EntityField val typ
-> DBName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldDef -> FieldNameDB
fieldDB (FieldDef -> FieldNameDB)
-> (EntityField val typ -> FieldDef)
-> EntityField val typ
-> FieldNameDB
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EntityField val typ -> FieldDef
forall record typ.
PersistEntity record =>
EntityField record typ -> FieldDef
forall typ. EntityField val typ -> FieldDef
persistFieldDef
setAux
:: (PersistEntity val, PersistField typ)
=> EntityField val typ
-> (SqlExpr (Entity val) -> SqlExpr (Value typ))
-> (SqlExpr (Entity val) -> SqlExpr Update)
setAux :: forall val typ.
(PersistEntity val, PersistField typ) =>
EntityField val typ
-> (SqlExpr (Entity val) -> SqlExpr (Value typ))
-> SqlExpr (Entity val)
-> SqlExpr Update
setAux EntityField val typ
field SqlExpr (Entity val) -> SqlExpr (Value typ)
value = \SqlExpr (Entity val)
ent -> SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr Update
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr Update)
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr Update
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info ->
let ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
valueF = SqlExpr (Entity val) -> SqlExpr (Value typ)
value SqlExpr (Entity val)
ent
(Builder
valueToSet, [PersistValue]
valueVals) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
valueF NeedParens
Parens IdentInfo
info
in (IdentInfo -> EntityField val typ -> Builder
forall val typ.
(PersistEntity val, PersistField typ) =>
IdentInfo -> EntityField val typ -> Builder
fieldName IdentInfo
info EntityField val typ
field Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" = " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
valueToSet, [PersistValue]
valueVals)
sub :: PersistField a => Mode -> SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
sub :: forall a.
PersistField a =>
Mode -> SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
sub Mode
mode SqlQuery (SqlExpr (Value a))
query = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info -> (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Builder -> Builder
parens ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ Mode
-> IdentInfo
-> SqlQuery (SqlExpr (Value a))
-> (Builder, [PersistValue])
forall a r backend.
(SqlSelect a r, BackendCompatible SqlBackend backend) =>
Mode
-> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])
toRawSql Mode
mode IdentInfo
info SqlQuery (SqlExpr (Value a))
query
fromDBName :: IdentInfo -> DBName -> TLB.Builder
fromDBName :: IdentInfo -> DBName -> Builder
fromDBName (SqlBackend
conn, IdentState
_) = Text -> Builder
TLB.fromText (Text -> Builder) -> (DBName -> Text) -> DBName -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> SqlBackend -> Text) -> SqlBackend -> Text -> Text
forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> SqlBackend -> Text
forall backend (m :: * -> *).
(BackendCompatible SqlBackend backend, MonadReader backend m) =>
Text -> m Text
getEscapedRawName SqlBackend
conn (Text -> Text) -> (DBName -> Text) -> DBName -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DBName -> Text
unDBName
existsHelper :: SqlQuery () -> SqlExpr (Value Bool)
existsHelper :: SqlQuery () -> SqlExpr (Value Bool)
existsHelper = Mode -> SqlQuery (SqlExpr (Value Bool)) -> SqlExpr (Value Bool)
forall a.
PersistField a =>
Mode -> SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a)
sub Mode
SELECT (SqlQuery (SqlExpr (Value Bool)) -> SqlExpr (Value Bool))
-> (SqlQuery () -> SqlQuery (SqlExpr (Value Bool)))
-> SqlQuery ()
-> SqlExpr (Value Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SqlQuery ()
-> SqlQuery (SqlExpr (Value Bool))
-> SqlQuery (SqlExpr (Value Bool))
forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SqlExpr (Value Bool) -> SqlQuery (SqlExpr (Value Bool))
forall a. a -> SqlQuery a
forall (m :: * -> *) a. Monad m => a -> m a
return SqlExpr (Value Bool)
true)
where
true :: SqlExpr (Value Bool)
true :: SqlExpr (Value Bool)
true = Bool -> SqlExpr (Value Bool)
forall typ. PersistField typ => typ -> SqlExpr (Value typ)
val Bool
True
unsafeSqlCase :: PersistField a => [(SqlExpr (Value Bool), SqlExpr (Value a))] -> SqlExpr (Value a) -> SqlExpr (Value a)
unsafeSqlCase :: forall a.
PersistField a =>
[(SqlExpr (Value Bool), SqlExpr (Value a))]
-> SqlExpr (Value a) -> SqlExpr (Value a)
unsafeSqlCase [(SqlExpr (Value Bool), SqlExpr (Value a))]
when SqlExpr (Value a)
v = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta NeedParens -> IdentInfo -> (Builder, [PersistValue])
buildCase
where
buildCase :: NeedParens -> IdentInfo -> (TLB.Builder, [PersistValue])
buildCase :: NeedParens -> IdentInfo -> (Builder, [PersistValue])
buildCase NeedParens
_ IdentInfo
info =
let (Builder
elseText, [PersistValue]
elseVals) = SqlExpr (Value a)
-> NeedParens -> IdentInfo -> (Builder, [PersistValue])
forall a.
SqlExpr (Value a)
-> NeedParens -> IdentInfo -> (Builder, [PersistValue])
valueToSql SqlExpr (Value a)
v NeedParens
Parens IdentInfo
info
(Builder
whenText, [PersistValue]
whenVals) = [(SqlExpr (Value Bool), SqlExpr (Value a))]
-> NeedParens -> IdentInfo -> (Builder, [PersistValue])
forall a.
[(SqlExpr (Value Bool), SqlExpr (Value a))]
-> NeedParens -> IdentInfo -> (Builder, [PersistValue])
mapWhen [(SqlExpr (Value Bool), SqlExpr (Value a))]
when NeedParens
Parens IdentInfo
info
in ( Builder
"CASE" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
whenText Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" ELSE " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
elseText Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" END", [PersistValue]
whenVals [PersistValue] -> [PersistValue] -> [PersistValue]
forall a. Semigroup a => a -> a -> a
<> [PersistValue]
elseVals)
mapWhen :: [(SqlExpr (Value Bool), SqlExpr (Value a))] -> NeedParens -> IdentInfo -> (TLB.Builder, [PersistValue])
mapWhen :: forall a.
[(SqlExpr (Value Bool), SqlExpr (Value a))]
-> NeedParens -> IdentInfo -> (Builder, [PersistValue])
mapWhen [] NeedParens
_ IdentInfo
_ = EsqueletoError -> (Builder, [PersistValue])
forall a e. Exception e => e -> a
throw (UnexpectedCaseError -> EsqueletoError
UnexpectedCaseErr UnexpectedCaseError
UnsafeSqlCaseError)
mapWhen [(SqlExpr (Value Bool), SqlExpr (Value a))]
when' NeedParens
p IdentInfo
info = ((Builder, [PersistValue])
-> (SqlExpr (Value Bool), SqlExpr (Value a))
-> (Builder, [PersistValue]))
-> (Builder, [PersistValue])
-> [(SqlExpr (Value Bool), SqlExpr (Value a))]
-> (Builder, [PersistValue])
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (NeedParens
-> IdentInfo
-> (Builder, [PersistValue])
-> (SqlExpr (Value Bool), SqlExpr (Value a))
-> (Builder, [PersistValue])
forall a.
NeedParens
-> IdentInfo
-> (Builder, [PersistValue])
-> (SqlExpr (Value Bool), SqlExpr (Value a))
-> (Builder, [PersistValue])
foldHelp NeedParens
p IdentInfo
info) (Builder
forall a. Monoid a => a
mempty, [PersistValue]
forall a. Monoid a => a
mempty) [(SqlExpr (Value Bool), SqlExpr (Value a))]
when'
foldHelp :: NeedParens -> IdentInfo -> (TLB.Builder, [PersistValue]) -> (SqlExpr (Value Bool), SqlExpr (Value a)) -> (TLB.Builder, [PersistValue])
foldHelp :: forall a.
NeedParens
-> IdentInfo
-> (Builder, [PersistValue])
-> (SqlExpr (Value Bool), SqlExpr (Value a))
-> (Builder, [PersistValue])
foldHelp NeedParens
p IdentInfo
info (Builder
b0, [PersistValue]
vals0) (SqlExpr (Value Bool)
v1, SqlExpr (Value a)
v2) =
let (Builder
b1, [PersistValue]
vals1) = SqlExpr (Value Bool)
-> NeedParens -> IdentInfo -> (Builder, [PersistValue])
forall a.
SqlExpr (Value a)
-> NeedParens -> IdentInfo -> (Builder, [PersistValue])
valueToSql SqlExpr (Value Bool)
v1 NeedParens
p IdentInfo
info
(Builder
b2, [PersistValue]
vals2) = SqlExpr (Value a)
-> NeedParens -> IdentInfo -> (Builder, [PersistValue])
forall a.
SqlExpr (Value a)
-> NeedParens -> IdentInfo -> (Builder, [PersistValue])
valueToSql SqlExpr (Value a)
v2 NeedParens
p IdentInfo
info
in ( Builder
b0 Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" WHEN " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
b1 Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" THEN " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
b2, [PersistValue]
vals0 [PersistValue] -> [PersistValue] -> [PersistValue]
forall a. Semigroup a => a -> a -> a
<> [PersistValue]
vals1 [PersistValue] -> [PersistValue] -> [PersistValue]
forall a. Semigroup a => a -> a -> a
<> [PersistValue]
vals2 )
valueToSql :: SqlExpr (Value a) -> NeedParens -> IdentInfo -> (TLB.Builder, [PersistValue])
valueToSql :: forall a.
SqlExpr (Value a)
-> NeedParens -> IdentInfo -> (Builder, [PersistValue])
valueToSql (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) NeedParens
p = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
p
unsafeSqlBinOp :: TLB.Builder -> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp :: forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
op (ERaw SqlExprMeta
m1 NeedParens -> IdentInfo -> (Builder, [PersistValue])
f1) (ERaw SqlExprMeta
m2 NeedParens -> IdentInfo -> (Builder, [PersistValue])
f2)
| Bool -> Bool
not (SqlExprMeta -> Bool
hasCompositeKeyMeta SqlExprMeta
m1 Bool -> Bool -> Bool
|| SqlExprMeta -> Bool
hasCompositeKeyMeta SqlExprMeta
m2) = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value c)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta NeedParens -> IdentInfo -> (Builder, [PersistValue])
f
where
f :: NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
p IdentInfo
info =
let (Builder
b1, [PersistValue]
vals1) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f1 NeedParens
Parens IdentInfo
info
(Builder
b2, [PersistValue]
vals2) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f2 NeedParens
Parens IdentInfo
info
in
( NeedParens -> Builder -> Builder
parensM NeedParens
p (Builder
b1 Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
op Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
b2)
, [PersistValue]
vals1 [PersistValue] -> [PersistValue] -> [PersistValue]
forall a. Semigroup a => a -> a -> a
<> [PersistValue]
vals2
)
unsafeSqlBinOp Builder
op SqlExpr (Value a)
a SqlExpr (Value b)
b = Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
op (SqlExpr (Value a) -> SqlExpr (Value a)
forall a. SqlExpr (Value a) -> SqlExpr (Value a)
construct SqlExpr (Value a)
a) (SqlExpr (Value b) -> SqlExpr (Value b)
forall a. SqlExpr (Value a) -> SqlExpr (Value a)
construct SqlExpr (Value b)
b)
where
construct :: SqlExpr (Value a) -> SqlExpr (Value a)
construct :: forall a. SqlExpr (Value a) -> SqlExpr (Value a)
construct (ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) =
case SqlExprMeta -> Maybe (IdentInfo -> [Builder])
sqlExprMetaCompositeFields SqlExprMeta
m of
Just IdentInfo -> [Builder]
fields ->
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info -> (Builder -> Builder
parens (Builder -> Builder) -> Builder -> Builder
forall a b. (a -> b) -> a -> b
$ [Builder] -> Builder
uncommas ([Builder] -> Builder) -> [Builder] -> Builder
forall a b. (a -> b) -> a -> b
$ IdentInfo -> [Builder]
fields IdentInfo
info, [PersistValue]
forall a. Monoid a => a
mempty)
Maybe (IdentInfo -> [Builder])
Nothing ->
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a)
forall a b. (a -> b) -> a -> b
$ \NeedParens
p IdentInfo
info ->
let (Builder
b1, [PersistValue]
vals) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f (if NeedParens
p NeedParens -> NeedParens -> Bool
forall a. Eq a => a -> a -> Bool
== NeedParens
Never then NeedParens
Parens else NeedParens
Never) IdentInfo
info
build :: (Builder, [PersistValue]) -> (Builder, [PersistValue])
build (Builder
"?", [PersistList [PersistValue]
vals']) =
([Builder] -> Builder
uncommas ([Builder] -> Builder) -> [Builder] -> Builder
forall a b. (a -> b) -> a -> b
$ Int -> Builder -> [Builder]
forall a. Int -> a -> [a]
replicate ([PersistValue] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [PersistValue]
vals') Builder
"?", [PersistValue]
vals')
build (Builder, [PersistValue])
expr = (Builder, [PersistValue])
expr
in
(Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (NeedParens -> Builder -> Builder
parensM NeedParens
p) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ (Builder, [PersistValue]) -> (Builder, [PersistValue])
build (Builder
b1, [PersistValue]
vals)
{-# INLINE unsafeSqlBinOp #-}
unsafeSqlBinOpComposite :: TLB.Builder -> TLB.Builder -> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOpComposite :: forall a b c.
Builder
-> Builder
-> SqlExpr (Value a)
-> SqlExpr (Value b)
-> SqlExpr (Value c)
unsafeSqlBinOpComposite Builder
op Builder
sep SqlExpr (Value a)
a SqlExpr (Value b)
b
| SqlExpr (Value a) -> Bool
forall x. SqlExpr (Value x) -> Bool
isCompositeKey SqlExpr (Value a)
a Bool -> Bool -> Bool
|| SqlExpr (Value b) -> Bool
forall x. SqlExpr (Value x) -> Bool
isCompositeKey SqlExpr (Value b)
b = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value c)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value c))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value c)
forall a b. (a -> b) -> a -> b
$ (IdentInfo -> (Builder, [PersistValue]))
-> NeedParens -> IdentInfo -> (Builder, [PersistValue])
forall a b. a -> b -> a
const ((IdentInfo -> (Builder, [PersistValue]))
-> NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> (IdentInfo -> (Builder, [PersistValue]))
-> NeedParens
-> IdentInfo
-> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ (IdentInfo -> ([Builder], [PersistValue]))
-> (IdentInfo -> ([Builder], [PersistValue]))
-> IdentInfo
-> (Builder, [PersistValue])
compose (SqlExpr (Value a) -> IdentInfo -> ([Builder], [PersistValue])
forall x.
SqlExpr (Value x) -> IdentInfo -> ([Builder], [PersistValue])
listify SqlExpr (Value a)
a) (SqlExpr (Value b) -> IdentInfo -> ([Builder], [PersistValue])
forall x.
SqlExpr (Value x) -> IdentInfo -> ([Builder], [PersistValue])
listify SqlExpr (Value b)
b)
| Bool
otherwise = Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
forall a b c.
Builder
-> SqlExpr (Value a) -> SqlExpr (Value b) -> SqlExpr (Value c)
unsafeSqlBinOp Builder
op SqlExpr (Value a)
a SqlExpr (Value b)
b
where
isCompositeKey :: SqlExpr (Value x) -> Bool
isCompositeKey :: forall x. SqlExpr (Value x) -> Bool
isCompositeKey (ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
_) = SqlExprMeta -> Bool
hasCompositeKeyMeta SqlExprMeta
m
listify :: SqlExpr (Value x) -> IdentInfo -> ([TLB.Builder], [PersistValue])
listify :: forall x.
SqlExpr (Value x) -> IdentInfo -> ([Builder], [PersistValue])
listify (ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f)
| Just IdentInfo -> [Builder]
k <- SqlExprMeta -> Maybe (IdentInfo -> [Builder])
sqlExprMetaCompositeFields SqlExprMeta
m = ([Builder] -> [PersistValue] -> ([Builder], [PersistValue]))
-> [PersistValue] -> [Builder] -> ([Builder], [PersistValue])
forall a b c. (a -> b -> c) -> b -> a -> c
flip (,) [] ([Builder] -> ([Builder], [PersistValue]))
-> (IdentInfo -> [Builder])
-> IdentInfo
-> ([Builder], [PersistValue])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IdentInfo -> [Builder]
k
| Bool
otherwise = (Builder, [PersistValue]) -> ([Builder], [PersistValue])
deconstruct ((Builder, [PersistValue]) -> ([Builder], [PersistValue]))
-> (IdentInfo -> (Builder, [PersistValue]))
-> IdentInfo
-> ([Builder], [PersistValue])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Parens
deconstruct :: (TLB.Builder, [PersistValue]) -> ([TLB.Builder], [PersistValue])
deconstruct :: (Builder, [PersistValue]) -> ([Builder], [PersistValue])
deconstruct (Builder
"?", [PersistList [PersistValue]
vals]) = (Int -> Builder -> [Builder]
forall a. Int -> a -> [a]
replicate ([PersistValue] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [PersistValue]
vals) Builder
"?", [PersistValue]
vals)
deconstruct (Builder
b', []) = (Text -> Builder
TLB.fromLazyText (Text -> Builder) -> [Text] -> [Builder]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HasCallStack => Text -> Text -> [Text]
Text -> Text -> [Text]
TL.splitOn Text
"," (Builder -> Text
TLB.toLazyText Builder
b'), [])
deconstruct (Builder, [PersistValue])
_ = EsqueletoError -> ([Builder], [PersistValue])
forall a e. Exception e => e -> a
throw (SqlBinOpCompositeError -> EsqueletoError
SqlBinOpCompositeErr SqlBinOpCompositeError
DeconstructionError)
compose :: (IdentInfo -> ([Builder], [PersistValue]))
-> (IdentInfo -> ([Builder], [PersistValue]))
-> IdentInfo
-> (Builder, [PersistValue])
compose IdentInfo -> ([Builder], [PersistValue])
f1 IdentInfo -> ([Builder], [PersistValue])
f2 IdentInfo
info
| Bool -> Bool
not ([PersistValue] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PersistValue]
v1 Bool -> Bool -> Bool
|| [PersistValue] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PersistValue]
v2) = EsqueletoError -> (Builder, [PersistValue])
forall a e. Exception e => e -> a
throw (SqlBinOpCompositeError -> EsqueletoError
SqlBinOpCompositeErr SqlBinOpCompositeError
NullPlaceholdersError)
| [Builder] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Builder]
b1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= [Builder] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Builder]
b2 = EsqueletoError -> (Builder, [PersistValue])
forall a e. Exception e => e -> a
throw (SqlBinOpCompositeError -> EsqueletoError
SqlBinOpCompositeErr SqlBinOpCompositeError
MismatchingLengthsError)
| Bool
otherwise = (Builder
bc, [PersistValue]
vc)
where
([Builder]
b1, [PersistValue]
v1) = IdentInfo -> ([Builder], [PersistValue])
f1 IdentInfo
info
([Builder]
b2, [PersistValue]
v2) = IdentInfo -> ([Builder], [PersistValue])
f2 IdentInfo
info
bc :: Builder
bc = Builder -> [Builder] -> Builder
intersperseB Builder
sep [Builder
x Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
op Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
y | (Builder
x, Builder
y) <- [Builder] -> [Builder] -> [(Builder, Builder)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Builder]
b1 [Builder]
b2]
vc :: [PersistValue]
vc = [PersistValue]
v1 [PersistValue] -> [PersistValue] -> [PersistValue]
forall a. Semigroup a => a -> a -> a
<> [PersistValue]
v2
unsafeSqlValue :: TLB.Builder -> SqlExpr (Value a)
unsafeSqlValue :: forall a. Builder -> SqlExpr (Value a)
unsafeSqlValue Builder
v = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value a)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
_ -> (Builder
v, [PersistValue]
forall a. Monoid a => a
mempty)
{-# INLINE unsafeSqlValue #-}
unsafeSqlEntity :: PersistEntity ent => Ident -> SqlExpr (Entity ent)
unsafeSqlEntity :: forall ent. PersistEntity ent => Ident -> SqlExpr (Entity ent)
unsafeSqlEntity Ident
ident = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Entity ent)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Entity ent))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Entity ent)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info ->
(IdentInfo -> Ident -> Builder
useIdent IdentInfo
info Ident
ident, [])
valueToFunctionArg :: IdentInfo -> SqlExpr (Value a) -> (TLB.Builder, [PersistValue])
valueToFunctionArg :: forall a.
IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue])
valueToFunctionArg IdentInfo
info (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info
unsafeSqlFunction
:: UnsafeSqlFunctionArgument a
=> TLB.Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction :: forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction Builder
name a
arg =
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value b)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value b))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value b)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info ->
let (Builder
argsTLB, [PersistValue]
argsVals) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas' ([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ (SqlExpr (Value ()) -> (Builder, [PersistValue]))
-> [SqlExpr (Value ())] -> [(Builder, [PersistValue])]
forall a b. (a -> b) -> [a] -> [b]
map (IdentInfo -> SqlExpr (Value ()) -> (Builder, [PersistValue])
forall a.
IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue])
valueToFunctionArg IdentInfo
info) ([SqlExpr (Value ())] -> [(Builder, [PersistValue])])
-> [SqlExpr (Value ())] -> [(Builder, [PersistValue])]
forall a b. (a -> b) -> a -> b
$ a -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList a
arg
in
(Builder
name Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parens Builder
argsTLB, [PersistValue]
argsVals)
unsafeSqlExtractSubField
:: UnsafeSqlFunctionArgument a
=> TLB.Builder -> a -> SqlExpr (Value b)
Builder
subField a
arg =
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value b)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value b))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value b)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info ->
let (Builder
argsTLB, [PersistValue]
argsVals) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas' ([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ (SqlExpr (Value ()) -> (Builder, [PersistValue]))
-> [SqlExpr (Value ())] -> [(Builder, [PersistValue])]
forall a b. (a -> b) -> [a] -> [b]
map (IdentInfo -> SqlExpr (Value ()) -> (Builder, [PersistValue])
forall a.
IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue])
valueToFunctionArg IdentInfo
info) ([SqlExpr (Value ())] -> [(Builder, [PersistValue])])
-> [SqlExpr (Value ())] -> [(Builder, [PersistValue])]
forall a b. (a -> b) -> a -> b
$ a -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList a
arg
in
(Builder
"EXTRACT" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parens (Builder
subField Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" FROM " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
argsTLB), [PersistValue]
argsVals)
unsafeSqlFunctionParens
:: UnsafeSqlFunctionArgument a
=> TLB.Builder -> a -> SqlExpr (Value b)
unsafeSqlFunctionParens :: forall a b.
UnsafeSqlFunctionArgument a =>
Builder -> a -> SqlExpr (Value b)
unsafeSqlFunctionParens Builder
name a
arg =
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value b)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value b))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value b)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ IdentInfo
info ->
let valueToFunctionArgParens :: SqlExpr (Value ()) -> (Builder, [PersistValue])
valueToFunctionArgParens (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info
(Builder
argsTLB, [PersistValue]
argsVals) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas' ([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ (SqlExpr (Value ()) -> (Builder, [PersistValue]))
-> [SqlExpr (Value ())] -> [(Builder, [PersistValue])]
forall a b. (a -> b) -> [a] -> [b]
map SqlExpr (Value ()) -> (Builder, [PersistValue])
valueToFunctionArgParens ([SqlExpr (Value ())] -> [(Builder, [PersistValue])])
-> [SqlExpr (Value ())] -> [(Builder, [PersistValue])]
forall a b. (a -> b) -> a -> b
$ a -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList a
arg
in (Builder
name Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parens Builder
argsTLB, [PersistValue]
argsVals)
unsafeSqlCastAs :: T.Text -> SqlExpr (Value a) -> SqlExpr (Value b)
unsafeSqlCastAs :: forall a b. Text -> SqlExpr (Value a) -> SqlExpr (Value b)
unsafeSqlCastAs Text
t (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) = SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value b)
forall a.
SqlExprMeta
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr a
ERaw SqlExprMeta
noMeta ((NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value b))
-> (NeedParens -> IdentInfo -> (Builder, [PersistValue]))
-> SqlExpr (Value b)
forall a b. (a -> b) -> a -> b
$ \NeedParens
_ -> (((Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (\Builder
value -> Builder
"CAST" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parens (Builder
value Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" AS " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
TLB.fromText Text
t))) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (IdentInfo -> (Builder, [PersistValue]))
-> IdentInfo
-> (Builder, [PersistValue])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never)
class UnsafeSqlFunctionArgument a where
toArgList :: a -> [SqlExpr (Value ())]
instance UnsafeSqlFunctionArgument () where
toArgList :: () -> [SqlExpr (Value ())]
toArgList ()
_ = []
instance (a ~ Value b) => UnsafeSqlFunctionArgument (SqlExpr a) where
toArgList :: SqlExpr a -> [SqlExpr (Value ())]
toArgList = (SqlExpr (Value ()) -> [SqlExpr (Value ())] -> [SqlExpr (Value ())]
forall a. a -> [a] -> [a]
:[]) (SqlExpr (Value ()) -> [SqlExpr (Value ())])
-> (SqlExpr a -> SqlExpr (Value ()))
-> SqlExpr a
-> [SqlExpr (Value ())]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlExpr a -> SqlExpr (Value ())
SqlExpr (Value b) -> SqlExpr (Value ())
forall a b. SqlExpr (Value a) -> SqlExpr (Value b)
veryUnsafeCoerceSqlExprValue
instance UnsafeSqlFunctionArgument a => UnsafeSqlFunctionArgument [a] where
toArgList :: [a] -> [SqlExpr (Value ())]
toArgList = (a -> [SqlExpr (Value ())]) -> [a] -> [SqlExpr (Value ())]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap a -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList
instance
(UnsafeSqlFunctionArgument a , UnsafeSqlFunctionArgument b)
=>
UnsafeSqlFunctionArgument (a, b)
where
toArgList :: (a, b) -> [SqlExpr (Value ())]
toArgList (a
a, b
b) = a -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList a
a [SqlExpr (Value ())]
-> [SqlExpr (Value ())] -> [SqlExpr (Value ())]
forall a. [a] -> [a] -> [a]
++ b -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList b
b
instance
( UnsafeSqlFunctionArgument a
, UnsafeSqlFunctionArgument b
, UnsafeSqlFunctionArgument c
)
=>
UnsafeSqlFunctionArgument (a, b, c)
where
toArgList :: (a, b, c) -> [SqlExpr (Value ())]
toArgList = ((a, b), c) -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList (((a, b), c) -> [SqlExpr (Value ())])
-> ((a, b, c) -> ((a, b), c)) -> (a, b, c) -> [SqlExpr (Value ())]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b, c) -> ((a, b), c)
forall a b c. (a, b, c) -> ((a, b), c)
from3
instance
( UnsafeSqlFunctionArgument a
, UnsafeSqlFunctionArgument b
, UnsafeSqlFunctionArgument c
, UnsafeSqlFunctionArgument d
)
=>
UnsafeSqlFunctionArgument (a, b, c, d)
where
toArgList :: (a, b, c, d) -> [SqlExpr (Value ())]
toArgList = ((a, b), (c, d)) -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList (((a, b), (c, d)) -> [SqlExpr (Value ())])
-> ((a, b, c, d) -> ((a, b), (c, d)))
-> (a, b, c, d)
-> [SqlExpr (Value ())]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b, c, d) -> ((a, b), (c, d))
forall a b c d. (a, b, c, d) -> ((a, b), (c, d))
from4
instance
( UnsafeSqlFunctionArgument a
, UnsafeSqlFunctionArgument b
, UnsafeSqlFunctionArgument c
, UnsafeSqlFunctionArgument d
, UnsafeSqlFunctionArgument e
)
=>
UnsafeSqlFunctionArgument (a, b, c, d, e)
where
toArgList :: (a, b, c, d, e) -> [SqlExpr (Value ())]
toArgList = ((a, b), (c, d), e) -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList (((a, b), (c, d), e) -> [SqlExpr (Value ())])
-> ((a, b, c, d, e) -> ((a, b), (c, d), e))
-> (a, b, c, d, e)
-> [SqlExpr (Value ())]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b, c, d, e) -> ((a, b), (c, d), e)
forall a b c d e. (a, b, c, d, e) -> ((a, b), (c, d), e)
from5
instance
( UnsafeSqlFunctionArgument a
, UnsafeSqlFunctionArgument b
, UnsafeSqlFunctionArgument c
, UnsafeSqlFunctionArgument d
, UnsafeSqlFunctionArgument e
, UnsafeSqlFunctionArgument f
)
=>
UnsafeSqlFunctionArgument (a, b, c, d, e, f)
where
toArgList :: (a, b, c, d, e, f) -> [SqlExpr (Value ())]
toArgList = ((a, b), (c, d), (e, f)) -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList (((a, b), (c, d), (e, f)) -> [SqlExpr (Value ())])
-> ((a, b, c, d, e, f) -> ((a, b), (c, d), (e, f)))
-> (a, b, c, d, e, f)
-> [SqlExpr (Value ())]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b, c, d, e, f) -> ((a, b), (c, d), (e, f))
forall a b c d e f. (a, b, c, d, e, f) -> ((a, b), (c, d), (e, f))
from6
instance ( UnsafeSqlFunctionArgument a
, UnsafeSqlFunctionArgument b
, UnsafeSqlFunctionArgument c
, UnsafeSqlFunctionArgument d
, UnsafeSqlFunctionArgument e
, UnsafeSqlFunctionArgument f
, UnsafeSqlFunctionArgument g
) => UnsafeSqlFunctionArgument (a, b, c, d, e, f, g) where
toArgList :: (a, b, c, d, e, f, g) -> [SqlExpr (Value ())]
toArgList = ((a, b), (c, d), (e, f), g) -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList (((a, b), (c, d), (e, f), g) -> [SqlExpr (Value ())])
-> ((a, b, c, d, e, f, g) -> ((a, b), (c, d), (e, f), g))
-> (a, b, c, d, e, f, g)
-> [SqlExpr (Value ())]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b, c, d, e, f, g) -> ((a, b), (c, d), (e, f), g)
forall a b c d e f g.
(a, b, c, d, e, f, g) -> ((a, b), (c, d), (e, f), g)
from7
instance ( UnsafeSqlFunctionArgument a
, UnsafeSqlFunctionArgument b
, UnsafeSqlFunctionArgument c
, UnsafeSqlFunctionArgument d
, UnsafeSqlFunctionArgument e
, UnsafeSqlFunctionArgument f
, UnsafeSqlFunctionArgument g
, UnsafeSqlFunctionArgument h
) => UnsafeSqlFunctionArgument (a, b, c, d, e, f, g, h) where
toArgList :: (a, b, c, d, e, f, g, h) -> [SqlExpr (Value ())]
toArgList = ((a, b), (c, d), (e, f), (g, h)) -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList (((a, b), (c, d), (e, f), (g, h)) -> [SqlExpr (Value ())])
-> ((a, b, c, d, e, f, g, h) -> ((a, b), (c, d), (e, f), (g, h)))
-> (a, b, c, d, e, f, g, h)
-> [SqlExpr (Value ())]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b, c, d, e, f, g, h) -> ((a, b), (c, d), (e, f), (g, h))
forall a b c d e f g h.
(a, b, c, d, e, f, g, h) -> ((a, b), (c, d), (e, f), (g, h))
from8
instance ( UnsafeSqlFunctionArgument a
, UnsafeSqlFunctionArgument b
, UnsafeSqlFunctionArgument c
, UnsafeSqlFunctionArgument d
, UnsafeSqlFunctionArgument e
, UnsafeSqlFunctionArgument f
, UnsafeSqlFunctionArgument g
, UnsafeSqlFunctionArgument h
, UnsafeSqlFunctionArgument i
) => UnsafeSqlFunctionArgument (a, b, c, d, e, f, g, h, i) where
toArgList :: (a, b, c, d, e, f, g, h, i) -> [SqlExpr (Value ())]
toArgList = ((a, b), (c, d), (e, f), (g, h), i) -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList (((a, b), (c, d), (e, f), (g, h), i) -> [SqlExpr (Value ())])
-> ((a, b, c, d, e, f, g, h, i)
-> ((a, b), (c, d), (e, f), (g, h), i))
-> (a, b, c, d, e, f, g, h, i)
-> [SqlExpr (Value ())]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b, c, d, e, f, g, h, i) -> ((a, b), (c, d), (e, f), (g, h), i)
forall a b c d e f g h i.
(a, b, c, d, e, f, g, h, i) -> ((a, b), (c, d), (e, f), (g, h), i)
from9
instance ( UnsafeSqlFunctionArgument a
, UnsafeSqlFunctionArgument b
, UnsafeSqlFunctionArgument c
, UnsafeSqlFunctionArgument d
, UnsafeSqlFunctionArgument e
, UnsafeSqlFunctionArgument f
, UnsafeSqlFunctionArgument g
, UnsafeSqlFunctionArgument h
, UnsafeSqlFunctionArgument i
, UnsafeSqlFunctionArgument j
) => UnsafeSqlFunctionArgument (a, b, c, d, e, f, g, h, i, j) where
toArgList :: (a, b, c, d, e, f, g, h, i, j) -> [SqlExpr (Value ())]
toArgList = ((a, b), (c, d), (e, f), (g, h), (i, j)) -> [SqlExpr (Value ())]
forall a. UnsafeSqlFunctionArgument a => a -> [SqlExpr (Value ())]
toArgList (((a, b), (c, d), (e, f), (g, h), (i, j)) -> [SqlExpr (Value ())])
-> ((a, b, c, d, e, f, g, h, i, j)
-> ((a, b), (c, d), (e, f), (g, h), (i, j)))
-> (a, b, c, d, e, f, g, h, i, j)
-> [SqlExpr (Value ())]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b, c, d, e, f, g, h, i, j)
-> ((a, b), (c, d), (e, f), (g, h), (i, j))
forall a b c d e f g h i j.
(a, b, c, d, e, f, g, h, i, j)
-> ((a, b), (c, d), (e, f), (g, h), (i, j))
from10
veryUnsafeCoerceSqlExprValue :: SqlExpr (Value a) -> SqlExpr (Value b)
veryUnsafeCoerceSqlExprValue :: forall a b. SqlExpr (Value a) -> SqlExpr (Value b)
veryUnsafeCoerceSqlExprValue = SqlExpr (Value a) -> SqlExpr (Value b)
forall a b. Coercible a b => a -> b
coerce
veryUnsafeCoerceSqlExprValueList :: SqlExpr (ValueList a) -> SqlExpr (Value a)
veryUnsafeCoerceSqlExprValueList :: forall a. SqlExpr (ValueList a) -> SqlExpr (Value a)
veryUnsafeCoerceSqlExprValueList = SqlExpr (ValueList a) -> SqlExpr (Value a)
forall a b. Coercible a b => a -> b
coerce
rawSelectSource
::
( SqlSelect a r
, MonadIO m1
, MonadIO m2
, SqlBackendCanRead backend
)
=> Mode
-> SqlQuery a
-> R.ReaderT backend m1 (Acquire (C.ConduitT () r m2 ()))
rawSelectSource :: forall a r (m1 :: * -> *) (m2 :: * -> *) backend.
(SqlSelect a r, MonadIO m1, MonadIO m2,
SqlBackendCanRead backend) =>
Mode
-> SqlQuery a -> ReaderT backend m1 (Acquire (ConduitT () r m2 ()))
rawSelectSource Mode
mode SqlQuery a
query = do
SqlBackend
conn <- backend -> SqlBackend
forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend (backend -> SqlBackend)
-> ReaderT backend m1 backend -> ReaderT backend m1 SqlBackend
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT backend m1 backend
forall (m :: * -> *) r. Monad m => ReaderT r m r
R.ask
let SqlBackend
_ = SqlBackend
conn :: SqlBackend
Acquire (ConduitM () [PersistValue] m2 ())
res <- (backend -> SqlBackend)
-> ReaderT
SqlBackend m1 (Acquire (ConduitM () [PersistValue] m2 ()))
-> ReaderT backend m1 (Acquire (ConduitM () [PersistValue] m2 ()))
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
R.withReaderT (SqlBackend -> backend -> SqlBackend
forall a b. a -> b -> a
const SqlBackend
conn) (SqlBackend
-> ReaderT
SqlBackend m1 (Acquire (ConduitM () [PersistValue] m2 ()))
run SqlBackend
conn)
Acquire (ConduitT () r m2 ())
-> ReaderT backend m1 (Acquire (ConduitT () r m2 ()))
forall a. a -> ReaderT backend m1 a
forall (m :: * -> *) a. Monad m => a -> m a
return (Acquire (ConduitT () r m2 ())
-> ReaderT backend m1 (Acquire (ConduitT () r m2 ())))
-> Acquire (ConduitT () r m2 ())
-> ReaderT backend m1 (Acquire (ConduitT () r m2 ()))
forall a b. (a -> b) -> a -> b
$ (ConduitM () [PersistValue] m2 ()
-> ConduitT [PersistValue] r m2 () -> ConduitT () r m2 ()
forall (m :: * -> *) a b c r.
Monad m =>
ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
C..| ConduitT [PersistValue] r m2 ()
massage) (ConduitM () [PersistValue] m2 () -> ConduitT () r m2 ())
-> Acquire (ConduitM () [PersistValue] m2 ())
-> Acquire (ConduitT () r m2 ())
forall a b. (a -> b) -> Acquire a -> Acquire b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Acquire (ConduitM () [PersistValue] m2 ())
res
where
run :: SqlBackend
-> ReaderT
SqlBackend m1 (Acquire (ConduitM () [PersistValue] m2 ()))
run SqlBackend
conn =
(Text
-> [PersistValue]
-> ReaderT
SqlBackend m1 (Acquire (ConduitM () [PersistValue] m2 ())))
-> (Text, [PersistValue])
-> ReaderT
SqlBackend m1 (Acquire (ConduitM () [PersistValue] m2 ()))
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Text
-> [PersistValue]
-> ReaderT
SqlBackend m1 (Acquire (ConduitM () [PersistValue] m2 ()))
forall (m1 :: * -> *) (m2 :: * -> *) env.
(MonadIO m1, MonadIO m2, BackendCompatible SqlBackend env) =>
Text
-> [PersistValue]
-> ReaderT env m1 (Acquire (ConduitM () [PersistValue] m2 ()))
rawQueryRes ((Text, [PersistValue])
-> ReaderT
SqlBackend m1 (Acquire (ConduitM () [PersistValue] m2 ())))
-> (Text, [PersistValue])
-> ReaderT
SqlBackend m1 (Acquire (ConduitM () [PersistValue] m2 ()))
forall a b. (a -> b) -> a -> b
$
(Builder -> Text)
-> (Builder, [PersistValue]) -> (Text, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Builder -> Text
builderToText ((Builder, [PersistValue]) -> (Text, [PersistValue]))
-> (Builder, [PersistValue]) -> (Text, [PersistValue])
forall a b. (a -> b) -> a -> b
$
Mode -> IdentInfo -> SqlQuery a -> (Builder, [PersistValue])
forall a r backend.
(SqlSelect a r, BackendCompatible SqlBackend backend) =>
Mode
-> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])
toRawSql Mode
mode (SqlBackend
conn, IdentState
initialIdentState) SqlQuery a
query
massage :: ConduitT [PersistValue] r m2 ()
massage = do
Maybe [PersistValue]
mrow <- ConduitT [PersistValue] r m2 (Maybe [PersistValue])
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
C.await
case [PersistValue] -> Either Text r
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow ([PersistValue] -> Either Text r)
-> Maybe [PersistValue] -> Maybe (Either Text r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe [PersistValue]
mrow of
Just (Right r
r) -> r -> ConduitT [PersistValue] r m2 ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
C.yield r
r ConduitT [PersistValue] r m2 ()
-> ConduitT [PersistValue] r m2 ()
-> ConduitT [PersistValue] r m2 ()
forall a b.
ConduitT [PersistValue] r m2 a
-> ConduitT [PersistValue] r m2 b -> ConduitT [PersistValue] r m2 b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitT [PersistValue] r m2 ()
massage
Just (Left Text
err) -> IO () -> ConduitT [PersistValue] r m2 ()
forall a. IO a -> ConduitT [PersistValue] r m2 a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ConduitT [PersistValue] r m2 ())
-> IO () -> ConduitT [PersistValue] r m2 ()
forall a b. (a -> b) -> a -> b
$ PersistException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (PersistException -> IO ()) -> PersistException -> IO ()
forall a b. (a -> b) -> a -> b
$ Text -> PersistException
PersistMarshalError Text
err
Maybe (Either Text r)
Nothing -> () -> ConduitT [PersistValue] r m2 ()
forall a. a -> ConduitT [PersistValue] r m2 a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
selectSource
::
( SqlSelect a r
, BackendCompatible SqlBackend backend
, IsPersistBackend backend
, PersistQueryRead backend
, PersistStoreRead backend, PersistUniqueRead backend
, MonadResource m
)
=> SqlQuery a
-> C.ConduitT () r (R.ReaderT backend m) ()
selectSource :: forall a r backend (m :: * -> *).
(SqlSelect a r, BackendCompatible SqlBackend backend,
IsPersistBackend backend, PersistQueryRead backend,
PersistStoreRead backend, PersistUniqueRead backend,
MonadResource m) =>
SqlQuery a -> ConduitT () r (ReaderT backend m) ()
selectSource SqlQuery a
query = do
Acquire (ConduitT () r (ReaderT backend m) ())
res <- ReaderT backend m (Acquire (ConduitT () r (ReaderT backend m) ()))
-> ConduitT
()
r
(ReaderT backend m)
(Acquire (ConduitT () r (ReaderT backend m) ()))
forall (m :: * -> *) a. Monad m => m a -> ConduitT () r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT backend m (Acquire (ConduitT () r (ReaderT backend m) ()))
-> ConduitT
()
r
(ReaderT backend m)
(Acquire (ConduitT () r (ReaderT backend m) ())))
-> ReaderT
backend m (Acquire (ConduitT () r (ReaderT backend m) ()))
-> ConduitT
()
r
(ReaderT backend m)
(Acquire (ConduitT () r (ReaderT backend m) ()))
forall a b. (a -> b) -> a -> b
$ Mode
-> SqlQuery a
-> ReaderT
backend m (Acquire (ConduitT () r (ReaderT backend m) ()))
forall a r (m1 :: * -> *) (m2 :: * -> *) backend.
(SqlSelect a r, MonadIO m1, MonadIO m2,
SqlBackendCanRead backend) =>
Mode
-> SqlQuery a -> ReaderT backend m1 (Acquire (ConduitT () r m2 ()))
rawSelectSource Mode
SELECT SqlQuery a
query
(ReleaseKey
key, ConduitT () r (ReaderT backend m) ()
src) <- ReaderT
backend m (ReleaseKey, ConduitT () r (ReaderT backend m) ())
-> ConduitT
()
r
(ReaderT backend m)
(ReleaseKey, ConduitT () r (ReaderT backend m) ())
forall (m :: * -> *) a. Monad m => m a -> ConduitT () r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT
backend m (ReleaseKey, ConduitT () r (ReaderT backend m) ())
-> ConduitT
()
r
(ReaderT backend m)
(ReleaseKey, ConduitT () r (ReaderT backend m) ()))
-> ReaderT
backend m (ReleaseKey, ConduitT () r (ReaderT backend m) ())
-> ConduitT
()
r
(ReaderT backend m)
(ReleaseKey, ConduitT () r (ReaderT backend m) ())
forall a b. (a -> b) -> a -> b
$ Acquire (ConduitT () r (ReaderT backend m) ())
-> ReaderT
backend m (ReleaseKey, ConduitT () r (ReaderT backend m) ())
forall (m :: * -> *) a.
MonadResource m =>
Acquire a -> m (ReleaseKey, a)
allocateAcquire Acquire (ConduitT () r (ReaderT backend m) ())
res
ConduitT () r (ReaderT backend m) ()
src
ReaderT backend m () -> ConduitT () r (ReaderT backend m) ()
forall (m :: * -> *) a. Monad m => m a -> ConduitT () r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT backend m () -> ConduitT () r (ReaderT backend m) ())
-> ReaderT backend m () -> ConduitT () r (ReaderT backend m) ()
forall a b. (a -> b) -> a -> b
$ ReleaseKey -> ReaderT backend m ()
forall (m :: * -> *). MonadIO m => ReleaseKey -> m ()
release ReleaseKey
key
select
::
( SqlSelect a r
, MonadIO m
, SqlBackendCanRead backend
)
=> SqlQuery a
-> R.ReaderT backend m [r]
select :: forall a r (m :: * -> *) backend.
(SqlSelect a r, MonadIO m, SqlBackendCanRead backend) =>
SqlQuery a -> ReaderT backend m [r]
select SqlQuery a
query = do
Acquire (ConduitT () r (ReaderT backend IO) ())
res <- Mode
-> SqlQuery a
-> ReaderT
backend m (Acquire (ConduitT () r (ReaderT backend IO) ()))
forall a r (m1 :: * -> *) (m2 :: * -> *) backend.
(SqlSelect a r, MonadIO m1, MonadIO m2,
SqlBackendCanRead backend) =>
Mode
-> SqlQuery a -> ReaderT backend m1 (Acquire (ConduitT () r m2 ()))
rawSelectSource Mode
SELECT SqlQuery a
query
backend
conn <- ReaderT backend m backend
forall (m :: * -> *) r. Monad m => ReaderT r m r
R.ask
IO [r] -> ReaderT backend m [r]
forall a. IO a -> ReaderT backend m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [r] -> ReaderT backend m [r])
-> IO [r] -> ReaderT backend m [r]
forall a b. (a -> b) -> a -> b
$ Acquire (ConduitT () r (ReaderT backend IO) ())
-> (ConduitT () r (ReaderT backend IO) () -> IO [r]) -> IO [r]
forall (m :: * -> *) a b.
MonadUnliftIO m =>
Acquire a -> (a -> m b) -> m b
with Acquire (ConduitT () r (ReaderT backend IO) ())
res ((ConduitT () r (ReaderT backend IO) () -> IO [r]) -> IO [r])
-> (ConduitT () r (ReaderT backend IO) () -> IO [r]) -> IO [r]
forall a b. (a -> b) -> a -> b
$ (ReaderT backend IO [r] -> backend -> IO [r])
-> backend -> ReaderT backend IO [r] -> IO [r]
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT backend IO [r] -> backend -> IO [r]
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
R.runReaderT backend
conn (ReaderT backend IO [r] -> IO [r])
-> (ConduitT () r (ReaderT backend IO) ()
-> ReaderT backend IO [r])
-> ConduitT () r (ReaderT backend IO) ()
-> IO [r]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConduitT () r (ReaderT backend IO) () -> ReaderT backend IO [r]
forall (m :: * -> *) r backend.
Monad m =>
ConduitT () r (ReaderT backend m) () -> ReaderT backend m [r]
runSource
selectOne :: (SqlSelect a r, MonadIO m, SqlBackendCanRead backend) => SqlQuery a -> R.ReaderT backend m (Maybe r)
selectOne :: forall a r (m :: * -> *) backend.
(SqlSelect a r, MonadIO m, SqlBackendCanRead backend) =>
SqlQuery a -> ReaderT backend m (Maybe r)
selectOne SqlQuery a
query = ([r] -> Maybe r)
-> ReaderT backend m [r] -> ReaderT backend m (Maybe r)
forall a b. (a -> b) -> ReaderT backend m a -> ReaderT backend m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [r] -> Maybe r
forall a. [a] -> Maybe a
Maybe.listToMaybe (ReaderT backend m [r] -> ReaderT backend m (Maybe r))
-> ReaderT backend m [r] -> ReaderT backend m (Maybe r)
forall a b. (a -> b) -> a -> b
$ SqlQuery a -> ReaderT backend m [r]
forall a r (m :: * -> *) backend.
(SqlSelect a r, MonadIO m, SqlBackendCanRead backend) =>
SqlQuery a -> ReaderT backend m [r]
select (SqlQuery a -> ReaderT backend m [r])
-> SqlQuery a -> ReaderT backend m [r]
forall a b. (a -> b) -> a -> b
$ Int64 -> SqlQuery ()
limit Int64
1 SqlQuery () -> SqlQuery a -> SqlQuery a
forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SqlQuery a
query
runSource
:: Monad m
=> C.ConduitT () r (R.ReaderT backend m) ()
-> R.ReaderT backend m [r]
runSource :: forall (m :: * -> *) r backend.
Monad m =>
ConduitT () r (ReaderT backend m) () -> ReaderT backend m [r]
runSource ConduitT () r (ReaderT backend m) ()
src = ConduitT () Void (ReaderT backend m) [r] -> ReaderT backend m [r]
forall (m :: * -> *) r. Monad m => ConduitT () Void m r -> m r
C.runConduit (ConduitT () Void (ReaderT backend m) [r] -> ReaderT backend m [r])
-> ConduitT () Void (ReaderT backend m) [r]
-> ReaderT backend m [r]
forall a b. (a -> b) -> a -> b
$ ConduitT () r (ReaderT backend m) ()
src ConduitT () r (ReaderT backend m) ()
-> ConduitT r Void (ReaderT backend m) [r]
-> ConduitT () Void (ReaderT backend m) [r]
forall (m :: * -> *) a b c r.
Monad m =>
ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
C..| ConduitT r Void (ReaderT backend m) [r]
forall (m :: * -> *) a o. Monad m => ConduitT a o m [a]
CL.consume
rawEsqueleto
:: (MonadIO m, SqlSelect a r, BackendCompatible SqlBackend backend)
=> Mode
-> SqlQuery a
-> R.ReaderT backend m Int64
rawEsqueleto :: forall (m :: * -> *) a r backend.
(MonadIO m, SqlSelect a r, BackendCompatible SqlBackend backend) =>
Mode -> SqlQuery a -> ReaderT backend m Int64
rawEsqueleto Mode
mode SqlQuery a
query = do
backend
conn <- ReaderT backend m backend
forall (m :: * -> *) r. Monad m => ReaderT r m r
R.ask
(Text -> [PersistValue] -> ReaderT backend m Int64)
-> (Text, [PersistValue]) -> ReaderT backend m Int64
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Text -> [PersistValue] -> ReaderT backend m Int64
forall (m :: * -> *) backend.
(MonadIO m, BackendCompatible SqlBackend backend) =>
Text -> [PersistValue] -> ReaderT backend m Int64
rawExecuteCount ((Text, [PersistValue]) -> ReaderT backend m Int64)
-> (Text, [PersistValue]) -> ReaderT backend m Int64
forall a b. (a -> b) -> a -> b
$
(Builder -> Text)
-> (Builder, [PersistValue]) -> (Text, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Builder -> Text
builderToText ((Builder, [PersistValue]) -> (Text, [PersistValue]))
-> (Builder, [PersistValue]) -> (Text, [PersistValue])
forall a b. (a -> b) -> a -> b
$
Mode
-> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])
forall a r backend.
(SqlSelect a r, BackendCompatible SqlBackend backend) =>
Mode
-> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])
toRawSql Mode
mode (backend
conn, IdentState
initialIdentState) SqlQuery a
query
delete
:: (MonadIO m, SqlBackendCanWrite backend)
=> SqlQuery ()
-> R.ReaderT backend m ()
delete :: forall (m :: * -> *) backend.
(MonadIO m, SqlBackendCanWrite backend) =>
SqlQuery () -> ReaderT backend m ()
delete SqlQuery ()
a = ReaderT backend m Int64 -> ReaderT backend m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ReaderT backend m Int64 -> ReaderT backend m ())
-> ReaderT backend m Int64 -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ SqlQuery () -> ReaderT backend m Int64
forall (m :: * -> *) backend.
(MonadIO m, SqlBackendCanWrite backend) =>
SqlQuery () -> ReaderT backend m Int64
deleteCount SqlQuery ()
a
deleteCount
:: (MonadIO m, SqlBackendCanWrite backend)
=> SqlQuery ()
-> R.ReaderT backend m Int64
deleteCount :: forall (m :: * -> *) backend.
(MonadIO m, SqlBackendCanWrite backend) =>
SqlQuery () -> ReaderT backend m Int64
deleteCount SqlQuery ()
a = Mode -> SqlQuery () -> ReaderT backend m Int64
forall (m :: * -> *) a r backend.
(MonadIO m, SqlSelect a r, BackendCompatible SqlBackend backend) =>
Mode -> SqlQuery a -> ReaderT backend m Int64
rawEsqueleto Mode
DELETE SqlQuery ()
a
update
::
( MonadIO m, PersistEntity val
, BackendCompatible SqlBackend (PersistEntityBackend val)
, SqlBackendCanWrite backend
)
=> (SqlExpr (Entity val) -> SqlQuery ())
-> R.ReaderT backend m ()
update :: forall (m :: * -> *) val backend.
(MonadIO m, PersistEntity val,
BackendCompatible SqlBackend (PersistEntityBackend val),
SqlBackendCanWrite backend) =>
(SqlExpr (Entity val) -> SqlQuery ()) -> ReaderT backend m ()
update SqlExpr (Entity val) -> SqlQuery ()
a = ReaderT backend m Int64 -> ReaderT backend m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ReaderT backend m Int64 -> ReaderT backend m ())
-> ReaderT backend m Int64 -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ (SqlExpr (Entity val) -> SqlQuery ()) -> ReaderT backend m Int64
forall (m :: * -> *) val backend.
(MonadIO m, PersistEntity val,
BackendCompatible SqlBackend (PersistEntityBackend val),
SqlBackendCanWrite backend) =>
(SqlExpr (Entity val) -> SqlQuery ()) -> ReaderT backend m Int64
updateCount SqlExpr (Entity val) -> SqlQuery ()
a
updateCount
::
( MonadIO m, PersistEntity val
, BackendCompatible SqlBackend (PersistEntityBackend val)
, SqlBackendCanWrite backend
)
=> (SqlExpr (Entity val) -> SqlQuery ())
-> R.ReaderT backend m Int64
updateCount :: forall (m :: * -> *) val backend.
(MonadIO m, PersistEntity val,
BackendCompatible SqlBackend (PersistEntityBackend val),
SqlBackendCanWrite backend) =>
(SqlExpr (Entity val) -> SqlQuery ()) -> ReaderT backend m Int64
updateCount SqlExpr (Entity val) -> SqlQuery ()
a = Mode -> SqlQuery () -> ReaderT backend m Int64
forall (m :: * -> *) a r backend.
(MonadIO m, SqlSelect a r, BackendCompatible SqlBackend backend) =>
Mode -> SqlQuery a -> ReaderT backend m Int64
rawEsqueleto Mode
UPDATE (SqlQuery () -> ReaderT backend m Int64)
-> SqlQuery () -> ReaderT backend m Int64
forall a b. (a -> b) -> a -> b
$ (SqlExpr (Entity val) -> SqlQuery ()) -> SqlQuery ()
forall a b. From a => (a -> SqlQuery b) -> SqlQuery b
from SqlExpr (Entity val) -> SqlQuery ()
a
builderToText :: TLB.Builder -> T.Text
builderToText :: Builder -> Text
builderToText = Text -> Text
TL.toStrict (Text -> Text) -> (Builder -> Text) -> Builder -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Builder -> Text
TLB.toLazyTextWith Int
defaultChunkSize
where
defaultChunkSize :: Int
defaultChunkSize :: Int
defaultChunkSize = Int
1024 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
32
toRawSql
:: (SqlSelect a r, BackendCompatible SqlBackend backend)
=> Mode -> (backend, IdentState) -> SqlQuery a -> (TLB.Builder, [PersistValue])
toRawSql :: forall a r backend.
(SqlSelect a r, BackendCompatible SqlBackend backend) =>
Mode
-> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])
toRawSql Mode
mode (backend
conn, IdentState
firstIdentState) SqlQuery a
query =
let ((a
ret, SideData
sd), IdentState
finalIdentState) =
(State IdentState (a, SideData)
-> IdentState -> ((a, SideData), IdentState))
-> IdentState
-> State IdentState (a, SideData)
-> ((a, SideData), IdentState)
forall a b c. (a -> b -> c) -> b -> a -> c
flip State IdentState (a, SideData)
-> IdentState -> ((a, SideData), IdentState)
forall s a. State s a -> s -> (a, s)
S.runState IdentState
firstIdentState (State IdentState (a, SideData) -> ((a, SideData), IdentState))
-> State IdentState (a, SideData) -> ((a, SideData), IdentState)
forall a b. (a -> b) -> a -> b
$
WriterT SideData (StateT IdentState Identity) a
-> State IdentState (a, SideData)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
W.runWriterT (WriterT SideData (StateT IdentState Identity) a
-> State IdentState (a, SideData))
-> WriterT SideData (StateT IdentState Identity) a
-> State IdentState (a, SideData)
forall a b. (a -> b) -> a -> b
$
SqlQuery a -> WriterT SideData (StateT IdentState Identity) a
forall a.
SqlQuery a -> WriterT SideData (StateT IdentState Identity) a
unQ SqlQuery a
query
deleteRepeatedNewlines :: Text -> Text
deleteRepeatedNewlines Text
txt =
let
(Text
preNewlines, Text
rest) = (Char -> Bool) -> Text -> (Text, Text)
TL.break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\n') Text
txt
(Text
_, Text
rest') = (Char -> Bool) -> Text -> (Text, Text)
TL.break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\n') Text
rest
in
if Text -> Bool
TL.null Text
rest'
then Text
preNewlines Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"
else Text
preNewlines Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
deleteRepeatedNewlines Text
rest'
SideData DistinctClause
distinctClause
[FromClause]
fromClauses
[SetClause]
setClauses
WhereClause
whereClauses
GroupByClause
groupByClause
WhereClause
havingClause
[SqlExpr OrderBy]
orderByClauses
LimitClause
limitClause
LockingClause
lockingClause
[CommonTableExpressionClause]
cteClause = SideData
sd
info :: IdentInfo
info = (backend -> SqlBackend
forall sup sub. BackendCompatible sup sub => sub -> sup
projectBackend backend
conn, IdentState
finalIdentState)
in (\(Builder
x, [PersistValue]
t) -> (Text -> Builder
TLB.fromLazyText (Text -> Builder) -> Text -> Builder
forall a b. (a -> b) -> a -> b
$ Text -> Text
deleteRepeatedNewlines (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text
TL.strip (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Builder -> Text
TLB.toLazyText Builder
x, [PersistValue]
t)) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [a] -> a
mconcat ([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ (Builder, [PersistValue])
-> [(Builder, [PersistValue])] -> [(Builder, [PersistValue])]
forall a. a -> [a] -> [a]
intersperse (Builder
"\n", [])
[ IdentInfo
-> [CommonTableExpressionClause] -> (Builder, [PersistValue])
makeCte IdentInfo
info [CommonTableExpressionClause]
cteClause
, IdentInfo -> Mode -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> Mode -> a -> (Builder, [PersistValue])
makeInsertInto IdentInfo
info Mode
mode a
ret
, IdentInfo
-> Mode -> DistinctClause -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo
-> Mode -> DistinctClause -> a -> (Builder, [PersistValue])
makeSelect IdentInfo
info Mode
mode DistinctClause
distinctClause a
ret
, IdentInfo -> Mode -> [FromClause] -> (Builder, [PersistValue])
makeFrom IdentInfo
info Mode
mode [FromClause]
fromClauses
, IdentInfo -> [SetClause] -> (Builder, [PersistValue])
makeSet IdentInfo
info [SetClause]
setClauses
, IdentInfo -> WhereClause -> (Builder, [PersistValue])
makeWhere IdentInfo
info WhereClause
whereClauses
, IdentInfo -> GroupByClause -> (Builder, [PersistValue])
makeGroupBy IdentInfo
info GroupByClause
groupByClause
, IdentInfo -> WhereClause -> (Builder, [PersistValue])
makeHaving IdentInfo
info WhereClause
havingClause
, IdentInfo -> [SqlExpr OrderBy] -> (Builder, [PersistValue])
makeOrderBy IdentInfo
info [SqlExpr OrderBy]
orderByClauses
, IdentInfo -> LimitClause -> (Builder, [PersistValue])
makeLimit IdentInfo
info LimitClause
limitClause
, IdentInfo -> LockingClause -> (Builder, [PersistValue])
makeLocking IdentInfo
info LockingClause
lockingClause
]
renderQueryToText
:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m)
=> Mode
-> SqlQuery a
-> R.ReaderT backend m (T.Text, [PersistValue])
renderQueryToText :: forall a r backend (m :: * -> *).
(SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) =>
Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])
renderQueryToText Mode
mode SqlQuery a
query = do
backend
backend <- ReaderT backend m backend
forall (m :: * -> *) r. Monad m => ReaderT r m r
R.ask
let (Builder
builder, [PersistValue]
pvals) = Mode
-> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])
forall a r backend.
(SqlSelect a r, BackendCompatible SqlBackend backend) =>
Mode
-> (backend, IdentState) -> SqlQuery a -> (Builder, [PersistValue])
toRawSql Mode
mode (backend
backend, IdentState
initialIdentState) SqlQuery a
query
(Text, [PersistValue]) -> ReaderT backend m (Text, [PersistValue])
forall a. a -> ReaderT backend m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Builder -> Text
builderToText Builder
builder, [PersistValue]
pvals)
renderQuerySelect
:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m)
=> SqlQuery a
-> R.ReaderT backend m (T.Text, [PersistValue])
renderQuerySelect :: forall a r backend (m :: * -> *).
(SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) =>
SqlQuery a -> ReaderT backend m (Text, [PersistValue])
renderQuerySelect = Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])
forall a r backend (m :: * -> *).
(SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) =>
Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])
renderQueryToText Mode
SELECT
renderQueryDelete
:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m)
=> SqlQuery a
-> R.ReaderT backend m (T.Text, [PersistValue])
renderQueryDelete :: forall a r backend (m :: * -> *).
(SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) =>
SqlQuery a -> ReaderT backend m (Text, [PersistValue])
renderQueryDelete = Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])
forall a r backend (m :: * -> *).
(SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) =>
Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])
renderQueryToText Mode
DELETE
renderQueryUpdate
:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m)
=> SqlQuery a
-> R.ReaderT backend m (T.Text, [PersistValue])
renderQueryUpdate :: forall a r backend (m :: * -> *).
(SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) =>
SqlQuery a -> ReaderT backend m (Text, [PersistValue])
renderQueryUpdate = Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])
forall a r backend (m :: * -> *).
(SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) =>
Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])
renderQueryToText Mode
UPDATE
renderQueryInsertInto
:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m)
=> SqlQuery a
-> R.ReaderT backend m (T.Text, [PersistValue])
renderQueryInsertInto :: forall a r backend (m :: * -> *).
(SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) =>
SqlQuery a -> ReaderT backend m (Text, [PersistValue])
renderQueryInsertInto = Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])
forall a r backend (m :: * -> *).
(SqlSelect a r, BackendCompatible SqlBackend backend, Monad m) =>
Mode -> SqlQuery a -> ReaderT backend m (Text, [PersistValue])
renderQueryToText Mode
INSERT_INTO
data Mode
= SELECT
| DELETE
| UPDATE
| INSERT_INTO
uncommas :: [TLB.Builder] -> TLB.Builder
uncommas :: [Builder] -> Builder
uncommas = Builder -> [Builder] -> Builder
intersperseB Builder
", "
intersperseB :: TLB.Builder -> [TLB.Builder] -> TLB.Builder
intersperseB :: Builder -> [Builder] -> Builder
intersperseB Builder
a = [Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ([Builder] -> Builder)
-> ([Builder] -> [Builder]) -> [Builder] -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> [Builder] -> [Builder]
forall a. a -> [a] -> [a]
intersperse Builder
a ([Builder] -> [Builder])
-> ([Builder] -> [Builder]) -> [Builder] -> [Builder]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Builder -> Bool) -> [Builder] -> [Builder]
forall a. (a -> Bool) -> [a] -> [a]
filter (Builder -> Builder -> Bool
forall a. Eq a => a -> a -> Bool
/= Builder
forall a. Monoid a => a
mempty)
uncommas' :: Monoid a => [(TLB.Builder, a)] -> (TLB.Builder, a)
uncommas' :: forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas' = ([Builder] -> Builder
uncommas ([Builder] -> Builder)
-> ([a] -> a) -> ([Builder], [a]) -> (Builder, a)
forall b c b' c'. (b -> c) -> (b' -> c') -> (b, b') -> (c, c')
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** [a] -> a
forall a. Monoid a => [a] -> a
mconcat) (([Builder], [a]) -> (Builder, a))
-> ([(Builder, a)] -> ([Builder], [a]))
-> [(Builder, a)]
-> (Builder, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Builder, a)] -> ([Builder], [a])
forall a b. [(a, b)] -> ([a], [b])
unzip
makeCte :: IdentInfo -> [CommonTableExpressionClause] -> (TLB.Builder, [PersistValue])
makeCte :: IdentInfo
-> [CommonTableExpressionClause] -> (Builder, [PersistValue])
makeCte IdentInfo
info [CommonTableExpressionClause]
cteClauses =
let
withCteText :: Builder
withCteText
| Bool
hasRecursive = Builder
"WITH RECURSIVE "
| Bool
otherwise = Builder
"WITH "
where
hasRecursive :: Bool
hasRecursive =
CommonTableExpressionKind -> [CommonTableExpressionKind] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem CommonTableExpressionKind
RecursiveCommonTableExpression
([CommonTableExpressionKind] -> Bool)
-> [CommonTableExpressionKind] -> Bool
forall a b. (a -> b) -> a -> b
$ (CommonTableExpressionClause -> CommonTableExpressionKind)
-> [CommonTableExpressionClause] -> [CommonTableExpressionKind]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(CommonTableExpressionClause CommonTableExpressionKind
cteKind Ident
_ IdentInfo -> (Builder, [PersistValue])
_) -> CommonTableExpressionKind
cteKind)
([CommonTableExpressionClause] -> [CommonTableExpressionKind])
-> [CommonTableExpressionClause] -> [CommonTableExpressionKind]
forall a b. (a -> b) -> a -> b
$ [CommonTableExpressionClause]
cteClauses
cteClauseToText :: CommonTableExpressionClause -> (Builder, [PersistValue])
cteClauseToText (CommonTableExpressionClause CommonTableExpressionKind
_ Ident
cteIdent IdentInfo -> (Builder, [PersistValue])
cteFn) =
(Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first
(\Builder
tlb -> IdentInfo -> Ident -> Builder
useIdent IdentInfo
info Ident
cteIdent Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" AS " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parens Builder
tlb)
(IdentInfo -> (Builder, [PersistValue])
cteFn IdentInfo
info)
cteBody :: (Builder, [PersistValue])
cteBody =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [a] -> a
mconcat
([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ (Builder, [PersistValue])
-> [(Builder, [PersistValue])] -> [(Builder, [PersistValue])]
forall a. a -> [a] -> [a]
intersperse (Builder
",\n", [PersistValue]
forall a. Monoid a => a
mempty)
([(Builder, [PersistValue])] -> [(Builder, [PersistValue])])
-> [(Builder, [PersistValue])] -> [(Builder, [PersistValue])]
forall a b. (a -> b) -> a -> b
$ (CommonTableExpressionClause -> (Builder, [PersistValue]))
-> [CommonTableExpressionClause] -> [(Builder, [PersistValue])]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CommonTableExpressionClause -> (Builder, [PersistValue])
cteClauseToText [CommonTableExpressionClause]
cteClauses
in
case [CommonTableExpressionClause]
cteClauses of
[] ->
(Builder, [PersistValue])
forall a. Monoid a => a
mempty
[CommonTableExpressionClause]
_ ->
(Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (\Builder
tlb -> Builder
withCteText Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
tlb Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n") (Builder, [PersistValue])
cteBody
makeInsertInto :: SqlSelect a r => IdentInfo -> Mode -> a -> (TLB.Builder, [PersistValue])
makeInsertInto :: forall a r.
SqlSelect a r =>
IdentInfo -> Mode -> a -> (Builder, [PersistValue])
makeInsertInto IdentInfo
info Mode
INSERT_INTO a
ret = IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlInsertInto IdentInfo
info a
ret
makeInsertInto IdentInfo
_ Mode
_ a
_ = (Builder, [PersistValue])
forall a. Monoid a => a
mempty
makeSelect :: SqlSelect a r => IdentInfo -> Mode -> DistinctClause -> a -> (TLB.Builder, [PersistValue])
makeSelect :: forall a r.
SqlSelect a r =>
IdentInfo
-> Mode -> DistinctClause -> a -> (Builder, [PersistValue])
makeSelect IdentInfo
info Mode
mode_ DistinctClause
distinctClause a
ret = Mode -> (Builder, [PersistValue])
process Mode
mode_
where
process :: Mode -> (Builder, [PersistValue])
process Mode
mode =
case Mode
mode of
Mode
SELECT -> (Builder, [PersistValue]) -> (Builder, [PersistValue])
withCols (Builder, [PersistValue])
selectKind
Mode
DELETE -> Builder -> (Builder, [PersistValue])
forall {a} {a}. a -> (a, [a])
plain Builder
"DELETE "
Mode
UPDATE -> Builder -> (Builder, [PersistValue])
forall {a} {a}. a -> (a, [a])
plain Builder
"UPDATE "
Mode
INSERT_INTO -> Mode -> (Builder, [PersistValue])
process Mode
SELECT
selectKind :: (Builder, [PersistValue])
selectKind =
case DistinctClause
distinctClause of
DistinctClause
DistinctAll -> (Builder
"SELECT ", [])
DistinctClause
DistinctStandard -> (Builder
"SELECT DISTINCT ", [])
DistinctOn [SqlExpr DistinctOn]
exprs ->
(Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first ((Builder
"SELECT DISTINCT ON (" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) (Builder -> Builder) -> (Builder -> Builder) -> Builder -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
") "))
((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas' (SqlExpr DistinctOn -> (Builder, [PersistValue])
processExpr (SqlExpr DistinctOn -> (Builder, [PersistValue]))
-> [SqlExpr DistinctOn] -> [(Builder, [PersistValue])]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [SqlExpr DistinctOn]
exprs)
where
processExpr :: SqlExpr DistinctOn -> (Builder, [PersistValue])
processExpr SqlExpr DistinctOn
e = IdentInfo -> SqlExpr (Value Any) -> (Builder, [PersistValue])
forall a.
IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue])
materializeExpr IdentInfo
info (SqlExpr DistinctOn -> SqlExpr (Value a)
forall a b. Coercible a b => a -> b
coerce SqlExpr DistinctOn
e :: SqlExpr (Value a))
withCols :: (Builder, [PersistValue]) -> (Builder, [PersistValue])
withCols (Builder, [PersistValue])
v = (Builder, [PersistValue])
v (Builder, [PersistValue])
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a. Semigroup a => a -> a -> a
<> IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
info a
ret
plain :: a -> (a, [a])
plain a
v = (a
v, [])
makeFrom
:: IdentInfo
-> Mode
-> [FromClause]
-> (TLB.Builder, [PersistValue])
makeFrom :: IdentInfo -> Mode -> [FromClause] -> (Builder, [PersistValue])
makeFrom IdentInfo
_ Mode
_ [] = (Builder, [PersistValue])
forall a. Monoid a => a
mempty
makeFrom IdentInfo
info Mode
mode [FromClause]
fs = (Builder, [PersistValue])
ret
where
ret :: (Builder, [PersistValue])
ret =
case SqlBackend
-> [FromClause] -> Either (SqlExpr (Value Bool)) [FromClause]
collectOnClauses (IdentInfo -> SqlBackend
forall a b. (a, b) -> a
fst IdentInfo
info) [FromClause]
fs of
Left SqlExpr (Value Bool)
expr -> OnClauseWithoutMatchingJoinException -> (Builder, [PersistValue])
forall a e. Exception e => e -> a
throw (OnClauseWithoutMatchingJoinException -> (Builder, [PersistValue]))
-> OnClauseWithoutMatchingJoinException
-> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ SqlExpr (Value Bool) -> OnClauseWithoutMatchingJoinException
mkExc SqlExpr (Value Bool)
expr
Right [FromClause]
fs' -> (Builder, [PersistValue]) -> (Builder, [PersistValue])
keyword ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas' ((FromClause -> (Builder, [PersistValue]))
-> [FromClause] -> [(Builder, [PersistValue])]
forall a b. (a -> b) -> [a] -> [b]
map (NeedParens -> FromClause -> (Builder, [PersistValue])
mk NeedParens
Never) [FromClause]
fs')
keyword :: (Builder, [PersistValue]) -> (Builder, [PersistValue])
keyword =
case Mode
mode of
Mode
UPDATE -> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a. a -> a
id
Mode
_ -> (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Builder
"\nFROM " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>)
mk :: NeedParens -> FromClause -> (Builder, [PersistValue])
mk NeedParens
_ (FromStart Ident
i EntityDef
def) = Ident -> EntityDef -> (Builder, [PersistValue])
base Ident
i EntityDef
def
mk NeedParens
paren (FromJoin FromClause
lhs JoinKind
kind FromClause
rhs Maybe (SqlExpr (Value Bool))
monClause) =
(Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (NeedParens -> Builder -> Builder
parensM NeedParens
paren) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [a] -> a
mconcat [ NeedParens -> FromClause -> (Builder, [PersistValue])
mk NeedParens
Never FromClause
lhs
, (JoinKind -> Builder
forall {a}. IsString a => JoinKind -> a
fromKind JoinKind
kind, [PersistValue]
forall a. Monoid a => a
mempty)
, NeedParens -> FromClause -> (Builder, [PersistValue])
mk NeedParens
Parens FromClause
rhs
, (Builder, [PersistValue])
-> (SqlExpr (Value Bool) -> (Builder, [PersistValue]))
-> Maybe (SqlExpr (Value Bool))
-> (Builder, [PersistValue])
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Builder, [PersistValue])
forall a. Monoid a => a
mempty SqlExpr (Value Bool) -> (Builder, [PersistValue])
makeOnClause Maybe (SqlExpr (Value Bool))
monClause
]
mk NeedParens
_ (OnClause SqlExpr (Value Bool)
_) = EsqueletoError -> (Builder, [PersistValue])
forall a e. Exception e => e -> a
throw (UnexpectedCaseError -> EsqueletoError
UnexpectedCaseErr UnexpectedCaseError
MakeFromError)
mk NeedParens
paren (FromRaw NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
paren IdentInfo
info
base :: Ident -> EntityDef -> (Builder, [PersistValue])
base ident :: Ident
ident@(I Text
identText) EntityDef
def =
let db :: DBName
db@(DBName Text
dbText) = EntityNameDB -> DBName
forall a b. Coercible a b => a -> b
coerce (EntityNameDB -> DBName) -> EntityNameDB -> DBName
forall a b. (a -> b) -> a -> b
$ EntityDef -> EntityNameDB
getEntityDBName EntityDef
def
in ( IdentInfo -> DBName -> Builder
fromDBName IdentInfo
info DBName
db Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>
if Text
dbText Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
identText
then Builder
forall a. Monoid a => a
mempty
else Builder
" AS " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> IdentInfo -> Ident -> Builder
useIdent IdentInfo
info Ident
ident
, [PersistValue]
forall a. Monoid a => a
mempty
)
fromKind :: JoinKind -> a
fromKind JoinKind
InnerJoinKind = a
" INNER JOIN "
fromKind JoinKind
CrossJoinKind = a
" CROSS JOIN "
fromKind JoinKind
LeftOuterJoinKind = a
" LEFT OUTER JOIN "
fromKind JoinKind
RightOuterJoinKind = a
" RIGHT OUTER JOIN "
fromKind JoinKind
FullOuterJoinKind = a
" FULL OUTER JOIN "
makeOnClause :: SqlExpr (Value Bool) -> (Builder, [PersistValue])
makeOnClause (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) = (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Builder
" ON " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) (NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info)
mkExc :: SqlExpr (Value Bool) -> OnClauseWithoutMatchingJoinException
mkExc :: SqlExpr (Value Bool) -> OnClauseWithoutMatchingJoinException
mkExc (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) =
String -> OnClauseWithoutMatchingJoinException
OnClauseWithoutMatchingJoinException (String -> OnClauseWithoutMatchingJoinException)
-> String -> OnClauseWithoutMatchingJoinException
forall a b. (a -> b) -> a -> b
$
Text -> String
TL.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ Builder -> Text
TLB.toLazyText (Builder -> Text) -> Builder -> Text
forall a b. (a -> b) -> a -> b
$ (Builder, [PersistValue]) -> Builder
forall a b. (a, b) -> a
fst (NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info)
makeSet :: IdentInfo -> [SetClause] -> (TLB.Builder, [PersistValue])
makeSet :: IdentInfo -> [SetClause] -> (Builder, [PersistValue])
makeSet IdentInfo
_ [] = (Builder, [PersistValue])
forall a. Monoid a => a
mempty
makeSet IdentInfo
info [SetClause]
os = (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Builder
"\nSET " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> ([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> [(Builder, [PersistValue])]
-> (Builder, [PersistValue])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas' ([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ (SetClause -> [(Builder, [PersistValue])])
-> [SetClause] -> [(Builder, [PersistValue])]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap SetClause -> [(Builder, [PersistValue])]
mk [SetClause]
os
where
mk :: SetClause -> [(Builder, [PersistValue])]
mk (SetClause (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f)) = [NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info]
makeWhere :: IdentInfo -> WhereClause -> (TLB.Builder, [PersistValue])
makeWhere :: IdentInfo -> WhereClause -> (Builder, [PersistValue])
makeWhere IdentInfo
_ WhereClause
NoWhere = (Builder, [PersistValue])
forall a. Monoid a => a
mempty
makeWhere IdentInfo
info (Where (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f)) = (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Builder
"\nWHERE " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info
makeGroupBy :: IdentInfo -> GroupByClause -> (TLB.Builder, [PersistValue])
makeGroupBy :: IdentInfo -> GroupByClause -> (Builder, [PersistValue])
makeGroupBy IdentInfo
_ (GroupBy []) = (Builder
forall a. Monoid a => a
mempty, [])
makeGroupBy IdentInfo
info (GroupBy [SomeValue]
fields) = (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Builder
"\nGROUP BY " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) (Builder, [PersistValue])
build
where
build :: (TLB.Builder, [PersistValue])
build :: (Builder, [PersistValue])
build = [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas' ([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ (SomeValue -> (Builder, [PersistValue]))
-> [SomeValue] -> [(Builder, [PersistValue])]
forall a b. (a -> b) -> [a] -> [b]
map SomeValue -> (Builder, [PersistValue])
match [SomeValue]
fields
match :: SomeValue -> (TLB.Builder, [PersistValue])
match :: SomeValue -> (Builder, [PersistValue])
match (SomeValue (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f)) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info
makeHaving :: IdentInfo -> WhereClause -> (TLB.Builder, [PersistValue])
makeHaving :: IdentInfo -> WhereClause -> (Builder, [PersistValue])
makeHaving IdentInfo
_ WhereClause
NoWhere = (Builder, [PersistValue])
forall a. Monoid a => a
mempty
makeHaving IdentInfo
info (Where (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f)) = (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Builder
"\nHAVING " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info
makeOrderByNoNewline
:: IdentInfo -> [OrderByClause] -> (TLB.Builder, [PersistValue])
makeOrderByNoNewline :: IdentInfo -> [SqlExpr OrderBy] -> (Builder, [PersistValue])
makeOrderByNoNewline IdentInfo
_ [] = (Builder, [PersistValue])
forall a. Monoid a => a
mempty
makeOrderByNoNewline IdentInfo
info [SqlExpr OrderBy]
os = (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Builder
"ORDER BY " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) ((Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> ([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> [(Builder, [PersistValue])]
-> (Builder, [PersistValue])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas' ([(Builder, [PersistValue])] -> (Builder, [PersistValue]))
-> [(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a b. (a -> b) -> a -> b
$ (SqlExpr OrderBy -> [(Builder, [PersistValue])])
-> [SqlExpr OrderBy] -> [(Builder, [PersistValue])]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap SqlExpr OrderBy -> [(Builder, [PersistValue])]
mk [SqlExpr OrderBy]
os
where
mk :: OrderByClause -> [(TLB.Builder, [PersistValue])]
mk :: SqlExpr OrderBy -> [(Builder, [PersistValue])]
mk (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) = [NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info]
makeOrderBy :: IdentInfo -> [OrderByClause] -> (TLB.Builder, [PersistValue])
makeOrderBy :: IdentInfo -> [SqlExpr OrderBy] -> (Builder, [PersistValue])
makeOrderBy IdentInfo
_ [] = (Builder, [PersistValue])
forall a. Monoid a => a
mempty
makeOrderBy IdentInfo
info [SqlExpr OrderBy]
is =
let (Builder
tlb, [PersistValue]
vals) = IdentInfo -> [SqlExpr OrderBy] -> (Builder, [PersistValue])
makeOrderByNoNewline IdentInfo
info [SqlExpr OrderBy]
is
in (Builder
tlb, [PersistValue]
vals)
makeLimit :: IdentInfo -> LimitClause -> (TLB.Builder, [PersistValue])
makeLimit :: IdentInfo -> LimitClause -> (Builder, [PersistValue])
makeLimit (SqlBackend
conn, IdentState
_) (Limit Maybe Int64
ml Maybe Int64
mo) =
let limitRaw :: Text
limitRaw = (Int, Int) -> Text -> SqlBackend -> Text
forall backend (m :: * -> *).
(BackendCompatible SqlBackend backend, MonadReader backend m) =>
(Int, Int) -> Text -> m Text
getConnLimitOffset (Maybe Int64 -> Int
v Maybe Int64
ml, Maybe Int64 -> Int
v Maybe Int64
mo) Text
"" SqlBackend
conn
v :: Maybe Int64 -> Int
v :: Maybe Int64 -> Int
v = Int -> (Int64 -> Int) -> Maybe Int64 -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
in (Text -> Builder
TLB.fromText Text
limitRaw, [PersistValue]
forall a. Monoid a => a
mempty)
makeLocking :: IdentInfo -> LockingClause -> (TLB.Builder, [PersistValue])
makeLocking :: IdentInfo -> LockingClause -> (Builder, [PersistValue])
makeLocking IdentInfo
_ (LegacyLockingClause LockingKind
lockingClause) =
case LockingKind
lockingClause of
LockingKind
ForUpdate -> (Builder
"\nFOR UPDATE", [])
LockingKind
ForUpdateSkipLocked -> (Builder
"\nFOR UPDATE SKIP LOCKED", [])
LockingKind
ForShare -> (Builder
"\nFOR SHARE", [])
LockingKind
LockInShareMode -> (Builder
"\nLOCK IN SHARE MODE", [])
makeLocking IdentInfo
info (PostgresLockingClauses [PostgresLockingKind]
clauses) =
((Builder, [PersistValue])
-> (Builder, [PersistValue]) -> (Builder, [PersistValue]))
-> (Builder, [PersistValue])
-> [(Builder, [PersistValue])]
-> (Builder, [PersistValue])
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' (Builder, [PersistValue])
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall {a} {b}.
(IsString a, Semigroup a, Semigroup b) =>
(a, b) -> (a, b) -> (a, b)
combineBuilderValPairs (Builder
"",[]) (PostgresLockingKind -> (Builder, [PersistValue])
makePostgresLockingClauses (PostgresLockingKind -> (Builder, [PersistValue]))
-> [PostgresLockingKind] -> [(Builder, [PersistValue])]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [PostgresLockingKind]
clauses)
where
combineBuilderValPairs :: (a, b) -> (a, b) -> (a, b)
combineBuilderValPairs (a
builder1, b
persistvals1) (a
builder2,b
persistvals2) =
(a
builder1 a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
builder2 a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
"\n", b
persistvals1 b -> b -> b
forall a. Semigroup a => a -> a -> a
<> b
persistvals2)
makePostgresLockingClauses :: PostgresLockingKind -> (TLB.Builder , [PersistValue])
makePostgresLockingClauses :: PostgresLockingKind -> (Builder, [PersistValue])
makePostgresLockingClauses PostgresLockingKind
l =
PostgresRowLevelLockStrength -> (Builder, [PersistValue])
makeLockingStrength (PostgresLockingKind -> PostgresRowLevelLockStrength
postgresRowLevelLockStrength PostgresLockingKind
l)
(Builder, [PersistValue])
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a. Semigroup a => a -> a -> a
<> Builder -> (Builder, [PersistValue])
forall {a} {a}. a -> (a, [a])
plain Builder
" "
(Builder, [PersistValue])
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a. Semigroup a => a -> a -> a
<> Maybe LockingOfClause -> (Builder, [PersistValue])
makeOfClause (PostgresLockingKind -> Maybe LockingOfClause
postgresLockingOfClause PostgresLockingKind
l)
(Builder, [PersistValue])
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a. Semigroup a => a -> a -> a
<> Builder -> (Builder, [PersistValue])
forall {a} {a}. a -> (a, [a])
plain Builder
" "
(Builder, [PersistValue])
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a. Semigroup a => a -> a -> a
<> OnLockedBehavior -> (Builder, [PersistValue])
makeLockingBehavior (PostgresLockingKind -> OnLockedBehavior
postgresOnLockedBehavior PostgresLockingKind
l)
makeLockingStrength :: PostgresRowLevelLockStrength -> (TLB.Builder, [PersistValue])
makeLockingStrength :: PostgresRowLevelLockStrength -> (Builder, [PersistValue])
makeLockingStrength PostgresRowLevelLockStrength
PostgresForUpdate = Builder -> (Builder, [PersistValue])
forall {a} {a}. a -> (a, [a])
plain Builder
"FOR UPDATE"
makeLockingStrength PostgresRowLevelLockStrength
PostgresForShare = Builder -> (Builder, [PersistValue])
forall {a} {a}. a -> (a, [a])
plain Builder
"FOR SHARE"
makeLockingBehavior :: OnLockedBehavior -> (TLB.Builder, [PersistValue])
makeLockingBehavior :: OnLockedBehavior -> (Builder, [PersistValue])
makeLockingBehavior OnLockedBehavior
NoWait = Builder -> (Builder, [PersistValue])
forall {a} {a}. a -> (a, [a])
plain Builder
"NOWAIT"
makeLockingBehavior OnLockedBehavior
SkipLocked = Builder -> (Builder, [PersistValue])
forall {a} {a}. a -> (a, [a])
plain Builder
"SKIP LOCKED"
makeLockingBehavior OnLockedBehavior
Wait = Builder -> (Builder, [PersistValue])
forall {a} {a}. a -> (a, [a])
plain Builder
""
makeOfClause :: Maybe LockingOfClause -> (TLB.Builder, [PersistValue])
makeOfClause :: Maybe LockingOfClause -> (Builder, [PersistValue])
makeOfClause (Just (LockingOfClause a
lockableEnts)) = Builder -> (Builder, [PersistValue])
forall {a} {a}. a -> (a, [a])
plain Builder
"OF " (Builder, [PersistValue])
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall a. Semigroup a => a -> a -> a
<> IdentInfo -> a -> (Builder, [PersistValue])
forall a.
LockableEntity a =>
IdentInfo -> a -> (Builder, [PersistValue])
makeLockableEntity IdentInfo
info a
lockableEnts
makeOfClause Maybe LockingOfClause
Nothing = Builder -> (Builder, [PersistValue])
forall {a} {a}. a -> (a, [a])
plain Builder
""
plain :: a -> (a, [a])
plain a
v = (a
v,[])
makeLocking IdentInfo
_ LockingClause
NoLockingClause = (Builder, [PersistValue])
forall a. Monoid a => a
mempty
parens :: TLB.Builder -> TLB.Builder
parens :: Builder -> Builder
parens Builder
b = Builder
"(" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> (Builder
b Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
")")
aliasedEntityColumnIdent :: Ident -> FieldDef -> Ident
aliasedEntityColumnIdent :: Ident -> FieldDef -> Ident
aliasedEntityColumnIdent (I Text
baseIdent) FieldDef
field =
Text -> Ident
I (Text
baseIdent Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"_" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (DBName -> Text
unDBName (DBName -> Text) -> DBName -> Text
forall a b. (a -> b) -> a -> b
$ FieldNameDB -> DBName
forall a b. Coercible a b => a -> b
coerce (FieldNameDB -> DBName) -> FieldNameDB -> DBName
forall a b. (a -> b) -> a -> b
$ FieldDef -> FieldNameDB
fieldDB FieldDef
field))
aliasedColumnName :: Ident -> IdentInfo -> T.Text -> TLB.Builder
aliasedColumnName :: Ident -> IdentInfo -> Text -> Builder
aliasedColumnName (I Text
baseIdent) IdentInfo
info Text
columnName =
IdentInfo -> Ident -> Builder
useIdent IdentInfo
info (Text -> Ident
I (Text
baseIdent Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"_" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
columnName))
class SqlSelect a r | a -> r, r -> a where
sqlSelectCols :: IdentInfo -> a -> (TLB.Builder, [PersistValue])
sqlSelectColCount :: Proxy a -> Int
sqlSelectProcessRow :: [PersistValue] -> Either T.Text r
sqlInsertInto :: IdentInfo -> a -> (TLB.Builder, [PersistValue])
sqlInsertInto = EsqueletoError -> IdentInfo -> a -> (Builder, [PersistValue])
forall a e. Exception e => e -> a
throw (UnexpectedCaseError -> EsqueletoError
UnexpectedCaseErr UnexpectedCaseError
UnsupportedSqlInsertIntoType)
instance PersistEntity e => SqlSelect (SqlExpr (Insertion e)) (Insertion e) where
sqlInsertInto :: IdentInfo -> SqlExpr (Insertion e) -> (Builder, [PersistValue])
sqlInsertInto IdentInfo
info SqlExpr (Insertion e)
e =
let fields :: Builder
fields =
[Builder] -> Builder
uncommas ([Builder] -> Builder) -> [Builder] -> Builder
forall a b. (a -> b) -> a -> b
$
(FieldDef -> Builder) -> [FieldDef] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map (IdentInfo -> DBName -> Builder
fromDBName IdentInfo
info (DBName -> Builder) -> (FieldDef -> DBName) -> FieldDef -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldNameDB -> DBName
forall a b. Coercible a b => a -> b
coerce (FieldNameDB -> DBName)
-> (FieldDef -> FieldNameDB) -> FieldDef -> DBName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldDef -> FieldNameDB
fieldDB) ([FieldDef] -> [Builder]) -> [FieldDef] -> [Builder]
forall a b. (a -> b) -> a -> b
$
EntityDef -> [FieldDef]
getEntityFields (EntityDef -> [FieldDef]) -> EntityDef -> [FieldDef]
forall a b. (a -> b) -> a -> b
$
Proxy e -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy e -> EntityDef
entityDef (SqlExpr (Insertion e) -> Proxy e
forall a. SqlExpr (Insertion a) -> Proxy a
proxy SqlExpr (Insertion e)
e)
proxy :: SqlExpr (Insertion a) -> Proxy a
proxy :: forall a. SqlExpr (Insertion a) -> Proxy a
proxy = Proxy a -> SqlExpr (Insertion a) -> Proxy a
forall a b. a -> b -> a
const Proxy a
forall {k} (t :: k). Proxy t
Proxy
table :: SqlExpr (Insertion e) -> Builder
table =
IdentInfo -> DBName -> Builder
fromDBName IdentInfo
info (DBName -> Builder)
-> (SqlExpr (Insertion e) -> DBName)
-> SqlExpr (Insertion e)
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> DBName
DBName (Text -> DBName)
-> (SqlExpr (Insertion e) -> Text)
-> SqlExpr (Insertion e)
-> DBName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EntityNameDB -> Text
forall a b. Coercible a b => a -> b
coerce (EntityNameDB -> Text)
-> (SqlExpr (Insertion e) -> EntityNameDB)
-> SqlExpr (Insertion e)
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EntityDef -> EntityNameDB
getEntityDBName (EntityDef -> EntityNameDB)
-> (SqlExpr (Insertion e) -> EntityDef)
-> SqlExpr (Insertion e)
-> EntityNameDB
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy e -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy e -> EntityDef
entityDef (Proxy e -> EntityDef)
-> (SqlExpr (Insertion e) -> Proxy e)
-> SqlExpr (Insertion e)
-> EntityDef
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlExpr (Insertion e) -> Proxy e
forall a. SqlExpr (Insertion a) -> Proxy a
proxy
in
(Builder
"INSERT INTO " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> SqlExpr (Insertion e) -> Builder
table SqlExpr (Insertion e)
e Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> Builder
parens Builder
fields Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"\n", [])
sqlSelectCols :: IdentInfo -> SqlExpr (Insertion e) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
info (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info
sqlSelectColCount :: Proxy (SqlExpr (Insertion e)) -> Int
sqlSelectColCount = Int -> Proxy (SqlExpr (Insertion e)) -> Int
forall a b. a -> b -> a
const Int
0
sqlSelectProcessRow :: [PersistValue] -> Either Text (Insertion e)
sqlSelectProcessRow =
Either Text (Insertion e)
-> [PersistValue] -> Either Text (Insertion e)
forall a b. a -> b -> a
const (Insertion e -> Either Text (Insertion e)
forall a b. b -> Either a b
Right (EsqueletoError -> Insertion e
forall a e. Exception e => e -> a
throw (UnexpectedCaseError -> EsqueletoError
UnexpectedCaseErr UnexpectedCaseError
InsertionFinalError)))
instance SqlSelect () () where
sqlSelectCols :: IdentInfo -> () -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
_ ()
_ = (Builder
"1", [])
sqlSelectColCount :: Proxy () -> Int
sqlSelectColCount Proxy ()
_ = Int
1
sqlSelectProcessRow :: [PersistValue] -> Either Text ()
sqlSelectProcessRow [PersistValue]
_ = () -> Either Text ()
forall a b. b -> Either a b
Right ()
unescapedColumnNames :: EntityDef -> [DBName]
unescapedColumnNames :: EntityDef -> [DBName]
unescapedColumnNames EntityDef
ent =
[DBName] -> [DBName]
addIdColumn [DBName]
rest
where
rest :: [DBName]
rest =
(FieldDef -> DBName) -> [FieldDef] -> [DBName]
forall a b. (a -> b) -> [a] -> [b]
map (FieldNameDB -> DBName
forall a b. Coercible a b => a -> b
coerce (FieldNameDB -> DBName)
-> (FieldDef -> FieldNameDB) -> FieldDef -> DBName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldDef -> FieldNameDB
fieldDB) (EntityDef -> [FieldDef]
getEntityFields EntityDef
ent)
addIdColumn :: [DBName] -> [DBName]
addIdColumn =
case EntityDef -> EntityIdDef
getEntityId EntityDef
ent of
EntityIdField FieldDef
fd ->
(:) (FieldNameDB -> DBName
forall a b. Coercible a b => a -> b
coerce (FieldDef -> FieldNameDB
fieldDB FieldDef
fd))
EntityIdNaturalKey CompositeDef
_ ->
[DBName] -> [DBName]
forall a. a -> a
id
instance PersistEntity a => SqlSelect (SqlExpr (Entity a)) (Entity a) where
sqlSelectCols :: IdentInfo -> SqlExpr (Entity a) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
info expr :: SqlExpr (Entity a)
expr@(ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f)
| Just Ident
baseIdent <- SqlExprMeta -> Maybe Ident
sqlExprMetaAlias SqlExprMeta
m, Bool
False <- SqlExprMeta -> Bool
sqlExprMetaIsReference SqlExprMeta
m =
let process :: Builder
process = [Builder] -> Builder
uncommas ([Builder] -> Builder) -> [Builder] -> Builder
forall a b. (a -> b) -> a -> b
$
(DBName -> Builder) -> [DBName] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map ((Builder
name Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) (Builder -> Builder) -> (DBName -> Builder) -> DBName -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DBName -> Builder
aliasName) ([DBName] -> [Builder]) -> [DBName] -> [Builder]
forall a b. (a -> b) -> a -> b
$
EntityDef -> [DBName]
unescapedColumnNames EntityDef
ed
aliasName :: DBName -> Builder
aliasName DBName
columnName = (IdentInfo -> DBName -> Builder
fromDBName IdentInfo
info DBName
columnName) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" AS " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Ident -> IdentInfo -> Text -> Builder
aliasedColumnName Ident
baseIdent IdentInfo
info (DBName -> Text
unDBName DBName
columnName)
name :: Builder
name = (Builder, [PersistValue]) -> Builder
forall a b. (a, b) -> a
fst (NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"."
ed :: EntityDef
ed = Proxy a -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy a -> EntityDef
entityDef (Proxy a -> EntityDef) -> Proxy a -> EntityDef
forall a b. (a -> b) -> a -> b
$ Proxy (SqlExpr (Entity a)) -> Proxy a
forall a. Proxy (SqlExpr (Entity a)) -> Proxy a
getEntityVal (Proxy (SqlExpr (Entity a)) -> Proxy a)
-> Proxy (SqlExpr (Entity a)) -> Proxy a
forall a b. (a -> b) -> a -> b
$ SqlExpr (Entity a) -> Proxy (SqlExpr (Entity a))
forall a. a -> Proxy a
forall (m :: * -> *) a. Monad m => a -> m a
return SqlExpr (Entity a)
expr
in (Builder
process, [PersistValue]
forall a. Monoid a => a
mempty)
| Just Ident
baseIdent <- SqlExprMeta -> Maybe Ident
sqlExprMetaAlias SqlExprMeta
m, Bool
True <- SqlExprMeta -> Bool
sqlExprMetaIsReference SqlExprMeta
m =
let process :: Builder
process = [Builder] -> Builder
uncommas ([Builder] -> Builder) -> [Builder] -> Builder
forall a b. (a -> b) -> a -> b
$
(DBName -> Builder) -> [DBName] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map ((Builder
name Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) (Builder -> Builder) -> (DBName -> Builder) -> DBName -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ident -> IdentInfo -> Text -> Builder
aliasedColumnName Ident
baseIdent IdentInfo
info (Text -> Builder) -> (DBName -> Text) -> DBName -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DBName -> Text
unDBName) ([DBName] -> [Builder]) -> [DBName] -> [Builder]
forall a b. (a -> b) -> a -> b
$
EntityDef -> [DBName]
unescapedColumnNames EntityDef
ed
name :: Builder
name = (Builder, [PersistValue]) -> Builder
forall a b. (a, b) -> a
fst (NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"."
ed :: EntityDef
ed = Proxy a -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy a -> EntityDef
entityDef (Proxy a -> EntityDef) -> Proxy a -> EntityDef
forall a b. (a -> b) -> a -> b
$ Proxy (SqlExpr (Entity a)) -> Proxy a
forall a. Proxy (SqlExpr (Entity a)) -> Proxy a
getEntityVal (Proxy (SqlExpr (Entity a)) -> Proxy a)
-> Proxy (SqlExpr (Entity a)) -> Proxy a
forall a b. (a -> b) -> a -> b
$ SqlExpr (Entity a) -> Proxy (SqlExpr (Entity a))
forall a. a -> Proxy a
forall (m :: * -> *) a. Monad m => a -> m a
return SqlExpr (Entity a)
expr
in (Builder
process, [PersistValue]
forall a. Monoid a => a
mempty)
| Bool
otherwise =
let process :: Builder
process =
[Builder] -> Builder
uncommas
([Builder] -> Builder) -> [Builder] -> Builder
forall a b. (a -> b) -> a -> b
$ (Text -> Builder) -> [Text] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
map ((Builder
name Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<>) (Builder -> Builder) -> (Text -> Builder) -> Text -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Builder
TLB.fromText)
([Text] -> [Builder]) -> [Text] -> [Builder]
forall a b. (a -> b) -> a -> b
$ NonEmpty Text -> [Text]
forall a. NonEmpty a -> [a]
NEL.toList
(NonEmpty Text -> [Text]) -> NonEmpty Text -> [Text]
forall a b. (a -> b) -> a -> b
$ EntityDef -> SqlBackend -> NonEmpty Text
keyAndEntityColumnNames EntityDef
ed (IdentInfo -> SqlBackend
forall a b. (a, b) -> a
fst IdentInfo
info)
name :: Builder
name = (Builder, [PersistValue]) -> Builder
forall a b. (a, b) -> a
fst (NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Never IdentInfo
info) Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
"."
ed :: EntityDef
ed = Proxy a -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy a -> EntityDef
entityDef (Proxy a -> EntityDef) -> Proxy a -> EntityDef
forall a b. (a -> b) -> a -> b
$ Proxy (SqlExpr (Entity a)) -> Proxy a
forall a. Proxy (SqlExpr (Entity a)) -> Proxy a
getEntityVal (Proxy (SqlExpr (Entity a)) -> Proxy a)
-> Proxy (SqlExpr (Entity a)) -> Proxy a
forall a b. (a -> b) -> a -> b
$ SqlExpr (Entity a) -> Proxy (SqlExpr (Entity a))
forall a. a -> Proxy a
forall (m :: * -> *) a. Monad m => a -> m a
return SqlExpr (Entity a)
expr
in (Builder
process, [PersistValue]
forall a. Monoid a => a
mempty)
sqlSelectColCount :: Proxy (SqlExpr (Entity a)) -> Int
sqlSelectColCount = EntityDef -> Int
entityColumnCount (EntityDef -> Int)
-> (Proxy (SqlExpr (Entity a)) -> EntityDef)
-> Proxy (SqlExpr (Entity a))
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy a -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy a -> EntityDef
entityDef (Proxy a -> EntityDef)
-> (Proxy (SqlExpr (Entity a)) -> Proxy a)
-> Proxy (SqlExpr (Entity a))
-> EntityDef
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (SqlExpr (Entity a)) -> Proxy a
forall a. Proxy (SqlExpr (Entity a)) -> Proxy a
getEntityVal
sqlSelectProcessRow :: [PersistValue] -> Either Text (Entity a)
sqlSelectProcessRow = EntityDef -> [PersistValue] -> Either Text (Entity a)
forall record.
PersistEntity record =>
EntityDef -> [PersistValue] -> Either Text (Entity record)
parseEntityValues EntityDef
ed
where
ed :: EntityDef
ed = Proxy a -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
forall (proxy :: * -> *). proxy a -> EntityDef
entityDef (Proxy a -> EntityDef) -> Proxy a -> EntityDef
forall a b. (a -> b) -> a -> b
$ Proxy (SqlExpr (Entity a)) -> Proxy a
forall a. Proxy (SqlExpr (Entity a)) -> Proxy a
getEntityVal (Proxy (SqlExpr (Entity a))
forall {k} (t :: k). Proxy t
Proxy :: Proxy (SqlExpr (Entity a)))
getEntityVal :: Proxy (SqlExpr (Entity a)) -> Proxy a
getEntityVal :: forall a. Proxy (SqlExpr (Entity a)) -> Proxy a
getEntityVal = Proxy a -> Proxy (SqlExpr (Entity a)) -> Proxy a
forall a b. a -> b -> a
const Proxy a
forall {k} (t :: k). Proxy t
Proxy
instance PersistEntity a => SqlSelect (SqlExpr (Maybe (Entity a))) (Maybe (Entity a)) where
sqlSelectCols :: IdentInfo
-> SqlExpr (Maybe (Entity a)) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
info SqlExpr (Maybe (Entity a))
e = IdentInfo -> SqlExpr (Entity a) -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
info (SqlExpr (Maybe (Entity a)) -> SqlExpr (Entity a)
forall a b. Coercible a b => a -> b
coerce SqlExpr (Maybe (Entity a))
e :: SqlExpr (Entity a))
sqlSelectColCount :: Proxy (SqlExpr (Maybe (Entity a))) -> Int
sqlSelectColCount = Proxy (SqlExpr (Entity a)) -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy (SqlExpr (Entity a)) -> Int)
-> (Proxy (SqlExpr (Maybe (Entity a)))
-> Proxy (SqlExpr (Entity a)))
-> Proxy (SqlExpr (Maybe (Entity a)))
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (SqlExpr (Maybe (Entity a))) -> Proxy (SqlExpr (Entity a))
forall e. Proxy (SqlExpr (Maybe e)) -> Proxy (SqlExpr e)
fromEMaybe
where
fromEMaybe :: Proxy (SqlExpr (Maybe e)) -> Proxy (SqlExpr e)
fromEMaybe :: forall e. Proxy (SqlExpr (Maybe e)) -> Proxy (SqlExpr e)
fromEMaybe = Proxy (SqlExpr e) -> Proxy (SqlExpr (Maybe e)) -> Proxy (SqlExpr e)
forall a b. a -> b -> a
const Proxy (SqlExpr e)
forall {k} (t :: k). Proxy t
Proxy
sqlSelectProcessRow :: [PersistValue] -> Either Text (Maybe (Entity a))
sqlSelectProcessRow [PersistValue]
cols
| (PersistValue -> Bool) -> [PersistValue] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (PersistValue -> PersistValue -> Bool
forall a. Eq a => a -> a -> Bool
== PersistValue
PersistNull) [PersistValue]
cols = Maybe (Entity a) -> Either Text (Maybe (Entity a))
forall a. a -> Either Text a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Entity a)
forall a. Maybe a
Nothing
| Bool
otherwise = Entity a -> Maybe (Entity a)
forall a. a -> Maybe a
Just (Entity a -> Maybe (Entity a))
-> Either Text (Entity a) -> Either Text (Maybe (Entity a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [PersistValue] -> Either Text (Entity a)
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow [PersistValue]
cols
instance PersistField a => SqlSelect (SqlExpr (Value a)) (Value a) where
sqlSelectCols :: IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue])
sqlSelectCols = IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue])
forall a.
IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue])
materializeExpr
sqlSelectColCount :: Proxy (SqlExpr (Value a)) -> Int
sqlSelectColCount = Int -> Proxy (SqlExpr (Value a)) -> Int
forall a b. a -> b -> a
const Int
1
sqlSelectProcessRow :: [PersistValue] -> Either Text (Value a)
sqlSelectProcessRow [PersistValue
pv] = a -> Value a
forall a. a -> Value a
Value (a -> Value a) -> Either Text a -> Either Text (Value a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PersistValue -> Either Text a
forall a. PersistField a => PersistValue -> Either Text a
fromPersistValue PersistValue
pv
sqlSelectProcessRow [PersistValue]
pvs = a -> Value a
forall a. a -> Value a
Value (a -> Value a) -> Either Text a -> Either Text (Value a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PersistValue -> Either Text a
forall a. PersistField a => PersistValue -> Either Text a
fromPersistValue ([PersistValue] -> PersistValue
PersistList [PersistValue]
pvs)
materializeExpr :: IdentInfo -> SqlExpr (Value a) -> (TLB.Builder, [PersistValue])
materializeExpr :: forall a.
IdentInfo -> SqlExpr (Value a) -> (Builder, [PersistValue])
materializeExpr IdentInfo
info (ERaw SqlExprMeta
m NeedParens -> IdentInfo -> (Builder, [PersistValue])
f)
| Just IdentInfo -> [Builder]
fields <- SqlExprMeta -> Maybe (IdentInfo -> [Builder])
sqlExprMetaCompositeFields SqlExprMeta
m = ([Builder] -> Builder
uncommas ([Builder] -> Builder) -> [Builder] -> Builder
forall a b. (a -> b) -> a -> b
$ (Builder -> Builder) -> [Builder] -> [Builder]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Builder -> Builder
parens ([Builder] -> [Builder]) -> [Builder] -> [Builder]
forall a b. (a -> b) -> a -> b
$ IdentInfo -> [Builder]
fields IdentInfo
info, [])
| Just Ident
alias <- SqlExprMeta -> Maybe Ident
sqlExprMetaAlias SqlExprMeta
m
, Bool -> Bool
not (SqlExprMeta -> Bool
sqlExprMetaIsReference SqlExprMeta
m) = (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
" AS " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> IdentInfo -> Ident -> Builder
useIdent IdentInfo
info Ident
alias) (NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Parens IdentInfo
info)
| Bool
otherwise = NeedParens -> IdentInfo -> (Builder, [PersistValue])
f NeedParens
Parens IdentInfo
info
instance (SqlSelect a ra, SqlSelect b rb) => SqlSelect (a, b) (ra, rb) where
sqlSelectCols :: IdentInfo -> (a, b) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
]
sqlSelectColCount :: Proxy (a, b) -> Int
sqlSelectColCount = (Int -> Int -> Int) -> (Int, Int) -> Int
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) ((Int, Int) -> Int)
-> (Proxy (a, b) -> (Int, Int)) -> Proxy (a, b) -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Proxy a -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy a -> Int)
-> (Proxy b -> Int) -> (Proxy a, Proxy b) -> (Int, Int)
forall b c b' c'. (b -> c) -> (b' -> c') -> (b, b') -> (c, c')
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** Proxy b -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount) ((Proxy a, Proxy b) -> (Int, Int))
-> (Proxy (a, b) -> (Proxy a, Proxy b))
-> Proxy (a, b)
-> (Int, Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b) -> (Proxy a, Proxy b)
fromTuple
where
fromTuple :: Proxy (a,b) -> (Proxy a, Proxy b)
fromTuple :: Proxy (a, b) -> (Proxy a, Proxy b)
fromTuple = (Proxy a, Proxy b) -> Proxy (a, b) -> (Proxy a, Proxy b)
forall a b. a -> b -> a
const (Proxy a
forall {k} (t :: k). Proxy t
Proxy, Proxy b
forall {k} (t :: k). Proxy t
Proxy)
sqlSelectProcessRow :: [PersistValue] -> Either Text (ra, rb)
sqlSelectProcessRow =
let x :: Proxy a
x = ([PersistValue] -> Either Text (ra, rb)) -> Proxy a
forall r z y x. SqlSelect a r => (z -> Either y (r, x)) -> Proxy a
getType [PersistValue] -> Either Text (ra, rb)
processRow
getType :: SqlSelect a r => (z -> Either y (r,x)) -> Proxy a
getType :: forall r z y x. SqlSelect a r => (z -> Either y (r, x)) -> Proxy a
getType = Proxy a -> (z -> Either y (r, x)) -> Proxy a
forall a b. a -> b -> a
const Proxy a
forall {k} (t :: k). Proxy t
Proxy
colCountFst :: Int
colCountFst = Proxy a -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount Proxy a
x
processRow :: [PersistValue] -> Either Text (ra, rb)
processRow [PersistValue]
row =
let ([PersistValue]
rowFst, [PersistValue]
rowSnd) = Int -> [PersistValue] -> ([PersistValue], [PersistValue])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
colCountFst [PersistValue]
row
in (,) (ra -> rb -> (ra, rb))
-> Either Text ra -> Either Text (rb -> (ra, rb))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [PersistValue] -> Either Text ra
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow [PersistValue]
rowFst
Either Text (rb -> (ra, rb))
-> Either Text rb -> Either Text (ra, rb)
forall a b. Either Text (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [PersistValue] -> Either Text rb
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow [PersistValue]
rowSnd
in Int
colCountFst Int
-> ([PersistValue] -> Either Text (ra, rb))
-> [PersistValue]
-> Either Text (ra, rb)
forall a b. a -> b -> b
`seq` [PersistValue] -> Either Text (ra, rb)
processRow
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
) => SqlSelect (a, b, c) (ra, rb, rc) where
sqlSelectCols :: IdentInfo -> (a, b, c) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
]
sqlSelectColCount :: Proxy (a, b, c) -> Int
sqlSelectColCount = Proxy ((a, b), c) -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), c) -> Int)
-> (Proxy (a, b, c) -> Proxy ((a, b), c)) -> Proxy (a, b, c) -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c) -> Proxy ((a, b), c)
forall a b c. Proxy (a, b, c) -> Proxy ((a, b), c)
from3P
sqlSelectProcessRow :: [PersistValue] -> Either Text (ra, rb, rc)
sqlSelectProcessRow = (((ra, rb), rc) -> (ra, rb, rc))
-> Either Text ((ra, rb), rc) -> Either Text (ra, rb, rc)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), rc) -> (ra, rb, rc)
forall a b c. ((a, b), c) -> (a, b, c)
to3 (Either Text ((ra, rb), rc) -> Either Text (ra, rb, rc))
-> ([PersistValue] -> Either Text ((ra, rb), rc))
-> [PersistValue]
-> Either Text (ra, rb, rc)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue] -> Either Text ((ra, rb), rc)
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from3P :: Proxy (a,b,c) -> Proxy ((a,b),c)
from3P :: forall a b c. Proxy (a, b, c) -> Proxy ((a, b), c)
from3P = Proxy ((a, b), c) -> Proxy (a, b, c) -> Proxy ((a, b), c)
forall a b. a -> b -> a
const Proxy ((a, b), c)
forall {k} (t :: k). Proxy t
Proxy
from3 :: (a,b,c) -> ((a,b),c)
from3 :: forall a b c. (a, b, c) -> ((a, b), c)
from3 (a
a,b
b,c
c) = ((a
a,b
b),c
c)
to3 :: ((a,b),c) -> (a,b,c)
to3 :: forall a b c. ((a, b), c) -> (a, b, c)
to3 ((a
a,b
b),c
c) = (a
a,b
b,c
c)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
) => SqlSelect (a, b, c, d) (ra, rb, rc, rd) where
sqlSelectCols :: IdentInfo -> (a, b, c, d) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
]
sqlSelectColCount :: Proxy (a, b, c, d) -> Int
sqlSelectColCount = Proxy ((a, b), (c, d)) -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), (c, d)) -> Int)
-> (Proxy (a, b, c, d) -> Proxy ((a, b), (c, d)))
-> Proxy (a, b, c, d)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d) -> Proxy ((a, b), (c, d))
forall a b c d. Proxy (a, b, c, d) -> Proxy ((a, b), (c, d))
from4P
sqlSelectProcessRow :: [PersistValue] -> Either Text (ra, rb, rc, rd)
sqlSelectProcessRow = (((ra, rb), (rc, rd)) -> (ra, rb, rc, rd))
-> Either Text ((ra, rb), (rc, rd)) -> Either Text (ra, rb, rc, rd)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd)) -> (ra, rb, rc, rd)
forall a b c d. ((a, b), (c, d)) -> (a, b, c, d)
to4 (Either Text ((ra, rb), (rc, rd)) -> Either Text (ra, rb, rc, rd))
-> ([PersistValue] -> Either Text ((ra, rb), (rc, rd)))
-> [PersistValue]
-> Either Text (ra, rb, rc, rd)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue] -> Either Text ((ra, rb), (rc, rd))
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from4P :: Proxy (a,b,c,d) -> Proxy ((a,b),(c,d))
from4P :: forall a b c d. Proxy (a, b, c, d) -> Proxy ((a, b), (c, d))
from4P = Proxy ((a, b), (c, d))
-> Proxy (a, b, c, d) -> Proxy ((a, b), (c, d))
forall a b. a -> b -> a
const Proxy ((a, b), (c, d))
forall {k} (t :: k). Proxy t
Proxy
from4 :: (a,b,c,d) -> ((a,b),(c,d))
from4 :: forall a b c d. (a, b, c, d) -> ((a, b), (c, d))
from4 (a
a,b
b,c
c,d
d) = ((a
a,b
b),(c
c,d
d))
to4 :: ((a,b),(c,d)) -> (a,b,c,d)
to4 :: forall a b c d. ((a, b), (c, d)) -> (a, b, c, d)
to4 ((a
a,b
b),(c
c,d
d)) = (a
a,b
b,c
c,d
d)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
, SqlSelect e re
) => SqlSelect (a, b, c, d, e) (ra, rb, rc, rd, re) where
sqlSelectCols :: IdentInfo -> (a, b, c, d, e) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d, e
e) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
, IdentInfo -> e -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc e
e
]
sqlSelectColCount :: Proxy (a, b, c, d, e) -> Int
sqlSelectColCount = Proxy ((a, b), (c, d), e) -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), (c, d), e) -> Int)
-> (Proxy (a, b, c, d, e) -> Proxy ((a, b), (c, d), e))
-> Proxy (a, b, c, d, e)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d, e) -> Proxy ((a, b), (c, d), e)
forall a b c d e.
Proxy (a, b, c, d, e) -> Proxy ((a, b), (c, d), e)
from5P
sqlSelectProcessRow :: [PersistValue] -> Either Text (ra, rb, rc, rd, re)
sqlSelectProcessRow = (((ra, rb), (rc, rd), re) -> (ra, rb, rc, rd, re))
-> Either Text ((ra, rb), (rc, rd), re)
-> Either Text (ra, rb, rc, rd, re)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd), re) -> (ra, rb, rc, rd, re)
forall a b c d e. ((a, b), (c, d), e) -> (a, b, c, d, e)
to5 (Either Text ((ra, rb), (rc, rd), re)
-> Either Text (ra, rb, rc, rd, re))
-> ([PersistValue] -> Either Text ((ra, rb), (rc, rd), re))
-> [PersistValue]
-> Either Text (ra, rb, rc, rd, re)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue] -> Either Text ((ra, rb), (rc, rd), re)
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from5P :: Proxy (a,b,c,d,e) -> Proxy ((a,b),(c,d),e)
from5P :: forall a b c d e.
Proxy (a, b, c, d, e) -> Proxy ((a, b), (c, d), e)
from5P = Proxy ((a, b), (c, d), e)
-> Proxy (a, b, c, d, e) -> Proxy ((a, b), (c, d), e)
forall a b. a -> b -> a
const Proxy ((a, b), (c, d), e)
forall {k} (t :: k). Proxy t
Proxy
from5 :: (a,b,c,d,e) -> ((a,b),(c,d),e)
from5 :: forall a b c d e. (a, b, c, d, e) -> ((a, b), (c, d), e)
from5 (a
a,b
b,c
c,d
d,e
e) = ((a
a,b
b),(c
c,d
d),e
e)
to5 :: ((a,b),(c,d),e) -> (a,b,c,d,e)
to5 :: forall a b c d e. ((a, b), (c, d), e) -> (a, b, c, d, e)
to5 ((a
a,b
b),(c
c,d
d),e
e) = (a
a,b
b,c
c,d
d,e
e)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
, SqlSelect e re
, SqlSelect f rf
) => SqlSelect (a, b, c, d, e, f) (ra, rb, rc, rd, re, rf) where
sqlSelectCols :: IdentInfo -> (a, b, c, d, e, f) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d, e
e, f
f) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
, IdentInfo -> e -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc e
e
, IdentInfo -> f -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc f
f
]
sqlSelectColCount :: Proxy (a, b, c, d, e, f) -> Int
sqlSelectColCount = Proxy ((a, b), (c, d), (e, f)) -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), (c, d), (e, f)) -> Int)
-> (Proxy (a, b, c, d, e, f) -> Proxy ((a, b), (c, d), (e, f)))
-> Proxy (a, b, c, d, e, f)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d, e, f) -> Proxy ((a, b), (c, d), (e, f))
forall a b c d e f.
Proxy (a, b, c, d, e, f) -> Proxy ((a, b), (c, d), (e, f))
from6P
sqlSelectProcessRow :: [PersistValue] -> Either Text (ra, rb, rc, rd, re, rf)
sqlSelectProcessRow = (((ra, rb), (rc, rd), (re, rf)) -> (ra, rb, rc, rd, re, rf))
-> Either Text ((ra, rb), (rc, rd), (re, rf))
-> Either Text (ra, rb, rc, rd, re, rf)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd), (re, rf)) -> (ra, rb, rc, rd, re, rf)
forall a b c d e f. ((a, b), (c, d), (e, f)) -> (a, b, c, d, e, f)
to6 (Either Text ((ra, rb), (rc, rd), (re, rf))
-> Either Text (ra, rb, rc, rd, re, rf))
-> ([PersistValue] -> Either Text ((ra, rb), (rc, rd), (re, rf)))
-> [PersistValue]
-> Either Text (ra, rb, rc, rd, re, rf)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue] -> Either Text ((ra, rb), (rc, rd), (re, rf))
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from6P :: Proxy (a,b,c,d,e,f) -> Proxy ((a,b),(c,d),(e,f))
from6P :: forall a b c d e f.
Proxy (a, b, c, d, e, f) -> Proxy ((a, b), (c, d), (e, f))
from6P = Proxy ((a, b), (c, d), (e, f))
-> Proxy (a, b, c, d, e, f) -> Proxy ((a, b), (c, d), (e, f))
forall a b. a -> b -> a
const Proxy ((a, b), (c, d), (e, f))
forall {k} (t :: k). Proxy t
Proxy
from6 :: (a,b,c,d,e,f) -> ((a,b),(c,d),(e,f))
from6 :: forall a b c d e f. (a, b, c, d, e, f) -> ((a, b), (c, d), (e, f))
from6 (a
a,b
b,c
c,d
d,e
e,f
f) = ((a
a,b
b),(c
c,d
d),(e
e,f
f))
to6 :: ((a,b),(c,d),(e,f)) -> (a,b,c,d,e,f)
to6 :: forall a b c d e f. ((a, b), (c, d), (e, f)) -> (a, b, c, d, e, f)
to6 ((a
a,b
b),(c
c,d
d),(e
e,f
f)) = (a
a,b
b,c
c,d
d,e
e,f
f)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
, SqlSelect e re
, SqlSelect f rf
, SqlSelect g rg
) => SqlSelect (a, b, c, d, e, f, g) (ra, rb, rc, rd, re, rf, rg) where
sqlSelectCols :: IdentInfo -> (a, b, c, d, e, f, g) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d, e
e, f
f, g
g) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
, IdentInfo -> e -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc e
e
, IdentInfo -> f -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc f
f
, IdentInfo -> g -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc g
g
]
sqlSelectColCount :: Proxy (a, b, c, d, e, f, g) -> Int
sqlSelectColCount = Proxy ((a, b), (c, d), (e, f), g) -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), (c, d), (e, f), g) -> Int)
-> (Proxy (a, b, c, d, e, f, g)
-> Proxy ((a, b), (c, d), (e, f), g))
-> Proxy (a, b, c, d, e, f, g)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d, e, f, g) -> Proxy ((a, b), (c, d), (e, f), g)
forall a b c d e f g.
Proxy (a, b, c, d, e, f, g) -> Proxy ((a, b), (c, d), (e, f), g)
from7P
sqlSelectProcessRow :: [PersistValue] -> Either Text (ra, rb, rc, rd, re, rf, rg)
sqlSelectProcessRow = (((ra, rb), (rc, rd), (re, rf), rg)
-> (ra, rb, rc, rd, re, rf, rg))
-> Either Text ((ra, rb), (rc, rd), (re, rf), rg)
-> Either Text (ra, rb, rc, rd, re, rf, rg)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd), (re, rf), rg) -> (ra, rb, rc, rd, re, rf, rg)
forall a b c d e f g.
((a, b), (c, d), (e, f), g) -> (a, b, c, d, e, f, g)
to7 (Either Text ((ra, rb), (rc, rd), (re, rf), rg)
-> Either Text (ra, rb, rc, rd, re, rf, rg))
-> ([PersistValue]
-> Either Text ((ra, rb), (rc, rd), (re, rf), rg))
-> [PersistValue]
-> Either Text (ra, rb, rc, rd, re, rf, rg)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue] -> Either Text ((ra, rb), (rc, rd), (re, rf), rg)
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from7P :: Proxy (a,b,c,d,e,f,g) -> Proxy ((a,b),(c,d),(e,f),g)
from7P :: forall a b c d e f g.
Proxy (a, b, c, d, e, f, g) -> Proxy ((a, b), (c, d), (e, f), g)
from7P = Proxy ((a, b), (c, d), (e, f), g)
-> Proxy (a, b, c, d, e, f, g) -> Proxy ((a, b), (c, d), (e, f), g)
forall a b. a -> b -> a
const Proxy ((a, b), (c, d), (e, f), g)
forall {k} (t :: k). Proxy t
Proxy
from7 :: (a,b,c,d,e,f,g) -> ((a,b),(c,d),(e,f),g)
from7 :: forall a b c d e f g.
(a, b, c, d, e, f, g) -> ((a, b), (c, d), (e, f), g)
from7 (a
a,b
b,c
c,d
d,e
e,f
f,g
g) = ((a
a,b
b),(c
c,d
d),(e
e,f
f),g
g)
to7 :: ((a,b),(c,d),(e,f),g) -> (a,b,c,d,e,f,g)
to7 :: forall a b c d e f g.
((a, b), (c, d), (e, f), g) -> (a, b, c, d, e, f, g)
to7 ((a
a,b
b),(c
c,d
d),(e
e,f
f),g
g) = (a
a,b
b,c
c,d
d,e
e,f
f,g
g)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
, SqlSelect e re
, SqlSelect f rf
, SqlSelect g rg
, SqlSelect h rh
) => SqlSelect (a, b, c, d, e, f, g, h) (ra, rb, rc, rd, re, rf, rg, rh) where
sqlSelectCols :: IdentInfo -> (a, b, c, d, e, f, g, h) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
, IdentInfo -> e -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc e
e
, IdentInfo -> f -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc f
f
, IdentInfo -> g -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc g
g
, IdentInfo -> h -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc h
h
]
sqlSelectColCount :: Proxy (a, b, c, d, e, f, g, h) -> Int
sqlSelectColCount = Proxy ((a, b), (c, d), (e, f), (g, h)) -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), (c, d), (e, f), (g, h)) -> Int)
-> (Proxy (a, b, c, d, e, f, g, h)
-> Proxy ((a, b), (c, d), (e, f), (g, h)))
-> Proxy (a, b, c, d, e, f, g, h)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d, e, f, g, h)
-> Proxy ((a, b), (c, d), (e, f), (g, h))
forall a b c d e f g h.
Proxy (a, b, c, d, e, f, g, h)
-> Proxy ((a, b), (c, d), (e, f), (g, h))
from8P
sqlSelectProcessRow :: [PersistValue] -> Either Text (ra, rb, rc, rd, re, rf, rg, rh)
sqlSelectProcessRow = (((ra, rb), (rc, rd), (re, rf), (rg, rh))
-> (ra, rb, rc, rd, re, rf, rg, rh))
-> Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh))
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd), (re, rf), (rg, rh))
-> (ra, rb, rc, rd, re, rf, rg, rh)
forall a b c d e f g h.
((a, b), (c, d), (e, f), (g, h)) -> (a, b, c, d, e, f, g, h)
to8 (Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh))
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh))
-> ([PersistValue]
-> Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh)))
-> [PersistValue]
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue]
-> Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh))
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from8P :: Proxy (a,b,c,d,e,f,g,h) -> Proxy ((a,b),(c,d),(e,f),(g,h))
from8P :: forall a b c d e f g h.
Proxy (a, b, c, d, e, f, g, h)
-> Proxy ((a, b), (c, d), (e, f), (g, h))
from8P = Proxy ((a, b), (c, d), (e, f), (g, h))
-> Proxy (a, b, c, d, e, f, g, h)
-> Proxy ((a, b), (c, d), (e, f), (g, h))
forall a b. a -> b -> a
const Proxy ((a, b), (c, d), (e, f), (g, h))
forall {k} (t :: k). Proxy t
Proxy
from8 :: (a,b,c,d,e,f,g,h) -> ((a,b),(c,d),(e,f),(g,h))
from8 :: forall a b c d e f g h.
(a, b, c, d, e, f, g, h) -> ((a, b), (c, d), (e, f), (g, h))
from8 (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h) = ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h))
to8 :: ((a,b),(c,d),(e,f),(g,h)) -> (a,b,c,d,e,f,g,h)
to8 :: forall a b c d e f g h.
((a, b), (c, d), (e, f), (g, h)) -> (a, b, c, d, e, f, g, h)
to8 ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h)) = (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
, SqlSelect e re
, SqlSelect f rf
, SqlSelect g rg
, SqlSelect h rh
, SqlSelect i ri
) => SqlSelect (a, b, c, d, e, f, g, h, i) (ra, rb, rc, rd, re, rf, rg, rh, ri) where
sqlSelectCols :: IdentInfo
-> (a, b, c, d, e, f, g, h, i) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h, i
i) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
, IdentInfo -> e -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc e
e
, IdentInfo -> f -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc f
f
, IdentInfo -> g -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc g
g
, IdentInfo -> h -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc h
h
, IdentInfo -> i -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc i
i
]
sqlSelectColCount :: Proxy (a, b, c, d, e, f, g, h, i) -> Int
sqlSelectColCount = Proxy ((a, b), (c, d), (e, f), (g, h), i) -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), (c, d), (e, f), (g, h), i) -> Int)
-> (Proxy (a, b, c, d, e, f, g, h, i)
-> Proxy ((a, b), (c, d), (e, f), (g, h), i))
-> Proxy (a, b, c, d, e, f, g, h, i)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d, e, f, g, h, i)
-> Proxy ((a, b), (c, d), (e, f), (g, h), i)
forall a b c d e f g h i.
Proxy (a, b, c, d, e, f, g, h, i)
-> Proxy ((a, b), (c, d), (e, f), (g, h), i)
from9P
sqlSelectProcessRow :: [PersistValue] -> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri)
sqlSelectProcessRow = (((ra, rb), (rc, rd), (re, rf), (rg, rh), ri)
-> (ra, rb, rc, rd, re, rf, rg, rh, ri))
-> Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), ri)
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd), (re, rf), (rg, rh), ri)
-> (ra, rb, rc, rd, re, rf, rg, rh, ri)
forall a b c d e f g h i.
((a, b), (c, d), (e, f), (g, h), i) -> (a, b, c, d, e, f, g, h, i)
to9 (Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), ri)
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri))
-> ([PersistValue]
-> Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), ri))
-> [PersistValue]
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue]
-> Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), ri)
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from9P :: Proxy (a,b,c,d,e,f,g,h,i) -> Proxy ((a,b),(c,d),(e,f),(g,h),i)
from9P :: forall a b c d e f g h i.
Proxy (a, b, c, d, e, f, g, h, i)
-> Proxy ((a, b), (c, d), (e, f), (g, h), i)
from9P = Proxy ((a, b), (c, d), (e, f), (g, h), i)
-> Proxy (a, b, c, d, e, f, g, h, i)
-> Proxy ((a, b), (c, d), (e, f), (g, h), i)
forall a b. a -> b -> a
const Proxy ((a, b), (c, d), (e, f), (g, h), i)
forall {k} (t :: k). Proxy t
Proxy
from9 :: (a,b,c,d,e,f,g,h,i) -> ((a,b),(c,d),(e,f),(g,h),i)
from9 :: forall a b c d e f g h i.
(a, b, c, d, e, f, g, h, i) -> ((a, b), (c, d), (e, f), (g, h), i)
from9 (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i) = ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),i
i)
to9 :: ((a,b),(c,d),(e,f),(g,h),i) -> (a,b,c,d,e,f,g,h,i)
to9 :: forall a b c d e f g h i.
((a, b), (c, d), (e, f), (g, h), i) -> (a, b, c, d, e, f, g, h, i)
to9 ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),i
i) = (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
, SqlSelect e re
, SqlSelect f rf
, SqlSelect g rg
, SqlSelect h rh
, SqlSelect i ri
, SqlSelect j rj
) => SqlSelect (a, b, c, d, e, f, g, h, i, j) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj) where
sqlSelectCols :: IdentInfo
-> (a, b, c, d, e, f, g, h, i, j) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h, i
i, j
j) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
, IdentInfo -> e -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc e
e
, IdentInfo -> f -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc f
f
, IdentInfo -> g -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc g
g
, IdentInfo -> h -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc h
h
, IdentInfo -> i -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc i
i
, IdentInfo -> j -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc j
j
]
sqlSelectColCount :: Proxy (a, b, c, d, e, f, g, h, i, j) -> Int
sqlSelectColCount = Proxy ((a, b), (c, d), (e, f), (g, h), (i, j)) -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), (c, d), (e, f), (g, h), (i, j)) -> Int)
-> (Proxy (a, b, c, d, e, f, g, h, i, j)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j)))
-> Proxy (a, b, c, d, e, f, g, h, i, j)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d, e, f, g, h, i, j)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j))
forall a b c d e f g h i j.
Proxy (a, b, c, d, e, f, g, h, i, j)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j))
from10P
sqlSelectProcessRow :: [PersistValue]
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj)
sqlSelectProcessRow = (((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj))
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj))
-> Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj))
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj))
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj)
forall a b c d e f g h i j.
((a, b), (c, d), (e, f), (g, h), (i, j))
-> (a, b, c, d, e, f, g, h, i, j)
to10 (Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj))
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj))
-> ([PersistValue]
-> Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj)))
-> [PersistValue]
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue]
-> Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj))
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from10P :: Proxy (a,b,c,d,e,f,g,h,i,j) -> Proxy ((a,b),(c,d),(e,f),(g,h),(i,j))
from10P :: forall a b c d e f g h i j.
Proxy (a, b, c, d, e, f, g, h, i, j)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j))
from10P = Proxy ((a, b), (c, d), (e, f), (g, h), (i, j))
-> Proxy (a, b, c, d, e, f, g, h, i, j)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j))
forall a b. a -> b -> a
const Proxy ((a, b), (c, d), (e, f), (g, h), (i, j))
forall {k} (t :: k). Proxy t
Proxy
from10 :: (a,b,c,d,e,f,g,h,i,j) -> ((a,b),(c,d),(e,f),(g,h),(i,j))
from10 :: forall a b c d e f g h i j.
(a, b, c, d, e, f, g, h, i, j)
-> ((a, b), (c, d), (e, f), (g, h), (i, j))
from10 (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j) = ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j))
to10 :: ((a,b),(c,d),(e,f),(g,h),(i,j)) -> (a,b,c,d,e,f,g,h,i,j)
to10 :: forall a b c d e f g h i j.
((a, b), (c, d), (e, f), (g, h), (i, j))
-> (a, b, c, d, e, f, g, h, i, j)
to10 ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j)) = (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
, SqlSelect e re
, SqlSelect f rf
, SqlSelect g rg
, SqlSelect h rh
, SqlSelect i ri
, SqlSelect j rj
, SqlSelect k rk
) => SqlSelect (a, b, c, d, e, f, g, h, i, j, k) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk) where
sqlSelectCols :: IdentInfo
-> (a, b, c, d, e, f, g, h, i, j, k) -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h, i
i, j
j, k
k) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
, IdentInfo -> e -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc e
e
, IdentInfo -> f -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc f
f
, IdentInfo -> g -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc g
g
, IdentInfo -> h -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc h
h
, IdentInfo -> i -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc i
i
, IdentInfo -> j -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc j
j
, IdentInfo -> k -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc k
k
]
sqlSelectColCount :: Proxy (a, b, c, d, e, f, g, h, i, j, k) -> Int
sqlSelectColCount = Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), k) -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), k) -> Int)
-> (Proxy (a, b, c, d, e, f, g, h, i, j, k)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), k))
-> Proxy (a, b, c, d, e, f, g, h, i, j, k)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d, e, f, g, h, i, j, k)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), k)
forall a b c d e f g h i j k.
Proxy (a, b, c, d, e, f, g, h, i, j, k)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), k)
from11P
sqlSelectProcessRow :: [PersistValue]
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk)
sqlSelectProcessRow = (((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), rk)
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk))
-> Either
Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), rk)
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), rk)
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk)
forall a b c d e f g h i j k.
((a, b), (c, d), (e, f), (g, h), (i, j), k)
-> (a, b, c, d, e, f, g, h, i, j, k)
to11 (Either Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), rk)
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk))
-> ([PersistValue]
-> Either
Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), rk))
-> [PersistValue]
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue]
-> Either
Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), rk)
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from11P :: Proxy (a,b,c,d,e,f,g,h,i,j,k) -> Proxy ((a,b),(c,d),(e,f),(g,h),(i,j),k)
from11P :: forall a b c d e f g h i j k.
Proxy (a, b, c, d, e, f, g, h, i, j, k)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), k)
from11P = Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), k)
-> Proxy (a, b, c, d, e, f, g, h, i, j, k)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), k)
forall a b. a -> b -> a
const Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), k)
forall {k} (t :: k). Proxy t
Proxy
from11 :: (a,b,c,d,e,f,g,h,i,j,k) -> ((a,b),(c,d),(e,f),(g,h),(i,j),k)
from11 :: forall a b c d e f g h i j k.
(a, b, c, d, e, f, g, h, i, j, k)
-> ((a, b), (c, d), (e, f), (g, h), (i, j), k)
from11 (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k) = ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j),k
k)
to11 :: ((a,b),(c,d),(e,f),(g,h),(i,j),k) -> (a,b,c,d,e,f,g,h,i,j,k)
to11 :: forall a b c d e f g h i j k.
((a, b), (c, d), (e, f), (g, h), (i, j), k)
-> (a, b, c, d, e, f, g, h, i, j, k)
to11 ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j),k
k) = (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
, SqlSelect e re
, SqlSelect f rf
, SqlSelect g rg
, SqlSelect h rh
, SqlSelect i ri
, SqlSelect j rj
, SqlSelect k rk
, SqlSelect l rl
) => SqlSelect (a, b, c, d, e, f, g, h, i, j, k, l) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl) where
sqlSelectCols :: IdentInfo
-> (a, b, c, d, e, f, g, h, i, j, k, l)
-> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h, i
i, j
j, k
k, l
l) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
, IdentInfo -> e -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc e
e
, IdentInfo -> f -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc f
f
, IdentInfo -> g -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc g
g
, IdentInfo -> h -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc h
h
, IdentInfo -> i -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc i
i
, IdentInfo -> j -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc j
j
, IdentInfo -> k -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc k
k
, IdentInfo -> l -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc l
l
]
sqlSelectColCount :: Proxy (a, b, c, d, e, f, g, h, i, j, k, l) -> Int
sqlSelectColCount = Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l)) -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l)) -> Int)
-> (Proxy (a, b, c, d, e, f, g, h, i, j, k, l)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l)))
-> Proxy (a, b, c, d, e, f, g, h, i, j, k, l)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d, e, f, g, h, i, j, k, l)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l))
forall a b c d e f g h i j k l.
Proxy (a, b, c, d, e, f, g, h, i, j, k, l)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l))
from12P
sqlSelectProcessRow :: [PersistValue]
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl)
sqlSelectProcessRow = (((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl))
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl))
-> Either
Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl))
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl))
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl)
forall a b c d e f g h i j k l.
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l))
-> (a, b, c, d, e, f, g, h, i, j, k, l)
to12 (Either
Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl))
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl))
-> ([PersistValue]
-> Either
Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl)))
-> [PersistValue]
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue]
-> Either
Text ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl))
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from12P :: Proxy (a,b,c,d,e,f,g,h,i,j,k,l) -> Proxy ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l))
from12P :: forall a b c d e f g h i j k l.
Proxy (a, b, c, d, e, f, g, h, i, j, k, l)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l))
from12P = Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l))
-> Proxy (a, b, c, d, e, f, g, h, i, j, k, l)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l))
forall a b. a -> b -> a
const Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l))
forall {k} (t :: k). Proxy t
Proxy
from12 :: (a,b,c,d,e,f,g,h,i,j,k,l) -> ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l))
from12 :: forall a b c d e f g h i j k l.
(a, b, c, d, e, f, g, h, i, j, k, l)
-> ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l))
from12 (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l) = ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j),(k
k,l
l))
to12 :: ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l)) -> (a,b,c,d,e,f,g,h,i,j,k,l)
to12 :: forall a b c d e f g h i j k l.
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l))
-> (a, b, c, d, e, f, g, h, i, j, k, l)
to12 ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j),(k
k,l
l)) = (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
, SqlSelect e re
, SqlSelect f rf
, SqlSelect g rg
, SqlSelect h rh
, SqlSelect i ri
, SqlSelect j rj
, SqlSelect k rk
, SqlSelect l rl
, SqlSelect m rm
) => SqlSelect (a, b, c, d, e, f, g, h, i, j, k, l, m) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm) where
sqlSelectCols :: IdentInfo
-> (a, b, c, d, e, f, g, h, i, j, k, l, m)
-> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h, i
i, j
j, k
k, l
l, m
m) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
, IdentInfo -> e -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc e
e
, IdentInfo -> f -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc f
f
, IdentInfo -> g -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc g
g
, IdentInfo -> h -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc h
h
, IdentInfo -> i -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc i
i
, IdentInfo -> j -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc j
j
, IdentInfo -> k -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc k
k
, IdentInfo -> l -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc l
l
, IdentInfo -> m -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc m
m
]
sqlSelectColCount :: Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Int
sqlSelectColCount = Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m) -> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m) -> Int)
-> (Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m))
-> Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m)
forall a b c d e f g h i j k l m.
Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m)
from13P
sqlSelectProcessRow :: [PersistValue]
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm)
sqlSelectProcessRow = (((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl), rm)
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm))
-> Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl), rm)
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl), rm)
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm)
forall a b c d e f g h i j k l m.
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m)
-> (a, b, c, d, e, f, g, h, i, j, k, l, m)
to13 (Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl), rm)
-> Either
Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm))
-> ([PersistValue]
-> Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl), rm))
-> [PersistValue]
-> Either Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue]
-> Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl), rm)
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from13P :: Proxy (a,b,c,d,e,f,g,h,i,j,k,l,m) -> Proxy ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),m)
from13P :: forall a b c d e f g h i j k l m.
Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m)
from13P = Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m)
-> Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m)
forall a b. a -> b -> a
const Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m)
forall {k} (t :: k). Proxy t
Proxy
from13 :: (a,b,c,d,e,f,g,h,i,j,k,l,m) -> ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),m)
from13 :: forall a b c d e f g h i j k l m.
(a, b, c, d, e, f, g, h, i, j, k, l, m)
-> ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m)
from13 (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m) = ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j),(k
k,l
l),m
m)
to13 :: ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),m) -> (a,b,c,d,e,f,g,h,i,j,k,l,m)
to13 :: forall a b c d e f g h i j k l m.
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), m)
-> (a, b, c, d, e, f, g, h, i, j, k, l, m)
to13 ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j),(k
k,l
l),m
m) = (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
, SqlSelect e re
, SqlSelect f rf
, SqlSelect g rg
, SqlSelect h rh
, SqlSelect i ri
, SqlSelect j rj
, SqlSelect k rk
, SqlSelect l rl
, SqlSelect m rm
, SqlSelect n rn
) => SqlSelect (a, b, c, d, e, f, g, h, i, j, k, l, m, n) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn) where
sqlSelectCols :: IdentInfo
-> (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
-> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h, i
i, j
j, k
k, l
l, m
m, n
n) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
, IdentInfo -> e -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc e
e
, IdentInfo -> f -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc f
f
, IdentInfo -> g -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc g
g
, IdentInfo -> h -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc h
h
, IdentInfo -> i -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc i
i
, IdentInfo -> j -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc j
j
, IdentInfo -> k -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc k
k
, IdentInfo -> l -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc l
l
, IdentInfo -> m -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc m
m
, IdentInfo -> n -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc n
n
]
sqlSelectColCount :: Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Int
sqlSelectColCount = Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n))
-> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n))
-> Int)
-> (Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n)))
-> Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n))
forall a b c d e f g h i j k l m n.
Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n))
from14P
sqlSelectProcessRow :: [PersistValue]
-> Either
Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn)
sqlSelectProcessRow = (((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn))
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn))
-> Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn))
-> Either
Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn))
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn)
forall a b c d e f g h i j k l m n.
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n))
-> (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
to14 (Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn))
-> Either
Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn))
-> ([PersistValue]
-> Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn)))
-> [PersistValue]
-> Either
Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue]
-> Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn))
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from14P :: Proxy (a,b,c,d,e,f,g,h,i,j,k,l,m,n) -> Proxy ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),(m,n))
from14P :: forall a b c d e f g h i j k l m n.
Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n))
from14P = Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n))
-> Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
-> Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n))
forall a b. a -> b -> a
const Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n))
forall {k} (t :: k). Proxy t
Proxy
from14 :: (a,b,c,d,e,f,g,h,i,j,k,l,m,n) -> ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),(m,n))
from14 :: forall a b c d e f g h i j k l m n.
(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
-> ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n))
from14 (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m,n
n) = ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j),(k
k,l
l),(m
m,n
n))
to14 :: ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),(m,n)) -> (a,b,c,d,e,f,g,h,i,j,k,l,m,n)
to14 :: forall a b c d e f g h i j k l m n.
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n))
-> (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
to14 ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j),(k
k,l
l),(m
m,n
n)) = (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m,n
n)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
, SqlSelect e re
, SqlSelect f rf
, SqlSelect g rg
, SqlSelect h rh
, SqlSelect i ri
, SqlSelect j rj
, SqlSelect k rk
, SqlSelect l rl
, SqlSelect m rm
, SqlSelect n rn
, SqlSelect o ro
) => SqlSelect (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro) where
sqlSelectCols :: IdentInfo
-> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
-> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h, i
i, j
j, k
k, l
l, m
m, n
n, o
o) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
, IdentInfo -> e -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc e
e
, IdentInfo -> f -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc f
f
, IdentInfo -> g -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc g
g
, IdentInfo -> h -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc h
h
, IdentInfo -> i -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc i
i
, IdentInfo -> j -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc j
j
, IdentInfo -> k -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc k
k
, IdentInfo -> l -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc l
l
, IdentInfo -> m -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc m
m
, IdentInfo -> n -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc n
n
, IdentInfo -> o -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc o
o
]
sqlSelectColCount :: Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Int
sqlSelectColCount = Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o)
-> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o)
-> Int)
-> (Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
-> Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o))
-> Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
-> Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o)
forall a b c d e f g h i j k l m n o.
Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
-> Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o)
from15P
sqlSelectProcessRow :: [PersistValue]
-> Either
Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro)
sqlSelectProcessRow = (((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn), ro)
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro))
-> Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn), ro)
-> Either
Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn), ro)
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro)
forall a b c d e f g h i j k l m n o.
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o)
-> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
to15 (Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn), ro)
-> Either
Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro))
-> ([PersistValue]
-> Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn), ro))
-> [PersistValue]
-> Either
Text (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue]
-> Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn), ro)
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from15P :: Proxy (a,b,c,d,e,f,g,h,i,j,k,l,m,n, o) -> Proxy ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),(m,n),o)
from15P :: forall a b c d e f g h i j k l m n o.
Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
-> Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o)
from15P = Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o)
-> Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
-> Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o)
forall a b. a -> b -> a
const Proxy ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o)
forall {k} (t :: k). Proxy t
Proxy
from15 :: (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) -> ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),(m,n),o)
from15 :: forall a b c d e f g h i j k l m n o.
(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
-> ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o)
from15 (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m,n
n,o
o) = ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j),(k
k,l
l),(m
m,n
n),o
o)
to15 :: ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),(m,n),o) -> (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)
to15 :: forall a b c d e f g h i j k l m n o.
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), o)
-> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
to15 ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j),(k
k,l
l),(m
m,n
n),o
o) = (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m,n
n,o
o)
instance ( SqlSelect a ra
, SqlSelect b rb
, SqlSelect c rc
, SqlSelect d rd
, SqlSelect e re
, SqlSelect f rf
, SqlSelect g rg
, SqlSelect h rh
, SqlSelect i ri
, SqlSelect j rj
, SqlSelect k rk
, SqlSelect l rl
, SqlSelect m rm
, SqlSelect n rn
, SqlSelect o ro
, SqlSelect p rp
) => SqlSelect (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro, rp) where
sqlSelectCols :: IdentInfo
-> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
-> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h, i
i, j
j, k
k, l
l, m
m, n
n, o
o, p
p) =
[(Builder, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [(Builder, a)] -> (Builder, a)
uncommas'
[ IdentInfo -> a -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc a
a
, IdentInfo -> b -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc b
b
, IdentInfo -> c -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc c
c
, IdentInfo -> d -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc d
d
, IdentInfo -> e -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc e
e
, IdentInfo -> f -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc f
f
, IdentInfo -> g -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc g
g
, IdentInfo -> h -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc h
h
, IdentInfo -> i -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc i
i
, IdentInfo -> j -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc j
j
, IdentInfo -> k -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc k
k
, IdentInfo -> l -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc l
l
, IdentInfo -> m -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc m
m
, IdentInfo -> n -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc n
n
, IdentInfo -> o -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc o
o
, IdentInfo -> p -> (Builder, [PersistValue])
forall a r.
SqlSelect a r =>
IdentInfo -> a -> (Builder, [PersistValue])
sqlSelectCols IdentInfo
esc p
p
]
sqlSelectColCount :: Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) -> Int
sqlSelectColCount = Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p))
-> Int
forall a r. SqlSelect a r => Proxy a -> Int
sqlSelectColCount (Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p))
-> Int)
-> (Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
-> Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p)))
-> Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
-> Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p))
forall a b c d e f g h i j k l m n o p.
Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
-> Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p))
from16P
sqlSelectProcessRow :: [PersistValue]
-> Either
Text
(ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro, rp)
sqlSelectProcessRow = (((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn), (ro, rp))
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro,
rp))
-> Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn), (ro, rp))
-> Either
Text
(ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro, rp)
forall a b. (a -> b) -> Either Text a -> Either Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn), (ro, rp))
-> (ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro, rp)
forall a b c d e f g h i j k l m n o p.
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p))
-> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
to16 (Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn), (ro, rp))
-> Either
Text
(ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro, rp))
-> ([PersistValue]
-> Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn), (ro, rp)))
-> [PersistValue]
-> Either
Text
(ra, rb, rc, rd, re, rf, rg, rh, ri, rj, rk, rl, rm, rn, ro, rp)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PersistValue]
-> Either
Text
((ra, rb), (rc, rd), (re, rf), (rg, rh), (ri, rj), (rk, rl),
(rm, rn), (ro, rp))
forall a r. SqlSelect a r => [PersistValue] -> Either Text r
sqlSelectProcessRow
from16P :: Proxy (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) -> Proxy ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),(m,n),(o,p))
from16P :: forall a b c d e f g h i j k l m n o p.
Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
-> Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p))
from16P = Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p))
-> Proxy (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
-> Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p))
forall a b. a -> b -> a
const Proxy
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p))
forall {k} (t :: k). Proxy t
Proxy
from16 :: (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) -> ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),(m,n),(o,p))
from16 :: forall a b c d e f g h i j k l m n o p.
(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
-> ((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p))
from16 (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m,n
n,o
o,p
p) = ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j),(k
k,l
l),(m
m,n
n),(o
o,p
p))
to16 :: ((a,b),(c,d),(e,f),(g,h),(i,j),(k,l),(m,n),(o,p)) -> (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
to16 :: forall a b c d e f g h i j k l m n o p.
((a, b), (c, d), (e, f), (g, h), (i, j), (k, l), (m, n), (o, p))
-> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
to16 ((a
a,b
b),(c
c,d
d),(e
e,f
f),(g
g,h
h),(i
i,j
j),(k
k,l
l),(m
m,n
n),(o
o,p
p)) = (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j,k
k,l
l,m
m,n
n,o
o,p
p)
insertSelect
:: (MonadIO m, PersistEntity a, SqlBackendCanWrite backend)
=> SqlQuery (SqlExpr (Insertion a))
-> R.ReaderT backend m ()
insertSelect :: forall (m :: * -> *) a backend.
(MonadIO m, PersistEntity a, SqlBackendCanWrite backend) =>
SqlQuery (SqlExpr (Insertion a)) -> ReaderT backend m ()
insertSelect SqlQuery (SqlExpr (Insertion a))
a = ReaderT backend m Int64 -> ReaderT backend m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ReaderT backend m Int64 -> ReaderT backend m ())
-> ReaderT backend m Int64 -> ReaderT backend m ()
forall a b. (a -> b) -> a -> b
$ SqlQuery (SqlExpr (Insertion a)) -> ReaderT backend m Int64
forall (m :: * -> *) a backend.
(MonadIO m, PersistEntity a, SqlBackendCanWrite backend) =>
SqlQuery (SqlExpr (Insertion a)) -> ReaderT backend m Int64
insertSelectCount SqlQuery (SqlExpr (Insertion a))
a
insertSelectCount
:: (MonadIO m, PersistEntity a, SqlBackendCanWrite backend)
=> SqlQuery (SqlExpr (Insertion a))
-> R.ReaderT backend m Int64
insertSelectCount :: forall (m :: * -> *) a backend.
(MonadIO m, PersistEntity a, SqlBackendCanWrite backend) =>
SqlQuery (SqlExpr (Insertion a)) -> ReaderT backend m Int64
insertSelectCount SqlQuery (SqlExpr (Insertion a))
a = Mode -> SqlQuery (SqlExpr (Insertion a)) -> ReaderT backend m Int64
forall (m :: * -> *) a r backend.
(MonadIO m, SqlSelect a r, BackendCompatible SqlBackend backend) =>
Mode -> SqlQuery a -> ReaderT backend m Int64
rawEsqueleto Mode
INSERT_INTO SqlQuery (SqlExpr (Insertion a))
a
renderExpr :: SqlBackend -> SqlExpr (Value Bool) -> T.Text
renderExpr :: SqlBackend -> SqlExpr (Value Bool) -> Text
renderExpr SqlBackend
sqlBackend SqlExpr (Value Bool)
e = case SqlExpr (Value Bool)
e of
ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
mkBuilderValues ->
let (Builder
builder, [PersistValue]
_) = NeedParens -> IdentInfo -> (Builder, [PersistValue])
mkBuilderValues NeedParens
Never (SqlBackend
sqlBackend, IdentState
initialIdentState)
in (Builder -> Text
builderToText Builder
builder)
data RenderExprException = RenderExprUnexpectedECompositeKey T.Text
deriving Int -> RenderExprException -> ShowS
[RenderExprException] -> ShowS
RenderExprException -> String
(Int -> RenderExprException -> ShowS)
-> (RenderExprException -> String)
-> ([RenderExprException] -> ShowS)
-> Show RenderExprException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RenderExprException -> ShowS
showsPrec :: Int -> RenderExprException -> ShowS
$cshow :: RenderExprException -> String
show :: RenderExprException -> String
$cshowList :: [RenderExprException] -> ShowS
showList :: [RenderExprException] -> ShowS
Show
instance Exception RenderExprException
valkey
:: (ToBackendKey SqlBackend entity, PersistField (Key entity))
=> Int64 -> SqlExpr (Value (Key entity))
valkey :: forall entity.
(ToBackendKey SqlBackend entity, PersistField (Key entity)) =>
Int64 -> SqlExpr (Value (Key entity))
valkey = Key entity -> SqlExpr (Value (Key entity))
forall typ. PersistField typ => typ -> SqlExpr (Value typ)
val (Key entity -> SqlExpr (Value (Key entity)))
-> (Int64 -> Key entity) -> Int64 -> SqlExpr (Value (Key entity))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Key entity
forall record.
ToBackendKey SqlBackend record =>
Int64 -> Key record
toSqlKey
valJ
:: (PersistField (Key entity))
=> Value (Key entity)
-> SqlExpr (Value (Key entity))
valJ :: forall entity.
PersistField (Key entity) =>
Value (Key entity) -> SqlExpr (Value (Key entity))
valJ = Key entity -> SqlExpr (Value (Key entity))
forall typ. PersistField typ => typ -> SqlExpr (Value typ)
val (Key entity -> SqlExpr (Value (Key entity)))
-> (Value (Key entity) -> Key entity)
-> Value (Key entity)
-> SqlExpr (Value (Key entity))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value (Key entity) -> Key entity
forall a. Value a -> a
unValue
deleteKey
::
( PersistStore backend
, BaseBackend backend ~ PersistEntityBackend val
, MonadIO m
, PersistEntity val
)
=> Key val
-> R.ReaderT backend m ()
deleteKey :: forall backend val (m :: * -> *).
(PersistStore backend,
BaseBackend backend ~ PersistEntityBackend val, MonadIO m,
PersistEntity val) =>
Key val -> ReaderT backend m ()
deleteKey = Key val -> ReaderT backend m ()
forall backend record (m :: * -> *).
(PersistStoreWrite backend, MonadIO m,
PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
forall record (m :: * -> *).
(MonadIO m, PersistRecordBackend record backend) =>
Key record -> ReaderT backend m ()
Database.Persist.delete
associateJoin
:: forall e1 e0. Ord (Key e0)
=> [(Entity e0, e1)]
-> Map.Map (Key e0) (e0, [e1])
associateJoin :: forall e1 e0.
Ord (Key e0) =>
[(Entity e0, e1)] -> Map (Key e0) (e0, [e1])
associateJoin = ((Entity e0, e1)
-> Map (Key e0) (e0, [e1]) -> Map (Key e0) (e0, [e1]))
-> Map (Key e0) (e0, [e1])
-> [(Entity e0, e1)]
-> Map (Key e0) (e0, [e1])
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Entity e0, e1)
-> Map (Key e0) (e0, [e1]) -> Map (Key e0) (e0, [e1])
forall {a} {a}.
Ord (Key a) =>
(Entity a, a) -> Map (Key a) (a, [a]) -> Map (Key a) (a, [a])
f Map (Key e0) (e0, [e1])
forall {k} {a}. Map k a
start
where
start :: Map k a
start = Map k a
forall {k} {a}. Map k a
Map.empty
f :: (Entity a, a) -> Map (Key a) (a, [a]) -> Map (Key a) (a, [a])
f (Entity a
one, a
many) =
((a, [a]) -> (a, [a]) -> (a, [a]))
-> Key a
-> (a, [a])
-> Map (Key a) (a, [a])
-> Map (Key a) (a, [a])
forall k a. Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
Map.insertWith
(\(a
oneOld, [a]
manyOld) (a
_, [a]
manyNew) -> (a
oneOld, [a]
manyNew [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a]
manyOld ))
(Entity a -> Key a
forall record. Entity record -> Key record
entityKey Entity a
one)
(Entity a -> a
forall record. Entity record -> record
entityVal Entity a
one, [a
many])