{-# LANGUAGE CPP #-}
{-# language DerivingStrategies, GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
module Database.Esqueleto.Internal.Internal where
import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.List.NonEmpty as NEL
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 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 qualified Data.Conduit as C
import qualified Data.Conduit.List as CL
import qualified Data.HashSet as HS
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.SqlBackend
import qualified Database.Persist
import Database.Persist (FieldNameDB(..), EntityNameDB(..))
import Database.Persist.Sql.Util
( entityColumnCount
, keyAndEntityColumnNames
, isIdField
, parseEntityValues
)
import Text.Blaze.Html (Html)
import Data.Coerce (coerce)
import Data.Kind (Type)
fromStart
:: forall a.
( PersistEntity a
, BackendCompatible SqlBackend (PersistEntityBackend a)
)
=> SqlQuery (PreprocessedFrom (SqlExpr (Entity a)))
fromStart :: SqlQuery (PreprocessedFrom (SqlExpr (Entity a)))
fromStart = do
let ed :: EntityDef
ed = Proxy a -> EntityDef
forall record (proxy :: * -> *).
PersistEntity record =>
proxy record -> EntityDef
entityDef (Proxy a
forall k (t :: k). Proxy t
Proxy :: Proxy a)
Ident
ident <- DBName -> SqlQuery Ident
newIdentFor (EntityNameDB -> DBName
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 (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 :: 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 :: 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))
coerce SqlExpr (Entity a)
e) FromClause
f'
fromJoin
:: IsJoinKind join
=> PreprocessedFrom a
-> PreprocessedFrom b
-> SqlQuery (PreprocessedFrom (join a b))
fromJoin :: PreprocessedFrom a
-> PreprocessedFrom b -> SqlQuery (PreprocessedFrom (join a b))
fromJoin (PreprocessedFrom a
lhsRet FromClause
lhsFrom)
(PreprocessedFrom b
rhsRet FromClause
rhsFrom) = WriterT SideData (State IdentState) (PreprocessedFrom (join a b))
-> SqlQuery (PreprocessedFrom (join a b))
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (WriterT SideData (State IdentState) (PreprocessedFrom (join a b))
-> SqlQuery (PreprocessedFrom (join a b)))
-> WriterT
SideData (State IdentState) (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 (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 (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 (State IdentState) (PreprocessedFrom (join a b))
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 :: PreprocessedFrom a -> SqlQuery a
fromFinish (PreprocessedFrom a
ret FromClause
f') = WriterT SideData (State IdentState) a -> SqlQuery a
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (WriterT SideData (State IdentState) a -> SqlQuery a)
-> WriterT SideData (State IdentState) a -> SqlQuery a
forall a b. (a -> b) -> a -> b
$ do
SideData -> WriterT SideData (State IdentState) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdFromClause :: [FromClause]
sdFromClause = [FromClause
f'] }
a -> WriterT SideData (State IdentState) 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 (State IdentState) () -> SqlQuery ()
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (WriterT SideData (State IdentState) () -> SqlQuery ())
-> WriterT SideData (State IdentState) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (State IdentState) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdWhereClause :: WhereClause
sdWhereClause = SqlExpr (Value Bool) -> WhereClause
Where SqlExpr (Value Bool)
expr }
on :: SqlExpr (Value Bool) -> SqlQuery ()
on :: SqlExpr (Value Bool) -> SqlQuery ()
on SqlExpr (Value Bool)
expr = WriterT SideData (State IdentState) () -> SqlQuery ()
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (WriterT SideData (State IdentState) () -> SqlQuery ())
-> WriterT SideData (State IdentState) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (State IdentState) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdFromClause :: [FromClause]
sdFromClause = [SqlExpr (Value Bool) -> FromClause
OnClause SqlExpr (Value Bool)
expr] }
groupBy :: (ToSomeValues a) => a -> SqlQuery ()
groupBy :: a -> SqlQuery ()
groupBy a
expr = WriterT SideData (State IdentState) () -> SqlQuery ()
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (WriterT SideData (State IdentState) () -> SqlQuery ())
-> WriterT SideData (State IdentState) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (State IdentState) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdGroupByClause :: GroupByClause
sdGroupByClause = [SomeValue] -> GroupByClause
GroupBy ([SomeValue] -> GroupByClause) -> [SomeValue] -> GroupByClause
forall a b. (a -> b) -> a -> b
$ a -> [SomeValue]
forall a. ToSomeValues a => a -> [SomeValue]
toSomeValues a
expr }
orderBy :: [SqlExpr OrderBy] -> SqlQuery ()
orderBy :: [SqlExpr OrderBy] -> SqlQuery ()
orderBy [SqlExpr OrderBy]
exprs = WriterT SideData (State IdentState) () -> SqlQuery ()
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (WriterT SideData (State IdentState) () -> SqlQuery ())
-> WriterT SideData (State IdentState) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (State IdentState) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdOrderByClause :: [SqlExpr OrderBy]
sdOrderByClause = [SqlExpr OrderBy]
exprs }
asc :: PersistField a => SqlExpr (Value a) -> SqlExpr OrderBy
asc :: 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 :: 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 :: 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 (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 (State IdentState) () -> SqlQuery ()
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (WriterT SideData (State IdentState) () -> SqlQuery ())
-> WriterT SideData (State IdentState) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (State IdentState) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdLimitClause :: LimitClause
sdLimitClause = Maybe Int64 -> Maybe Int64 -> LimitClause
Limit (Int64 -> Maybe Int64
forall a. a -> Maybe a
Just Int64
n) Maybe Int64
forall a. Maybe a
Nothing }
offset :: Int64 -> SqlQuery ()
offset :: Int64 -> SqlQuery ()
offset Int64
n = WriterT SideData (State IdentState) () -> SqlQuery ()
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (WriterT SideData (State IdentState) () -> SqlQuery ())
-> WriterT SideData (State IdentState) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (State IdentState) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdLimitClause :: LimitClause
sdLimitClause = Maybe Int64 -> Maybe Int64 -> LimitClause
Limit Maybe Int64
forall a. Maybe a
Nothing (Int64 -> Maybe Int64
forall a. a -> Maybe a
Just Int64
n) }
distinct :: SqlQuery a -> SqlQuery a
distinct :: SqlQuery a -> SqlQuery a
distinct SqlQuery a
act = WriterT SideData (State IdentState) () -> SqlQuery ()
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (SideData -> WriterT SideData (State IdentState) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdDistinctClause :: DistinctClause
sdDistinctClause = DistinctClause
DistinctStandard }) SqlQuery () -> SqlQuery a -> SqlQuery a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SqlQuery a
act
distinctOn :: [SqlExpr DistinctOn] -> SqlQuery a -> SqlQuery a
distinctOn :: [SqlExpr DistinctOn] -> SqlQuery a -> SqlQuery a
distinctOn [SqlExpr DistinctOn]
exprs SqlQuery a
act = WriterT SideData (State IdentState) () -> SqlQuery ()
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (SideData -> WriterT SideData (State IdentState) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdDistinctClause :: DistinctClause
sdDistinctClause = [SqlExpr DistinctOn] -> DistinctClause
DistinctOn [SqlExpr DistinctOn]
exprs }) SqlQuery () -> SqlQuery a -> SqlQuery a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SqlQuery a
act
don :: SqlExpr (Value a) -> SqlExpr DistinctOn
don :: SqlExpr (Value a) -> SqlExpr DistinctOn
don = SqlExpr (Value a) -> SqlExpr DistinctOn
coerce
distinctOnOrderBy :: [SqlExpr OrderBy] -> SqlQuery a -> SqlQuery a
distinctOnOrderBy :: [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
$ Text -> Text -> Text -> Text
TL.replace Text
" DESC" Text
""
(Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ 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 (State IdentState) () -> SqlQuery ()
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (WriterT SideData (State IdentState) () -> SqlQuery ())
-> WriterT SideData (State IdentState) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (State IdentState) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdHavingClause :: WhereClause
sdHavingClause = SqlExpr (Value Bool) -> WhereClause
Where SqlExpr (Value Bool)
expr }
locking :: LockingKind -> SqlQuery ()
locking :: LockingKind -> SqlQuery ()
locking LockingKind
kind = WriterT SideData (State IdentState) () -> SqlQuery ()
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (WriterT SideData (State IdentState) () -> SqlQuery ())
-> WriterT SideData (State IdentState) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (State IdentState) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdLockingClause :: LockingClause
sdLockingClause = Maybe LockingKind -> LockingClause
forall a. Maybe a -> Last a
Monoid.Last (LockingKind -> Maybe LockingKind
forall a. a -> Maybe a
Just LockingKind
kind) }
{-#
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 :: 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 :: 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 (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 :: 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 :: 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 (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 :: 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 :: 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 (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 :: 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 ^. :: 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
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
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 :: Maybe (IdentInfo -> [Builder])
sqlExprMetaCompositeFields = (IdentInfo -> [Builder]) -> Maybe (IdentInfo -> [Builder])
forall a. a -> Maybe a
Just IdentInfo -> [Builder]
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
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 (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
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 :: 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 ?. :: 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 :: 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 :: 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 (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 (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 :: (Builder, a) -> (Builder, a)
isNullExpr = (Builder -> Builder) -> (Builder, a) -> (Builder, a)
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"))
just :: SqlExpr (Value typ) -> SqlExpr (Value (Maybe typ))
just :: 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 :: 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 :: 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 :: 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 :: (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 (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 :: 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 :: 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 :: 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 (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)
==. :: 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)
>=. :: 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)
>. :: 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)
<=. :: 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)
<. :: 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)
!=. :: 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)
+. :: 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)
-. :: 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)
/. :: 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)
*. :: 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 :: 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_ :: 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_ :: 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_ :: 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_ :: 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_ :: 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_ :: 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_ :: 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_ :: 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 :: 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 :: 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 :: [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 :: [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 (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_ :: 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_ :: 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_ :: 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_ :: 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_ :: 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_ :: 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_ :: (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_ :: (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 :: 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 :: 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)
% :: 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_ :: [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)
++. :: 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 :: 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 :: 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 (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 :: [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 (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 :: 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_ :: 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 :: 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 :: SqlExpr (Entity val)
-> [SqlExpr (Entity val) -> SqlExpr Update] -> SqlQuery ()
set SqlExpr (Entity val)
ent [SqlExpr (Entity val) -> SqlExpr Update]
upds = WriterT SideData (State IdentState) () -> SqlQuery ()
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (WriterT SideData (State IdentState) () -> SqlQuery ())
-> WriterT SideData (State IdentState) () -> SqlQuery ()
forall a b. (a -> b) -> a -> b
$ SideData -> WriterT SideData (State IdentState) ()
forall (m :: * -> *) w. Monad m => w -> WriterT w m ()
W.tell SideData
forall a. Monoid a => a
mempty { sdSetClause :: [SetClause]
sdSetClause = ((SqlExpr (Entity val) -> SqlExpr Update) -> SetClause)
-> [SqlExpr (Entity val) -> SqlExpr Update] -> [SetClause]
forall a b. (a -> b) -> [a] -> [b]
map (SqlExpr (Entity val) -> SqlExpr Update) -> SetClause
apply [SqlExpr (Entity val) -> SqlExpr Update]
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 =. :: 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 +=. :: EntityField val a
-> SqlExpr (Value a) -> 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 -=. :: EntityField val a
-> SqlExpr (Value a) -> 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 *=. :: EntityField val a
-> SqlExpr (Value a) -> 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 /=. :: EntityField val a
-> SqlExpr (Value a) -> 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)
<# :: (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) <&> :: 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_ :: [(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 :: 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_ :: 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_ :: expr a -> expr a
else_ = expr a -> expr a
forall a. a -> a
id
newtype Value a = Value { 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
/= :: Value a -> Value a -> Bool
$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
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
min :: Value a -> Value a -> Value a
$cmin :: forall a. Ord a => Value a -> Value a -> Value a
max :: Value a -> Value a -> Value a
$cmax :: forall a. Ord a => Value a -> Value a -> Value a
>= :: 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
$c< :: forall a. Ord a => Value a -> Value a -> Bool
compare :: Value a -> Value a -> Ordering
$ccompare :: forall a. Ord a => Value a -> Value a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (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
showList :: [Value a] -> ShowS
$cshowList :: forall a. Show a => [Value a] -> ShowS
show :: Value a -> String
$cshow :: forall a. Show a => Value a -> String
showsPrec :: Int -> Value a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Value a -> ShowS
Show, Typeable)
instance Functor Value where
fmap :: (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
<*> :: 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 :: a -> Value a
pure = a -> Value a
forall a. a -> Value a
Value
instance Monad Value where
>>= :: 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 (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
/= :: ValueList a -> ValueList a -> Bool
$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
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
min :: ValueList a -> ValueList a -> ValueList a
$cmin :: forall a. Ord a => ValueList a -> ValueList a -> ValueList a
max :: ValueList a -> ValueList a -> ValueList a
$cmax :: forall a. Ord a => ValueList a -> ValueList a -> ValueList a
>= :: 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
$c< :: forall a. Ord a => ValueList a -> ValueList a -> Bool
compare :: ValueList a -> ValueList a -> Ordering
$ccompare :: forall a. Ord a => ValueList a -> ValueList a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (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
showList :: [ValueList a] -> ShowS
$cshowList :: forall a. Show a => [ValueList a] -> ShowS
show :: ValueList a -> String
$cshow :: forall a. Show a => ValueList a -> String
showsPrec :: Int -> ValueList a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> 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 -> 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 :: 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. [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
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 :: 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 :: (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
/= :: JoinKind -> JoinKind -> Bool
$c/= :: JoinKind -> JoinKind -> Bool
== :: JoinKind -> JoinKind -> Bool
$c== :: 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
showList :: [JoinKind] -> ShowS
$cshowList :: [JoinKind] -> ShowS
show :: JoinKind -> String
$cshow :: JoinKind -> String
showsPrec :: Int -> JoinKind -> ShowS
$cshowsPrec :: Int -> JoinKind -> ShowS
Show)
class IsJoinKind join where
smartJoin :: a -> b -> join a b
reifyJoinKind :: join a b -> JoinKind
instance IsJoinKind InnerJoin where
smartJoin :: 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 :: InnerJoin a b -> JoinKind
reifyJoinKind InnerJoin a b
_ = JoinKind
InnerJoinKind
instance IsJoinKind CrossJoin where
smartJoin :: 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 :: CrossJoin a b -> JoinKind
reifyJoinKind CrossJoin a b
_ = JoinKind
CrossJoinKind
instance IsJoinKind LeftOuterJoin where
smartJoin :: 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 :: LeftOuterJoin a b -> JoinKind
reifyJoinKind LeftOuterJoin a b
_ = JoinKind
LeftOuterJoinKind
instance IsJoinKind RightOuterJoin where
smartJoin :: 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 :: RightOuterJoin a b -> JoinKind
reifyJoinKind RightOuterJoin a b
_ = JoinKind
RightOuterJoinKind
instance IsJoinKind FullOuterJoin where
smartJoin :: 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 :: 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
/= :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
$c/= :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
== :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
$c== :: 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
min :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
$cmin :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
max :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
$cmax :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException
>= :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Bool
$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
compare :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Ordering
$ccompare :: OnClauseWithoutMatchingJoinException
-> OnClauseWithoutMatchingJoinException -> Ordering
$cp1Ord :: Eq 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
showList :: [OnClauseWithoutMatchingJoinException] -> ShowS
$cshowList :: [OnClauseWithoutMatchingJoinException] -> ShowS
show :: OnClauseWithoutMatchingJoinException -> String
$cshow :: OnClauseWithoutMatchingJoinException -> String
showsPrec :: Int -> OnClauseWithoutMatchingJoinException -> ShowS
$cshowsPrec :: Int -> OnClauseWithoutMatchingJoinException -> ShowS
Show, Typeable)
instance Exception OnClauseWithoutMatchingJoinException
data OrderBy
data DistinctOn
data Update
data Insertion a
data LockingKind
= ForUpdate
| ForUpdateSkipLocked
| ForShare
| LockInShareMode
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 :: (a -> SqlQuery b) -> SqlQuery b
from = (SqlQuery a
forall a. From a => SqlQuery a
from_ 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 val.
(PersistEntity val,
BackendCompatible SqlBackend (PersistEntityBackend val)) =>
SqlQuery (PreprocessedFrom (SqlExpr (Maybe (Entity val))))
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
showList :: [EsqueletoError] -> ShowS
$cshowList :: [EsqueletoError] -> ShowS
show :: EsqueletoError -> String
$cshow :: EsqueletoError -> String
showsPrec :: Int -> EsqueletoError -> ShowS
$cshowsPrec :: Int -> 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
showList :: [CompositeKeyError] -> ShowS
$cshowList :: [CompositeKeyError] -> ShowS
show :: CompositeKeyError -> String
$cshow :: CompositeKeyError -> String
showsPrec :: Int -> CompositeKeyError -> ShowS
$cshowsPrec :: Int -> 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
showList :: [UnexpectedCaseError] -> ShowS
$cshowList :: [UnexpectedCaseError] -> ShowS
show :: UnexpectedCaseError -> String
$cshow :: UnexpectedCaseError -> String
showsPrec :: Int -> UnexpectedCaseError -> ShowS
$cshowsPrec :: Int -> 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
showList :: [SqlBinOpCompositeError] -> ShowS
$cshowList :: [SqlBinOpCompositeError] -> ShowS
show :: SqlBinOpCompositeError -> String
$cshow :: SqlBinOpCompositeError -> String
showsPrec :: Int -> SqlBinOpCompositeError -> ShowS
$cshowsPrec :: Int -> SqlBinOpCompositeError -> ShowS
Show)
newtype SqlQuery a = Q { SqlQuery a -> WriterT SideData (State IdentState) a
unQ :: W.WriterT SideData (S.State IdentState) a }
deriving newtype (a -> SqlQuery b -> SqlQuery a
(a -> b) -> SqlQuery a -> SqlQuery b
(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
<$ :: a -> SqlQuery b -> SqlQuery a
$c<$ :: forall a b. a -> SqlQuery b -> SqlQuery a
fmap :: (a -> b) -> SqlQuery a -> SqlQuery b
$cfmap :: forall a b. (a -> b) -> SqlQuery a -> SqlQuery b
Functor, Functor SqlQuery
a -> SqlQuery a
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
SqlQuery a -> SqlQuery b -> SqlQuery b
SqlQuery a -> SqlQuery b -> SqlQuery a
SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
(a -> b -> c) -> SqlQuery a -> SqlQuery b -> SqlQuery c
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
<* :: SqlQuery a -> SqlQuery b -> SqlQuery a
$c<* :: forall a b. SqlQuery a -> SqlQuery b -> SqlQuery a
*> :: SqlQuery a -> SqlQuery b -> SqlQuery b
$c*> :: forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b
liftA2 :: (a -> b -> c) -> SqlQuery a -> SqlQuery b -> SqlQuery c
$cliftA2 :: forall a b c.
(a -> b -> c) -> SqlQuery a -> SqlQuery b -> SqlQuery c
<*> :: SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
$c<*> :: forall a b. SqlQuery (a -> b) -> SqlQuery a -> SqlQuery b
pure :: a -> SqlQuery a
$cpure :: forall a. a -> SqlQuery a
$cp1Applicative :: Functor SqlQuery
Applicative, Applicative SqlQuery
a -> SqlQuery a
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
SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
SqlQuery a -> SqlQuery b -> SqlQuery b
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
return :: a -> SqlQuery a
$creturn :: forall a. a -> SqlQuery a
>> :: SqlQuery a -> SqlQuery b -> SqlQuery b
$c>> :: forall a b. SqlQuery a -> SqlQuery b -> SqlQuery b
>>= :: SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
$c>>= :: forall a b. SqlQuery a -> (a -> SqlQuery b) -> SqlQuery b
$cp1Monad :: Applicative SqlQuery
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
/= :: CommonTableExpressionKind -> CommonTableExpressionKind -> Bool
$c/= :: CommonTableExpressionKind -> CommonTableExpressionKind -> Bool
== :: CommonTableExpressionKind -> CommonTableExpressionKind -> Bool
$c== :: 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
showList :: [SubQueryType] -> ShowS
$cshowList :: [SubQueryType] -> ShowS
show :: SubQueryType -> String
$cshow :: SubQueryType -> String
showsPrec :: Int -> SubQueryType -> ShowS
$cshowsPrec :: Int -> 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 :: (Text -> IO Statement)
-> (EntityDef -> [PersistValue] -> InsertSqlResult)
-> IORef (Map Text Statement)
-> IO ()
-> ([EntityDef]
-> (Text -> IO Statement)
-> EntityDef
-> IO (Either [Text] [(Bool, Text)]))
-> ((Text -> IO Statement) -> Maybe IsolationLevel -> IO ())
-> ((Text -> IO Statement) -> IO ())
-> ((Text -> IO Statement) -> IO ())
-> (FieldNameDB -> Text)
-> (EntityDef -> Text)
-> (Text -> Text)
-> Text
-> Text
-> ((Int, Int) -> Text -> Text)
-> LogFunc
-> MkSqlBackendArgs
MkSqlBackendArgs
{ connEscapeRawName :: Text -> Text
connEscapeRawName = Text -> Text
forall a. a -> a
id
}
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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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
/= :: LimitClause -> LimitClause -> Bool
$c/= :: LimitClause -> LimitClause -> Bool
== :: LimitClause -> LimitClause -> Bool
$c== :: 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 (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` Maybe Int64
l1) (Maybe Int64
o2 Maybe Int64 -> Maybe Int64 -> Maybe Int64
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 (m :: * -> *) a. MonadPlus m => m a
mzero Maybe Int64
forall (m :: * -> *) a. MonadPlus m => m a
mzero
mappend :: LimitClause -> LimitClause -> LimitClause
mappend = LimitClause -> LimitClause -> LimitClause
forall a. Semigroup a => a -> a -> a
(<>)
type LockingClause = Monoid.Last LockingKind
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
/= :: Ident -> Ident -> Bool
$c/= :: Ident -> Ident -> Bool
== :: Ident -> Ident -> Bool
$c== :: 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
min :: Ident -> Ident -> Ident
$cmin :: Ident -> Ident -> Ident
max :: Ident -> Ident -> Ident
$cmax :: Ident -> Ident -> Ident
>= :: Ident -> Ident -> Bool
$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
compare :: Ident -> Ident -> Ordering
$ccompare :: Ident -> Ident -> Ordering
$cp1Ord :: Eq 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
showList :: [Ident] -> ShowS
$cshowList :: [Ident] -> ShowS
show :: Ident -> String
$cshow :: Ident -> String
showsPrec :: Int -> Ident -> ShowS
$cshowsPrec :: Int -> 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 (State IdentState) Ident -> SqlQuery Ident
forall a. WriterT SideData (State IdentState) a -> SqlQuery a
Q (WriterT SideData (State IdentState) Ident -> SqlQuery Ident)
-> WriterT SideData (State IdentState) Ident -> SqlQuery Ident
forall a b. (a -> b) -> a -> b
$ StateT IdentState Identity Ident
-> WriterT SideData (State IdentState) Ident
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (StateT IdentState Identity Ident
-> WriterT SideData (State IdentState) Ident)
-> StateT IdentState Identity Ident
-> WriterT SideData (State IdentState) Ident
forall a b. (a -> b) -> a -> b
$ Maybe Int -> StateT IdentState Identity Ident
findFree Maybe Int
forall a. Maybe a
Nothing
where
findFree :: Maybe Int -> StateT IdentState Identity 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 -> StateT IdentState Identity 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 (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 :: HashSet Text
inUse = Text -> HashSet Text -> HashSet Text
forall a. (Eq a, Hashable a) => a -> HashSet a -> HashSet a
HS.insert Text
withSuffix (IdentState -> HashSet Text
inUse IdentState
s) })
Ident -> StateT IdentState Identity Ident
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 :: Maybe (IdentInfo -> [Builder])
-> Maybe Ident -> Bool -> SqlExprMeta
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 :: SqlExpr (Entity val) -> SqlExpr (Value (Entity val))
entityAsValue = SqlExpr (Entity val) -> SqlExpr (Value (Entity val))
coerce
entityAsValueMaybe
:: SqlExpr (Maybe (Entity val))
-> SqlExpr (Value (Maybe (Entity val)))
entityAsValueMaybe :: SqlExpr (Maybe (Entity val))
-> SqlExpr (Value (Maybe (Entity val)))
entityAsValueMaybe = SqlExpr (Maybe (Entity val))
-> SqlExpr (Value (Maybe (Entity val)))
coerce
data SqlExpr a = ERaw SqlExprMeta (NeedParens -> IdentInfo -> (TLB.Builder, [PersistValue]))
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
/= :: NeedParens -> NeedParens -> Bool
$c/= :: NeedParens -> NeedParens -> Bool
== :: NeedParens -> NeedParens -> Bool
$c== :: 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 :: 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
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
persistFieldDef
setAux
:: (PersistEntity val, PersistField typ)
=> EntityField val typ
-> (SqlExpr (Entity val) -> SqlExpr (Value typ))
-> (SqlExpr (Entity val) -> SqlExpr Update)
setAux :: 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 :: 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 (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 (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SqlExpr (Value Bool) -> SqlQuery (SqlExpr (Value Bool))
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 :: [(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 :: [(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 (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 :: 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 :: 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 :: 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 :: 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 (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 (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 :: 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 :: 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 :: 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 (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
<$> 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 (t :: * -> *) a. Foldable t => t a -> Bool
null [PersistValue]
v1 Bool -> Bool -> Bool
|| [PersistValue] -> 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 (t :: * -> *) a. Foldable t => t a -> Int
length [Builder]
b1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= [Builder] -> 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 :: 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 :: 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 :: 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 :: 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 :: 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 :: 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 (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 (Value b) -> SqlExpr (Value ()))
-> SqlExpr (Value b)
-> [SqlExpr (Value ())]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 :: SqlExpr (Value a) -> SqlExpr (Value b)
veryUnsafeCoerceSqlExprValue = SqlExpr (Value a) -> SqlExpr (Value b)
coerce
veryUnsafeCoerceSqlExprValueList :: SqlExpr (ValueList a) -> SqlExpr (Value a)
veryUnsafeCoerceSqlExprValueList :: SqlExpr (ValueList a) -> SqlExpr (Value a)
veryUnsafeCoerceSqlExprValueList = SqlExpr (ValueList a) -> SqlExpr (Value a)
coerce
rawSelectSource
::
( SqlSelect a r
, MonadIO m1
, MonadIO m2
)
=> Mode
-> SqlQuery a
-> SqlReadT m1 (Acquire (C.ConduitT () r m2 ()))
rawSelectSource :: Mode -> SqlQuery a -> SqlReadT 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 (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 ()
-> ConduitM [PersistValue] r m2 () -> ConduitT () r m2 ()
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
C..| ConduitM [PersistValue] r m2 ()
massage) (ConduitM () [PersistValue] m2 () -> ConduitT () r m2 ())
-> Acquire (ConduitM () [PersistValue] m2 ())
-> Acquire (ConduitT () r m2 ())
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 (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 :: ConduitM [PersistValue] r m2 ()
massage = do
Maybe [PersistValue]
mrow <- ConduitT [PersistValue] r m2 (Maybe [PersistValue])
forall (m :: * -> *) i. Monad m => Consumer i 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 -> ConduitM [PersistValue] r m2 ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
C.yield r
r ConduitM [PersistValue] r m2 ()
-> ConduitM [PersistValue] r m2 ()
-> ConduitM [PersistValue] r m2 ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitM [PersistValue] r m2 ()
massage
Just (Left Text
err) -> IO () -> ConduitM [PersistValue] r m2 ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ConduitM [PersistValue] r m2 ())
-> IO () -> ConduitM [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 -> () -> ConduitM [PersistValue] r m2 ()
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 :: 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 (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
-> SqlReadT m (Acquire (ConduitT () r (ReaderT backend m) ()))
forall a r (m1 :: * -> *) (m2 :: * -> *).
(SqlSelect a r, MonadIO m1, MonadIO m2) =>
Mode -> SqlQuery a -> SqlReadT 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 (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 (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
)
=> SqlQuery a
-> SqlReadT m [r]
select :: SqlQuery a -> SqlReadT m [r]
select SqlQuery a
query = do
Acquire (ConduitT () r (ReaderT backend IO) ())
res <- Mode
-> SqlQuery a
-> SqlReadT m (Acquire (ConduitT () r (ReaderT backend IO) ()))
forall a r (m1 :: * -> *) (m2 :: * -> *).
(SqlSelect a r, MonadIO m1, MonadIO m2) =>
Mode -> SqlQuery a -> SqlReadT 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 (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) => SqlQuery a -> SqlReadT m (Maybe r)
selectOne :: SqlQuery a -> SqlReadT m (Maybe r)
selectOne SqlQuery a
query = ([r] -> Maybe r)
-> ReaderT backend m [r] -> ReaderT backend m (Maybe r)
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 -> SqlReadT m [r]
forall a r (m :: * -> *).
(SqlSelect a r, MonadIO m) =>
SqlQuery a -> SqlReadT m [r]
select (SqlQuery a -> SqlReadT m [r]) -> SqlQuery a -> SqlReadT m [r]
forall a b. (a -> b) -> a -> b
$ Int64 -> SqlQuery ()
limit Int64
1 SqlQuery () -> SqlQuery a -> SqlQuery a
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 :: 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) ()
-> ConduitM r Void (ReaderT backend m) [r]
-> ConduitT () Void (ReaderT backend m) [r]
forall (m :: * -> *) a b c r.
Monad m =>
ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
C..| ConduitM 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 :: 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 (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)
=> SqlQuery ()
-> SqlWriteT m ()
delete :: SqlQuery () -> SqlWriteT 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 () -> SqlWriteT m Int64
forall (m :: * -> *). MonadIO m => SqlQuery () -> SqlWriteT m Int64
deleteCount SqlQuery ()
a
deleteCount
:: (MonadIO m)
=> SqlQuery ()
-> SqlWriteT m Int64
deleteCount :: SqlQuery () -> SqlWriteT 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)
)
=> (SqlExpr (Entity val) -> SqlQuery ())
-> SqlWriteT m ()
update :: (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT 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 ()) -> SqlWriteT m Int64
forall (m :: * -> *) val.
(MonadIO m, PersistEntity val,
BackendCompatible SqlBackend (PersistEntityBackend val)) =>
(SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m Int64
updateCount SqlExpr (Entity val) -> SqlQuery ()
a
updateCount
::
( MonadIO m, PersistEntity val
, BackendCompatible SqlBackend (PersistEntityBackend val)
)
=> (SqlExpr (Entity val) -> SqlQuery ())
-> SqlWriteT m Int64
updateCount :: (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT 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 :: 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 (State IdentState) a
-> State IdentState (a, SideData)
forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
W.runWriterT (WriterT SideData (State IdentState) a
-> State IdentState (a, SideData))
-> WriterT SideData (State IdentState) a
-> State IdentState (a, SideData)
forall a b. (a -> b) -> a -> b
$
SqlQuery a -> WriterT SideData (State IdentState) a
forall a. SqlQuery a -> WriterT SideData (State IdentState) a
unQ SqlQuery a
query
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, [PersistValue])] -> (Builder, [PersistValue])
forall a. Monoid a => [a] -> a
mconcat
[ 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
, LockingClause -> (Builder, [PersistValue])
makeLocking LockingClause
lockingClause
]
renderQueryToText
:: (SqlSelect a r, BackendCompatible SqlBackend backend, Monad m)
=> Mode
-> SqlQuery a
-> R.ReaderT backend m (T.Text, [PersistValue])
renderQueryToText :: 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 (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 :: 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 :: 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 :: 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 :: 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' :: [(Builder, a)] -> (Builder, a)
uncommas' = ([Builder] -> Builder
uncommas ([Builder] -> Builder)
-> ([a] -> a) -> ([Builder], [a]) -> (Builder, a)
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 (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 (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 (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 (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 (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 :: 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 :: 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 (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)
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 (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 (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 p. IsString p => JoinKind -> p
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
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 -> p
fromKind JoinKind
InnerJoinKind = p
" INNER JOIN "
fromKind JoinKind
CrossJoinKind = p
" CROSS JOIN "
fromKind JoinKind
LeftOuterJoinKind = p
" LEFT OUTER JOIN "
fromKind JoinKind
RightOuterJoinKind = p
" RIGHT OUTER JOIN "
fromKind JoinKind
FullOuterJoinKind = p
" FULL OUTER JOIN "
makeOnClause :: SqlExpr (Value Bool) -> (Builder, [PersistValue])
makeOnClause (ERaw SqlExprMeta
_ NeedParens -> IdentInfo -> (Builder, [PersistValue])
f) = (Builder -> Builder)
-> (Builder, [PersistValue]) -> (Builder, [PersistValue])
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 (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 (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 (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 (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 (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
"\n" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> 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
"\n" 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 :: LockingClause -> (TLB.Builder, [PersistValue])
makeLocking :: LockingClause -> (Builder, [PersistValue])
makeLocking = (Builder -> [PersistValue] -> (Builder, [PersistValue]))
-> [PersistValue] -> Builder -> (Builder, [PersistValue])
forall a b c. (a -> b -> c) -> b -> a -> c
flip (,) [] (Builder -> (Builder, [PersistValue]))
-> (LockingClause -> Builder)
-> LockingClause
-> (Builder, [PersistValue])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> (LockingKind -> Builder) -> Maybe LockingKind -> Builder
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Builder
forall a. Monoid a => a
mempty LockingKind -> Builder
forall p. IsString p => LockingKind -> p
toTLB (Maybe LockingKind -> Builder)
-> (LockingClause -> Maybe LockingKind) -> LockingClause -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LockingClause -> Maybe LockingKind
forall a. Last a -> Maybe a
Monoid.getLast
where
toTLB :: LockingKind -> p
toTLB LockingKind
ForUpdate = p
"\nFOR UPDATE"
toTLB LockingKind
ForUpdateSkipLocked = p
"\nFOR UPDATE SKIP LOCKED"
toTLB LockingKind
ForShare = p
"\nFOR SHARE"
toTLB LockingKind
LockInShareMode = p
"\nLOCK IN SHARE MODE"
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
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
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
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 :: 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
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
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
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
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
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 (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
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 (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
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 (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
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
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 :: 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)
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 :: 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 (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 :: 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 (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 (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 (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 :: (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 (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)
`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 (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 :: 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 :: (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 :: ((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 (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 :: 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 :: (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 :: ((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 (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 :: 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 :: (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 :: ((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 (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 :: 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 :: (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 :: ((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 (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 :: 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 :: (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 :: ((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 (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 :: 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 :: (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 :: ((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 (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 :: 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 :: (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 :: ((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 (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 :: 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 :: (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 :: ((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 (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 :: 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
to11 :: ((a,b),(c,d),(e,f),(g,h),(i,j),k) -> (a,b,c,d,e,f,g,h,i,j,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 ((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 (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 :: 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
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 :: ((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 (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 :: 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
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 :: ((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 (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 :: 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
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 :: ((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 (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 :: 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
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 :: ((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 (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 :: 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
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 :: ((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)
=> SqlQuery (SqlExpr (Insertion a))
-> SqlWriteT m ()
insertSelect :: SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT 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)) -> SqlWriteT m Int64
forall (m :: * -> *) a.
(MonadIO m, PersistEntity a) =>
SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m Int64
insertSelectCount SqlQuery (SqlExpr (Insertion a))
a
insertSelectCount
:: (MonadIO m, PersistEntity a)
=> SqlQuery (SqlExpr (Insertion a))
-> SqlWriteT m Int64
insertSelectCount :: SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT 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
showList :: [RenderExprException] -> ShowS
$cshowList :: [RenderExprException] -> ShowS
show :: RenderExprException -> String
$cshow :: RenderExprException -> String
showsPrec :: Int -> RenderExprException -> ShowS
$cshowsPrec :: Int -> RenderExprException -> ShowS
Show
instance Exception RenderExprException
valkey
:: (ToBackendKey SqlBackend entity, PersistField (Key entity))
=> Int64 -> SqlExpr (Value (Key entity))
valkey :: 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 :: 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 :: 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 ()
Database.Persist.delete
associateJoin
:: forall e1 e0. Ord (Key e0)
=> [(Entity e0, e1)]
-> Map.Map (Key e0) (e0, [e1])
associateJoin :: [(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 (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])