{-# LANGUAGE BangPatterns, TypeFamilies, DataKinds, PolyKinds, TypeApplications, ScopedTypeVariables, ConstraintKinds, TypeOperators, GADTs, UndecidableInstances, StandaloneDeriving, FunctionalDependencies, FlexibleContexts, InstanceSigs, AllowAmbiguousTypes, DeriveAnyClass #-}
module IHP.QueryBuilder
( query
, QueryBuilder (..)
, In (In)
, orderBy
, orderByAsc
, orderByDesc
, limit
, offset
, queryUnion
, queryUnionList
, queryOr
, DefaultScope (..)
, filterWhere
, filterWhereCaseInsensitive
, filterWhereNot
, filterWhereIn
, filterWhereIdIn
, filterWhereNotIn
, filterWhereLike
, filterWhereILike
, filterWhereMatches
, filterWhereIMatches
, filterWhereJoinedTable
, filterWhereNotJoinedTable
, filterWhereInJoinedTable
, filterWhereNotInJoinedTable
, filterWhereLikeJoinedTable
, filterWhereILikeJoinedTable
, filterWhereMatchesJoinedTable
, filterWhereIMatchesJoinedTable
, filterWherePast
, filterWhereFuture
, labelResults
, EqOrIsOperator
, filterWhereSql
, FilterPrimaryKey (..)
, distinctOn
, distinct
, toSQL
, toSQL'
, buildQuery
, SQLQuery (..)
, OrderByClause (..)
, innerJoin
, innerJoinThirdTable
, HasQueryBuilder
, JoinQueryBuilderWrapper
, NoJoinQueryBuilderWrapper
, LabeledQueryBuilderWrapper
, getQueryBuilder
, NoJoins
, Condition (..)
, Join (..)
, OrderByDirection (..)
, injectQueryBuilder
, FilterOperator (..)
, toEqOrIsOperator
)
where
import IHP.Prelude
import Database.PostgreSQL.Simple.Types (In (In))
import Database.PostgreSQL.Simple.ToField
import IHP.ModelSupport
import qualified Data.ByteString.Builder as Builder
import IHP.HSX.ToHtml
import qualified Data.ByteString.Char8 as ByteString
import qualified Data.ByteString.Lazy as LByteString
import qualified Control.DeepSeq as DeepSeq
import qualified Data.Text.Encoding as Text
import qualified GHC.Generics
class DefaultScope table where
defaultScope :: QueryBuilder table -> QueryBuilder table
instance {-# OVERLAPPABLE #-} DefaultScope table where
{-# INLINE defaultScope #-}
defaultScope :: QueryBuilder table -> QueryBuilder table
defaultScope QueryBuilder table
queryBuilder = QueryBuilder table
queryBuilder
instance Table (GetModelByTableName table) => Default (QueryBuilder table) where
{-# INLINE def #-}
def :: QueryBuilder table
def = NewQueryBuilder { selectFrom :: ByteString
selectFrom = forall record. Table record => ByteString
tableNameByteString @(GetModelByTableName table), columns :: [ByteString]
columns = forall record. Table record => [ByteString]
columnNames @(GetModelByTableName table) }
data MatchSensitivity = CaseSensitive | CaseInsensitive deriving (Int -> MatchSensitivity -> ShowS
[MatchSensitivity] -> ShowS
MatchSensitivity -> String
(Int -> MatchSensitivity -> ShowS)
-> (MatchSensitivity -> String)
-> ([MatchSensitivity] -> ShowS)
-> Show MatchSensitivity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MatchSensitivity -> ShowS
showsPrec :: Int -> MatchSensitivity -> ShowS
$cshow :: MatchSensitivity -> String
show :: MatchSensitivity -> String
$cshowList :: [MatchSensitivity] -> ShowS
showList :: [MatchSensitivity] -> ShowS
Show, MatchSensitivity -> MatchSensitivity -> Bool
(MatchSensitivity -> MatchSensitivity -> Bool)
-> (MatchSensitivity -> MatchSensitivity -> Bool)
-> Eq MatchSensitivity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MatchSensitivity -> MatchSensitivity -> Bool
== :: MatchSensitivity -> MatchSensitivity -> Bool
$c/= :: MatchSensitivity -> MatchSensitivity -> Bool
/= :: MatchSensitivity -> MatchSensitivity -> Bool
Eq)
data FilterOperator
= EqOp
| NotEqOp
| InOp
| NotInOp
| IsOp
| IsNotOp
| LikeOp !MatchSensitivity
| NotLikeOp !MatchSensitivity
| MatchesOp !MatchSensitivity
| SqlOp
deriving (Int -> FilterOperator -> ShowS
[FilterOperator] -> ShowS
FilterOperator -> String
(Int -> FilterOperator -> ShowS)
-> (FilterOperator -> String)
-> ([FilterOperator] -> ShowS)
-> Show FilterOperator
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FilterOperator -> ShowS
showsPrec :: Int -> FilterOperator -> ShowS
$cshow :: FilterOperator -> String
show :: FilterOperator -> String
$cshowList :: [FilterOperator] -> ShowS
showList :: [FilterOperator] -> ShowS
Show, FilterOperator -> FilterOperator -> Bool
(FilterOperator -> FilterOperator -> Bool)
-> (FilterOperator -> FilterOperator -> Bool) -> Eq FilterOperator
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FilterOperator -> FilterOperator -> Bool
== :: FilterOperator -> FilterOperator -> Bool
$c/= :: FilterOperator -> FilterOperator -> Bool
/= :: FilterOperator -> FilterOperator -> Bool
Eq)
compileOperator :: FilterOperator -> ByteString
compileOperator :: FilterOperator -> ByteString
compileOperator FilterOperator
EqOp = ByteString
"="
compileOperator FilterOperator
NotEqOp = ByteString
"!="
compileOperator FilterOperator
InOp = ByteString
"IN"
compileOperator FilterOperator
NotInOp = ByteString
"NOT IN"
compileOperator FilterOperator
IsOp = ByteString
"IS"
compileOperator FilterOperator
IsNotOp = ByteString
"IS NOT"
compileOperator (LikeOp MatchSensitivity
CaseSensitive) = ByteString
"LIKE"
compileOperator (LikeOp MatchSensitivity
CaseInsensitive) = ByteString
"ILIKE"
compileOperator (NotLikeOp MatchSensitivity
CaseSensitive) = ByteString
"NOT LIKE"
compileOperator (NotLikeOp MatchSensitivity
CaseInsensitive) = ByteString
"NOT ILIKE"
compileOperator (MatchesOp MatchSensitivity
CaseSensitive) = ByteString
" ~ "
compileOperator (MatchesOp MatchSensitivity
CaseInsensitive) = ByteString
" ~* "
compileOperator FilterOperator
SqlOp = ByteString
""
{-# INLINE compileOperator #-}
negateFilterOperator :: FilterOperator -> FilterOperator
negateFilterOperator :: FilterOperator -> FilterOperator
negateFilterOperator FilterOperator
EqOp = FilterOperator
NotEqOp
negateFilterOperator FilterOperator
InOp = FilterOperator
NotInOp
negateFilterOperator FilterOperator
IsOp = FilterOperator
IsNotOp
negateFilterOperator (LikeOp MatchSensitivity
matchSensitivity) = (MatchSensitivity -> FilterOperator
NotLikeOp MatchSensitivity
matchSensitivity)
negateFilterOperator (MatchesOp MatchSensitivity
matchSensitivity) = Text -> FilterOperator
forall a. Text -> a
error Text
"not supported"
negateFilterOperator FilterOperator
SqlOp = FilterOperator
SqlOp
data OrderByClause =
OrderByClause
{ OrderByClause -> ByteString
orderByColumn :: !ByteString
, OrderByClause -> OrderByDirection
orderByDirection :: !OrderByDirection }
deriving (Int -> OrderByClause -> ShowS
[OrderByClause] -> ShowS
OrderByClause -> String
(Int -> OrderByClause -> ShowS)
-> (OrderByClause -> String)
-> ([OrderByClause] -> ShowS)
-> Show OrderByClause
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OrderByClause -> ShowS
showsPrec :: Int -> OrderByClause -> ShowS
$cshow :: OrderByClause -> String
show :: OrderByClause -> String
$cshowList :: [OrderByClause] -> ShowS
showList :: [OrderByClause] -> ShowS
Show, OrderByClause -> OrderByClause -> Bool
(OrderByClause -> OrderByClause -> Bool)
-> (OrderByClause -> OrderByClause -> Bool) -> Eq OrderByClause
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OrderByClause -> OrderByClause -> Bool
== :: OrderByClause -> OrderByClause -> Bool
$c/= :: OrderByClause -> OrderByClause -> Bool
/= :: OrderByClause -> OrderByClause -> Bool
Eq, (forall x. OrderByClause -> Rep OrderByClause x)
-> (forall x. Rep OrderByClause x -> OrderByClause)
-> Generic OrderByClause
forall x. Rep OrderByClause x -> OrderByClause
forall x. OrderByClause -> Rep OrderByClause x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. OrderByClause -> Rep OrderByClause x
from :: forall x. OrderByClause -> Rep OrderByClause x
$cto :: forall x. Rep OrderByClause x -> OrderByClause
to :: forall x. Rep OrderByClause x -> OrderByClause
GHC.Generics.Generic, OrderByClause -> ()
(OrderByClause -> ()) -> NFData OrderByClause
forall a. (a -> ()) -> NFData a
$crnf :: OrderByClause -> ()
rnf :: OrderByClause -> ()
DeepSeq.NFData)
data NoJoins
data EmptyModelList
data ConsModelList model models
class ModelList a
instance ModelList EmptyModelList
instance ModelList (ConsModelList model models)
class IsJoined a b
instance (ModelList b) => IsJoined a (ConsModelList a b)
instance {-# OVERLAPPABLE #-} (ModelList b, IsJoined a b) => IsJoined a (ConsModelList c b)
class HasQueryBuilder queryBuilderProvider joinRegister | queryBuilderProvider -> joinRegister where
getQueryBuilder :: queryBuilderProvider table -> QueryBuilder table
injectQueryBuilder :: QueryBuilder table -> queryBuilderProvider table
getQueryIndex :: queryBuilderProvider table -> Maybe ByteString
getQueryIndex queryBuilderProvider table
_ = Maybe ByteString
forall a. Maybe a
Nothing
{-# INLINABLE getQueryIndex #-}
newtype JoinQueryBuilderWrapper joinRegister table = JoinQueryBuilderWrapper (QueryBuilder table)
newtype NoJoinQueryBuilderWrapper table = NoJoinQueryBuilderWrapper (QueryBuilder table)
newtype LabeledQueryBuilderWrapper foreignTable indexColumn indexValue table = LabeledQueryBuilderWrapper (QueryBuilder table)
instance HasQueryBuilder QueryBuilder EmptyModelList where
getQueryBuilder :: forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
getQueryBuilder = QueryBuilder table -> QueryBuilder table
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
{-# INLINE getQueryBuilder #-}
injectQueryBuilder :: forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
injectQueryBuilder = QueryBuilder table -> QueryBuilder table
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
{-# INLINE injectQueryBuilder #-}
instance HasQueryBuilder (JoinQueryBuilderWrapper joinRegister) joinRegister where
getQueryBuilder :: forall (table :: Symbol).
JoinQueryBuilderWrapper joinRegister table -> QueryBuilder table
getQueryBuilder (JoinQueryBuilderWrapper QueryBuilder table
queryBuilder) = QueryBuilder table
queryBuilder
{-# INLINABLE getQueryBuilder #-}
injectQueryBuilder :: forall (table :: Symbol).
QueryBuilder table -> JoinQueryBuilderWrapper joinRegister table
injectQueryBuilder = QueryBuilder table -> JoinQueryBuilderWrapper joinRegister table
forall k (joinRegister :: k) (table :: Symbol).
QueryBuilder table -> JoinQueryBuilderWrapper joinRegister table
JoinQueryBuilderWrapper
{-# INLINABLE injectQueryBuilder #-}
instance HasQueryBuilder NoJoinQueryBuilderWrapper NoJoins where
getQueryBuilder :: forall (table :: Symbol).
NoJoinQueryBuilderWrapper table -> QueryBuilder table
getQueryBuilder (NoJoinQueryBuilderWrapper QueryBuilder table
queryBuilder) = QueryBuilder table
queryBuilder
{-# INLINABLE getQueryBuilder #-}
injectQueryBuilder :: forall (table :: Symbol).
QueryBuilder table -> NoJoinQueryBuilderWrapper table
injectQueryBuilder = QueryBuilder table -> NoJoinQueryBuilderWrapper table
forall (table :: Symbol).
QueryBuilder table -> NoJoinQueryBuilderWrapper table
NoJoinQueryBuilderWrapper
{-# INLINABLE injectQueryBuilder #-}
instance (KnownSymbol foreignTable, foreignModel ~ GetModelByTableName foreignTable , KnownSymbol indexColumn, HasField indexColumn foreignModel indexValue) => HasQueryBuilder (LabeledQueryBuilderWrapper foreignTable indexColumn indexValue) NoJoins where
getQueryBuilder :: forall (table :: Symbol).
LabeledQueryBuilderWrapper
foreignTable indexColumn indexValue table
-> QueryBuilder table
getQueryBuilder (LabeledQueryBuilderWrapper QueryBuilder table
queryBuilder) = QueryBuilder table
queryBuilder
{-# INLINABLE getQueryBuilder #-}
injectQueryBuilder :: forall (table :: Symbol).
QueryBuilder table
-> LabeledQueryBuilderWrapper
foreignTable indexColumn indexValue table
injectQueryBuilder = QueryBuilder table
-> LabeledQueryBuilderWrapper
foreignTable indexColumn indexValue table
forall {k} {k} {k} (foreignTable :: k) (indexColumn :: k)
(indexValue :: k) (table :: Symbol).
QueryBuilder table
-> LabeledQueryBuilderWrapper
foreignTable indexColumn indexValue table
LabeledQueryBuilderWrapper
{-# INLINABLE injectQueryBuilder #-}
getQueryIndex :: forall (table :: Symbol).
LabeledQueryBuilderWrapper
foreignTable indexColumn indexValue table
-> Maybe ByteString
getQueryIndex LabeledQueryBuilderWrapper
foreignTable indexColumn indexValue table
_ = ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ forall (symbol :: Symbol). KnownSymbol symbol => ByteString
symbolToByteString @foreignTable ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> (Text -> ByteString
Text.encodeUtf8 (Text -> ByteString) -> (Text -> Text) -> Text -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> Text
fieldNameToColumnName) (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @indexColumn)
{-# INLINABLE getQueryIndex #-}
data QueryBuilder (table :: Symbol) =
NewQueryBuilder { forall (table :: Symbol). QueryBuilder table -> ByteString
selectFrom :: !ByteString, forall (table :: Symbol). QueryBuilder table -> [ByteString]
columns :: ![ByteString] }
| DistinctQueryBuilder { forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
queryBuilder :: !(QueryBuilder table) }
| DistinctOnQueryBuilder { queryBuilder :: !(QueryBuilder table), forall (table :: Symbol). QueryBuilder table -> ByteString
distinctOnColumn :: !ByteString }
| FilterByQueryBuilder { queryBuilder :: !(QueryBuilder table), forall (table :: Symbol).
QueryBuilder table -> (ByteString, FilterOperator, Action)
queryFilter :: !(ByteString, FilterOperator, Action), forall (table :: Symbol). QueryBuilder table -> Maybe ByteString
applyLeft :: !(Maybe ByteString), forall (table :: Symbol). QueryBuilder table -> Maybe ByteString
applyRight :: !(Maybe ByteString) }
| OrderByQueryBuilder { queryBuilder :: !(QueryBuilder table), forall (table :: Symbol). QueryBuilder table -> OrderByClause
queryOrderByClause :: !OrderByClause }
| LimitQueryBuilder { queryBuilder :: !(QueryBuilder table), forall (table :: Symbol). QueryBuilder table -> Int
queryLimit :: !Int }
| OffsetQueryBuilder { queryBuilder :: !(QueryBuilder table), forall (table :: Symbol). QueryBuilder table -> Int
queryOffset :: !Int }
| UnionQueryBuilder { forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
firstQueryBuilder :: !(QueryBuilder table), forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
secondQueryBuilder :: !(QueryBuilder table) }
| JoinQueryBuilder { queryBuilder :: !(QueryBuilder table), forall (table :: Symbol). QueryBuilder table -> Join
joinData :: Join}
deriving (Int -> QueryBuilder table -> ShowS
[QueryBuilder table] -> ShowS
QueryBuilder table -> String
(Int -> QueryBuilder table -> ShowS)
-> (QueryBuilder table -> String)
-> ([QueryBuilder table] -> ShowS)
-> Show (QueryBuilder table)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (table :: Symbol). Int -> QueryBuilder table -> ShowS
forall (table :: Symbol). [QueryBuilder table] -> ShowS
forall (table :: Symbol). QueryBuilder table -> String
$cshowsPrec :: forall (table :: Symbol). Int -> QueryBuilder table -> ShowS
showsPrec :: Int -> QueryBuilder table -> ShowS
$cshow :: forall (table :: Symbol). QueryBuilder table -> String
show :: QueryBuilder table -> String
$cshowList :: forall (table :: Symbol). [QueryBuilder table] -> ShowS
showList :: [QueryBuilder table] -> ShowS
Show, QueryBuilder table -> QueryBuilder table -> Bool
(QueryBuilder table -> QueryBuilder table -> Bool)
-> (QueryBuilder table -> QueryBuilder table -> Bool)
-> Eq (QueryBuilder table)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (table :: Symbol).
QueryBuilder table -> QueryBuilder table -> Bool
$c== :: forall (table :: Symbol).
QueryBuilder table -> QueryBuilder table -> Bool
== :: QueryBuilder table -> QueryBuilder table -> Bool
$c/= :: forall (table :: Symbol).
QueryBuilder table -> QueryBuilder table -> Bool
/= :: QueryBuilder table -> QueryBuilder table -> Bool
Eq)
data Condition = VarCondition !ByteString !Action | OrCondition !Condition !Condition | AndCondition !Condition !Condition deriving (Int -> Condition -> ShowS
[Condition] -> ShowS
Condition -> String
(Int -> Condition -> ShowS)
-> (Condition -> String)
-> ([Condition] -> ShowS)
-> Show Condition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Condition -> ShowS
showsPrec :: Int -> Condition -> ShowS
$cshow :: Condition -> String
show :: Condition -> String
$cshowList :: [Condition] -> ShowS
showList :: [Condition] -> ShowS
Show, Condition -> Condition -> Bool
(Condition -> Condition -> Bool)
-> (Condition -> Condition -> Bool) -> Eq Condition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Condition -> Condition -> Bool
== :: Condition -> Condition -> Bool
$c/= :: Condition -> Condition -> Bool
/= :: Condition -> Condition -> Bool
Eq)
instance KnownSymbol table => ToHtml (QueryBuilder table) where
toHtml :: QueryBuilder table -> Html
toHtml QueryBuilder table
queryBuilder = (ByteString, [Action]) -> Html
forall a. ToHtml a => a -> Html
toHtml (QueryBuilder table -> (ByteString, [Action])
forall {k} (table :: Symbol) (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k).
(KnownSymbol table,
HasQueryBuilder queryBuilderProvider joinRegister) =>
queryBuilderProvider table -> (ByteString, [Action])
toSQL QueryBuilder table
queryBuilder)
data Join = Join { Join -> ByteString
table :: ByteString, Join -> ByteString
tableJoinColumn :: ByteString, Join -> ByteString
otherJoinColumn :: ByteString }
deriving (Int -> Join -> ShowS
[Join] -> ShowS
Join -> String
(Int -> Join -> ShowS)
-> (Join -> String) -> ([Join] -> ShowS) -> Show Join
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Join -> ShowS
showsPrec :: Int -> Join -> ShowS
$cshow :: Join -> String
show :: Join -> String
$cshowList :: [Join] -> ShowS
showList :: [Join] -> ShowS
Show, Join -> Join -> Bool
(Join -> Join -> Bool) -> (Join -> Join -> Bool) -> Eq Join
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Join -> Join -> Bool
== :: Join -> Join -> Bool
$c/= :: Join -> Join -> Bool
/= :: Join -> Join -> Bool
Eq)
data OrderByDirection = Asc | Desc deriving (OrderByDirection -> OrderByDirection -> Bool
(OrderByDirection -> OrderByDirection -> Bool)
-> (OrderByDirection -> OrderByDirection -> Bool)
-> Eq OrderByDirection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OrderByDirection -> OrderByDirection -> Bool
== :: OrderByDirection -> OrderByDirection -> Bool
$c/= :: OrderByDirection -> OrderByDirection -> Bool
/= :: OrderByDirection -> OrderByDirection -> Bool
Eq, Int -> OrderByDirection -> ShowS
[OrderByDirection] -> ShowS
OrderByDirection -> String
(Int -> OrderByDirection -> ShowS)
-> (OrderByDirection -> String)
-> ([OrderByDirection] -> ShowS)
-> Show OrderByDirection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OrderByDirection -> ShowS
showsPrec :: Int -> OrderByDirection -> ShowS
$cshow :: OrderByDirection -> String
show :: OrderByDirection -> String
$cshowList :: [OrderByDirection] -> ShowS
showList :: [OrderByDirection] -> ShowS
Show, (forall x. OrderByDirection -> Rep OrderByDirection x)
-> (forall x. Rep OrderByDirection x -> OrderByDirection)
-> Generic OrderByDirection
forall x. Rep OrderByDirection x -> OrderByDirection
forall x. OrderByDirection -> Rep OrderByDirection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. OrderByDirection -> Rep OrderByDirection x
from :: forall x. OrderByDirection -> Rep OrderByDirection x
$cto :: forall x. Rep OrderByDirection x -> OrderByDirection
to :: forall x. Rep OrderByDirection x -> OrderByDirection
GHC.Generics.Generic, OrderByDirection -> ()
(OrderByDirection -> ()) -> NFData OrderByDirection
forall a. (a -> ()) -> NFData a
$crnf :: OrderByDirection -> ()
rnf :: OrderByDirection -> ()
DeepSeq.NFData)
data SQLQuery = SQLQuery
{ SQLQuery -> Maybe ByteString
queryIndex :: !(Maybe ByteString)
, SQLQuery -> ByteString
selectFrom :: !ByteString
, SQLQuery -> Maybe ByteString
distinctClause :: !(Maybe ByteString)
, SQLQuery -> Maybe ByteString
distinctOnClause :: !(Maybe ByteString)
, SQLQuery -> Maybe Condition
whereCondition :: !(Maybe Condition)
, SQLQuery -> [Join]
joins :: ![Join]
, SQLQuery -> [OrderByClause]
orderByClause :: ![OrderByClause]
, SQLQuery -> Maybe ByteString
limitClause :: !(Maybe ByteString)
, SQLQuery -> Maybe ByteString
offsetClause :: !(Maybe ByteString)
, SQLQuery -> [ByteString]
columns :: ![ByteString]
} deriving (Int -> SQLQuery -> ShowS
[SQLQuery] -> ShowS
SQLQuery -> String
(Int -> SQLQuery -> ShowS)
-> (SQLQuery -> String) -> ([SQLQuery] -> ShowS) -> Show SQLQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SQLQuery -> ShowS
showsPrec :: Int -> SQLQuery -> ShowS
$cshow :: SQLQuery -> String
show :: SQLQuery -> String
$cshowList :: [SQLQuery] -> ShowS
showList :: [SQLQuery] -> ShowS
Show, SQLQuery -> SQLQuery -> Bool
(SQLQuery -> SQLQuery -> Bool)
-> (SQLQuery -> SQLQuery -> Bool) -> Eq SQLQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SQLQuery -> SQLQuery -> Bool
== :: SQLQuery -> SQLQuery -> Bool
$c/= :: SQLQuery -> SQLQuery -> Bool
/= :: SQLQuery -> SQLQuery -> Bool
Eq)
deriving instance Eq Action
instance Eq Builder.Builder where
Builder
a == :: Builder -> Builder -> Bool
== Builder
b = (Builder -> LazyByteString
Builder.toLazyByteString Builder
a) LazyByteString -> LazyByteString -> Bool
forall a. Eq a => a -> a -> Bool
== (Builder -> LazyByteString
Builder.toLazyByteString Builder
b)
instance SetField "queryIndex" SQLQuery (Maybe ByteString) where setField :: Maybe ByteString -> SQLQuery -> SQLQuery
setField Maybe ByteString
value SQLQuery
sqlQuery = SQLQuery
sqlQuery { queryIndex = value }
instance SetField "selectFrom" SQLQuery ByteString where setField :: ByteString -> SQLQuery -> SQLQuery
setField ByteString
value SQLQuery
sqlQuery = SQLQuery
sqlQuery { selectFrom = value }
instance SetField "distinctClause" SQLQuery (Maybe ByteString) where setField :: Maybe ByteString -> SQLQuery -> SQLQuery
setField Maybe ByteString
value SQLQuery
sqlQuery = SQLQuery
sqlQuery { distinctClause = value }
instance SetField "distinctOnClause" SQLQuery (Maybe ByteString) where setField :: Maybe ByteString -> SQLQuery -> SQLQuery
setField Maybe ByteString
value SQLQuery
sqlQuery = SQLQuery
sqlQuery { distinctOnClause = value }
instance SetField "whereCondition" SQLQuery (Maybe Condition) where setField :: Maybe Condition -> SQLQuery -> SQLQuery
setField Maybe Condition
value SQLQuery
sqlQuery = SQLQuery
sqlQuery { whereCondition = value }
instance SetField "orderByClause" SQLQuery [OrderByClause] where setField :: [OrderByClause] -> SQLQuery -> SQLQuery
setField [OrderByClause]
value SQLQuery
sqlQuery = SQLQuery
sqlQuery { orderByClause = value }
instance SetField "limitClause" SQLQuery (Maybe ByteString) where setField :: Maybe ByteString -> SQLQuery -> SQLQuery
setField Maybe ByteString
value SQLQuery
sqlQuery = SQLQuery
sqlQuery { limitClause = value }
instance SetField "offsetClause" SQLQuery (Maybe ByteString) where setField :: Maybe ByteString -> SQLQuery -> SQLQuery
setField Maybe ByteString
value SQLQuery
sqlQuery = SQLQuery
sqlQuery { offsetClause = value }
query :: forall model table. (table ~ GetTableName model, Table model) => DefaultScope table => QueryBuilder table
query :: forall model (table :: Symbol).
(table ~ GetTableName model, Table model, DefaultScope table) =>
QueryBuilder table
query = (forall (table :: Symbol).
DefaultScope table =>
QueryBuilder table -> QueryBuilder table
defaultScope @table) NewQueryBuilder { selectFrom :: ByteString
selectFrom = forall record. Table record => ByteString
tableNameByteString @model, columns :: [ByteString]
columns = forall record. Table record => [ByteString]
columnNames @model }
{-# INLINE query #-}
{-# INLINE buildQuery #-}
buildQuery :: forall table queryBuilderProvider joinRegister. (KnownSymbol table, HasQueryBuilder queryBuilderProvider joinRegister) => queryBuilderProvider table -> SQLQuery
buildQuery :: forall {k} (table :: Symbol) (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k).
(KnownSymbol table,
HasQueryBuilder queryBuilderProvider joinRegister) =>
queryBuilderProvider table -> SQLQuery
buildQuery queryBuilderProvider table
queryBuilderProvider = QueryBuilder table -> SQLQuery
buildQueryHelper (QueryBuilder table -> SQLQuery) -> QueryBuilder table -> SQLQuery
forall a b. (a -> b) -> a -> b
$ queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
where
buildQueryHelper :: QueryBuilder table -> SQLQuery
buildQueryHelper NewQueryBuilder { ByteString
selectFrom :: forall (table :: Symbol). QueryBuilder table -> ByteString
selectFrom :: ByteString
selectFrom, [ByteString]
columns :: forall (table :: Symbol). QueryBuilder table -> [ByteString]
columns :: [ByteString]
columns } =
SQLQuery
{ queryIndex :: Maybe ByteString
queryIndex = queryBuilderProvider table -> Maybe ByteString
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> Maybe ByteString
forall (table :: Symbol).
queryBuilderProvider table -> Maybe ByteString
getQueryIndex queryBuilderProvider table
queryBuilderProvider
, selectFrom :: ByteString
selectFrom = ByteString
selectFrom
, distinctClause :: Maybe ByteString
distinctClause = Maybe ByteString
forall a. Maybe a
Nothing
, distinctOnClause :: Maybe ByteString
distinctOnClause = Maybe ByteString
forall a. Maybe a
Nothing
, whereCondition :: Maybe Condition
whereCondition = Maybe Condition
forall a. Maybe a
Nothing
, joins :: [Join]
joins = []
, orderByClause :: [OrderByClause]
orderByClause = []
, limitClause :: Maybe ByteString
limitClause = Maybe ByteString
forall a. Maybe a
Nothing
, offsetClause :: Maybe ByteString
offsetClause = Maybe ByteString
forall a. Maybe a
Nothing
, [ByteString]
columns :: [ByteString]
columns :: [ByteString]
columns
}
buildQueryHelper DistinctQueryBuilder { QueryBuilder table
queryBuilder :: forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder } = QueryBuilder table
queryBuilder
QueryBuilder table -> (QueryBuilder table -> SQLQuery) -> SQLQuery
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> QueryBuilder table -> SQLQuery
buildQueryHelper
SQLQuery -> (SQLQuery -> SQLQuery) -> SQLQuery
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> Proxy "distinctClause" -> ByteString -> SQLQuery -> SQLQuery
forall model (name :: Symbol) value.
(KnownSymbol name, SetField name model (Maybe value)) =>
Proxy name -> value -> model -> model
setJust Proxy "distinctClause"
#distinctClause ByteString
"DISTINCT"
buildQueryHelper DistinctOnQueryBuilder { QueryBuilder table
queryBuilder :: forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, ByteString
distinctOnColumn :: forall (table :: Symbol). QueryBuilder table -> ByteString
distinctOnColumn :: ByteString
distinctOnColumn } = QueryBuilder table
queryBuilder
QueryBuilder table -> (QueryBuilder table -> SQLQuery) -> SQLQuery
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> QueryBuilder table -> SQLQuery
buildQueryHelper
SQLQuery -> (SQLQuery -> SQLQuery) -> SQLQuery
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> Proxy "distinctOnClause" -> ByteString -> SQLQuery -> SQLQuery
forall model (name :: Symbol) value.
(KnownSymbol name, SetField name model (Maybe value)) =>
Proxy name -> value -> model -> model
setJust Proxy "distinctOnClause"
#distinctOnClause (ByteString
"DISTINCT ON (" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
distinctOnColumn ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
")")
buildQueryHelper FilterByQueryBuilder { QueryBuilder table
queryBuilder :: forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: forall (table :: Symbol).
QueryBuilder table -> (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, FilterOperator
operator, Action
value), Maybe ByteString
applyLeft :: forall (table :: Symbol). QueryBuilder table -> Maybe ByteString
applyLeft :: Maybe ByteString
applyLeft, Maybe ByteString
applyRight :: forall (table :: Symbol). QueryBuilder table -> Maybe ByteString
applyRight :: Maybe ByteString
applyRight } =
let
applyFn :: Maybe a -> a -> a
applyFn Maybe a
fn a
value = case Maybe a
fn of
Just a
fn -> a
fn a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
"(" a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
value a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
")"
Maybe a
Nothing -> a
value
condition :: Condition
condition = ByteString -> Action -> Condition
VarCondition (Maybe ByteString -> ByteString -> ByteString
forall {a}. (Semigroup a, IsString a) => Maybe a -> a -> a
applyFn Maybe ByteString
applyLeft ByteString
columnName ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
" " ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> FilterOperator -> ByteString
compileOperator FilterOperator
operator ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
" " ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Maybe ByteString -> ByteString -> ByteString
forall {a}. (Semigroup a, IsString a) => Maybe a -> a -> a
applyFn Maybe ByteString
applyRight ByteString
"?") Action
value
in
QueryBuilder table
queryBuilder
QueryBuilder table -> (QueryBuilder table -> SQLQuery) -> SQLQuery
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> QueryBuilder table -> SQLQuery
buildQueryHelper
SQLQuery -> (SQLQuery -> SQLQuery) -> SQLQuery
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> Proxy "whereCondition"
-> (Maybe Condition -> Maybe Condition) -> SQLQuery -> SQLQuery
forall model (name :: Symbol) value.
(KnownSymbol name, HasField name model value,
SetField name model value) =>
Proxy name -> (value -> value) -> model -> model
modify Proxy "whereCondition"
#whereCondition \case
Just Condition
c -> Condition -> Maybe Condition
forall a. a -> Maybe a
Just (Condition -> Condition -> Condition
AndCondition Condition
c Condition
condition)
Maybe Condition
Nothing -> Condition -> Maybe Condition
forall a. a -> Maybe a
Just Condition
condition
buildQueryHelper OrderByQueryBuilder { QueryBuilder table
queryBuilder :: forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, OrderByClause
queryOrderByClause :: forall (table :: Symbol). QueryBuilder table -> OrderByClause
queryOrderByClause :: OrderByClause
queryOrderByClause } = QueryBuilder table
queryBuilder
QueryBuilder table -> (QueryBuilder table -> SQLQuery) -> SQLQuery
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> QueryBuilder table -> SQLQuery
buildQueryHelper
SQLQuery -> (SQLQuery -> SQLQuery) -> SQLQuery
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> Proxy "orderByClause"
-> ([OrderByClause] -> [OrderByClause]) -> SQLQuery -> SQLQuery
forall model (name :: Symbol) value.
(KnownSymbol name, HasField name model value,
SetField name model value) =>
Proxy name -> (value -> value) -> model -> model
modify Proxy "orderByClause"
#orderByClause (\[OrderByClause]
value -> [OrderByClause]
value [OrderByClause] -> [OrderByClause] -> [OrderByClause]
forall a. Semigroup a => a -> a -> a
<> [OrderByClause
queryOrderByClause] )
buildQueryHelper LimitQueryBuilder { QueryBuilder table
queryBuilder :: forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, Int
queryLimit :: forall (table :: Symbol). QueryBuilder table -> Int
queryLimit :: Int
queryLimit } =
QueryBuilder table
queryBuilder
QueryBuilder table -> (QueryBuilder table -> SQLQuery) -> SQLQuery
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> QueryBuilder table -> SQLQuery
buildQueryHelper
SQLQuery -> (SQLQuery -> SQLQuery) -> SQLQuery
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> Proxy "limitClause" -> ByteString -> SQLQuery -> SQLQuery
forall model (name :: Symbol) value.
(KnownSymbol name, SetField name model (Maybe value)) =>
Proxy name -> value -> model -> model
setJust Proxy "limitClause"
#limitClause (
(ByteString -> Builder
Builder.byteString ByteString
"LIMIT " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Int -> Builder
Builder.intDec Int
queryLimit)
Builder -> (Builder -> LazyByteString) -> LazyByteString
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> Builder -> LazyByteString
Builder.toLazyByteString
LazyByteString -> (LazyByteString -> ByteString) -> ByteString
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> LazyByteString -> ByteString
LByteString.toStrict
)
buildQueryHelper OffsetQueryBuilder { QueryBuilder table
queryBuilder :: forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, Int
queryOffset :: forall (table :: Symbol). QueryBuilder table -> Int
queryOffset :: Int
queryOffset } = QueryBuilder table
queryBuilder
QueryBuilder table -> (QueryBuilder table -> SQLQuery) -> SQLQuery
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> QueryBuilder table -> SQLQuery
buildQueryHelper
SQLQuery -> (SQLQuery -> SQLQuery) -> SQLQuery
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> Proxy "offsetClause" -> ByteString -> SQLQuery -> SQLQuery
forall model (name :: Symbol) value.
(KnownSymbol name, SetField name model (Maybe value)) =>
Proxy name -> value -> model -> model
setJust Proxy "offsetClause"
#offsetClause (
(ByteString -> Builder
Builder.byteString ByteString
"OFFSET " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Int -> Builder
Builder.intDec Int
queryOffset)
Builder -> (Builder -> LazyByteString) -> LazyByteString
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> Builder -> LazyByteString
Builder.toLazyByteString
LazyByteString -> (LazyByteString -> ByteString) -> ByteString
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> LazyByteString -> ByteString
LByteString.toStrict
)
buildQueryHelper UnionQueryBuilder { QueryBuilder table
firstQueryBuilder :: forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
firstQueryBuilder :: QueryBuilder table
firstQueryBuilder, QueryBuilder table
secondQueryBuilder :: forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
secondQueryBuilder :: QueryBuilder table
secondQueryBuilder } =
let
firstQuery :: SQLQuery
firstQuery = QueryBuilder table -> SQLQuery
buildQueryHelper QueryBuilder table
firstQueryBuilder
secondQuery :: SQLQuery
secondQuery = QueryBuilder table -> SQLQuery
buildQueryHelper QueryBuilder table
secondQueryBuilder
isSimpleQuery :: SQLQuery -> Bool
isSimpleQuery SQLQuery
query = [OrderByClause] -> Bool
forall mono. MonoFoldable mono => mono -> Bool
null (SQLQuery -> [OrderByClause]
orderByClause SQLQuery
query) Bool -> Bool -> Bool
&& Maybe ByteString -> Bool
forall a. Maybe a -> Bool
isNothing (SQLQuery -> Maybe ByteString
limitClause SQLQuery
query) Bool -> Bool -> Bool
&& Maybe ByteString -> Bool
forall a. Maybe a -> Bool
isNothing (SQLQuery -> Maybe ByteString
offsetClause SQLQuery
query) Bool -> Bool -> Bool
&& [Join] -> Bool
forall mono. MonoFoldable mono => mono -> Bool
null (SQLQuery -> [Join]
joins SQLQuery
query)
isSimpleUnion :: Bool
isSimpleUnion = SQLQuery -> Bool
isSimpleQuery SQLQuery
firstQuery Bool -> Bool -> Bool
&& SQLQuery -> Bool
isSimpleQuery SQLQuery
secondQuery
unionWhere :: Maybe Condition
unionWhere =
case (SQLQuery -> Maybe Condition
whereCondition SQLQuery
firstQuery, SQLQuery -> Maybe Condition
whereCondition SQLQuery
secondQuery) of
(Maybe Condition
Nothing, Maybe Condition
whereCondition) -> Maybe Condition
whereCondition
(Maybe Condition
whereCondition, Maybe Condition
Nothing) -> Maybe Condition
whereCondition
(Just Condition
firstWhere, Just Condition
secondWhere) -> Condition -> Maybe Condition
forall a. a -> Maybe a
Just (Condition -> Maybe Condition) -> Condition -> Maybe Condition
forall a b. (a -> b) -> a -> b
$ Condition -> Condition -> Condition
OrCondition Condition
firstWhere Condition
secondWhere
in
if Bool
isSimpleUnion then
SQLQuery
firstQuery { whereCondition = unionWhere }
else
Text -> SQLQuery
forall a. Text -> a
error Text
"buildQuery: Union of complex queries not supported yet"
buildQueryHelper JoinQueryBuilder { QueryBuilder table
queryBuilder :: forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, Join
joinData :: forall (table :: Symbol). QueryBuilder table -> Join
joinData :: Join
joinData } =
let
firstQuery :: SQLQuery
firstQuery = QueryBuilder table -> SQLQuery
buildQueryHelper QueryBuilder table
queryBuilder
in SQLQuery
firstQuery { joins = joinData:joins firstQuery }
toSQL :: (KnownSymbol table, HasQueryBuilder queryBuilderProvider joinRegister) => queryBuilderProvider table -> (ByteString, [Action])
toSQL :: forall {k} (table :: Symbol) (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k).
(KnownSymbol table,
HasQueryBuilder queryBuilderProvider joinRegister) =>
queryBuilderProvider table -> (ByteString, [Action])
toSQL queryBuilderProvider table
queryBuilderProvider = SQLQuery -> (ByteString, [Action])
toSQL' (queryBuilderProvider table -> SQLQuery
forall {k} (table :: Symbol) (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k).
(KnownSymbol table,
HasQueryBuilder queryBuilderProvider joinRegister) =>
queryBuilderProvider table -> SQLQuery
buildQuery queryBuilderProvider table
queryBuilderProvider)
{-# INLINE toSQL #-}
toSQL' :: SQLQuery -> (ByteString, [Action])
toSQL' :: SQLQuery -> (ByteString, [Action])
toSQL' sqlQuery :: SQLQuery
sqlQuery@SQLQuery { Maybe ByteString
queryIndex :: SQLQuery -> Maybe ByteString
queryIndex :: Maybe ByteString
queryIndex, ByteString
selectFrom :: SQLQuery -> ByteString
selectFrom :: ByteString
selectFrom, Maybe ByteString
distinctClause :: SQLQuery -> Maybe ByteString
distinctClause :: Maybe ByteString
distinctClause, Maybe ByteString
distinctOnClause :: SQLQuery -> Maybe ByteString
distinctOnClause :: Maybe ByteString
distinctOnClause, [OrderByClause]
orderByClause :: SQLQuery -> [OrderByClause]
orderByClause :: [OrderByClause]
orderByClause, Maybe ByteString
limitClause :: SQLQuery -> Maybe ByteString
limitClause :: Maybe ByteString
limitClause, Maybe ByteString
offsetClause :: SQLQuery -> Maybe ByteString
offsetClause :: Maybe ByteString
offsetClause, [ByteString]
columns :: SQLQuery -> [ByteString]
columns :: [ByteString]
columns } =
(ByteString -> ByteString
forall a. NFData a => a -> a
DeepSeq.force ByteString
theQuery, [Action]
theParams)
where
!theQuery :: ByteString
theQuery =
ByteString -> [ByteString] -> ByteString
ByteString.intercalate ByteString
" " ([ByteString] -> ByteString) -> [ByteString] -> ByteString
forall a b. (a -> b) -> a -> b
$
[Maybe ByteString] -> [ByteString]
forall a. [Maybe a] -> [a]
catMaybes
[ ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
"SELECT"
, Maybe ByteString
distinctClause
, Maybe ByteString
distinctOnClause
, ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
selectors
, ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
"FROM"
, ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
fromClause
, Maybe ByteString
joinClause
, Maybe ByteString
whereConditions'
, Maybe ByteString
orderByClause'
, Maybe ByteString
limitClause
, Maybe ByteString
offsetClause
]
selectors :: ByteString
selectors :: ByteString
selectors = ByteString -> [ByteString] -> ByteString
ByteString.intercalate ByteString
", " ([ByteString] -> ByteString) -> [ByteString] -> ByteString
forall a b. (a -> b) -> a -> b
$ ([Maybe ByteString] -> [ByteString]
forall a. [Maybe a] -> [a]
catMaybes [Maybe ByteString
queryIndex]) [ByteString] -> [ByteString] -> [ByteString]
forall a. Semigroup a => a -> a -> a
<> [ByteString]
selectFromWithColumns
where
selectFromWithColumns :: [ByteString]
selectFromWithColumns :: [ByteString]
selectFromWithColumns =
[ByteString]
columns
[ByteString] -> ([ByteString] -> [ByteString]) -> [ByteString]
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> (ByteString -> ByteString) -> [ByteString] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map (\ByteString
column -> ByteString
selectFrom ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
column)
fromClause :: ByteString
fromClause :: ByteString
fromClause = ByteString
selectFrom
!theParams :: [Action]
theParams =
case SQLQuery -> Maybe Condition
whereCondition SQLQuery
sqlQuery of
Just Condition
condition -> Condition -> [Action]
compileConditionArgs Condition
condition
Maybe Condition
Nothing -> [Action]
forall a. Monoid a => a
mempty
toQualifiedName :: ByteString -> ByteString
toQualifiedName ByteString
unqualifiedName = ByteString
selectFrom ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
unqualifiedName
whereConditions' :: Maybe ByteString
whereConditions' = case SQLQuery -> Maybe Condition
whereCondition SQLQuery
sqlQuery of
Just Condition
condition -> ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ ByteString
"WHERE " ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Condition -> ByteString
compileConditionQuery Condition
condition
Maybe Condition
Nothing -> Maybe ByteString
forall a. Maybe a
Nothing
orderByClause' :: Maybe ByteString
orderByClause' :: Maybe ByteString
orderByClause' = case [OrderByClause]
orderByClause of
[] -> Maybe ByteString
forall a. Maybe a
Nothing
[OrderByClause]
xs -> ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString
"ORDER BY " ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString -> [ByteString] -> ByteString
ByteString.intercalate ByteString
"," (((OrderByClause -> ByteString) -> [OrderByClause] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map (\OrderByClause { ByteString
orderByColumn :: OrderByClause -> ByteString
orderByColumn :: ByteString
orderByColumn, OrderByDirection
orderByDirection :: OrderByClause -> OrderByDirection
orderByDirection :: OrderByDirection
orderByDirection } -> ByteString
orderByColumn ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> (if OrderByDirection
orderByDirection OrderByDirection -> OrderByDirection -> Bool
forall a. Eq a => a -> a -> Bool
== OrderByDirection
Desc then ByteString
" DESC" else ByteString
forall a. Monoid a => a
mempty)) [OrderByClause]
xs)))
joinClause :: Maybe ByteString
joinClause :: Maybe ByteString
joinClause = [Join] -> Maybe ByteString
buildJoinClause ([Join] -> Maybe ByteString) -> [Join] -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ [Join] -> [Join]
forall a. [a] -> [a]
reverse ([Join] -> [Join]) -> [Join] -> [Join]
forall a b. (a -> b) -> a -> b
$ SQLQuery -> [Join]
joins SQLQuery
sqlQuery
buildJoinClause :: [Join] -> Maybe ByteString
buildJoinClause :: [Join] -> Maybe ByteString
buildJoinClause [] = Maybe ByteString
forall a. Maybe a
Nothing
buildJoinClause (Join
joinClause:[Join]
joinClauses) = ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ ByteString
"INNER JOIN " ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Join -> ByteString
table Join
joinClause ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
" ON " ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Join -> ByteString
tableJoinColumn Join
joinClause ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
" = " ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<>Join -> ByteString
table Join
joinClause ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Join -> ByteString
otherJoinColumn Join
joinClause ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
-> (ByteString -> ByteString) -> Maybe ByteString -> ByteString
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ByteString
"" (ByteString
" " <>) ([Join] -> Maybe ByteString
buildJoinClause [Join]
joinClauses)
{-# INLINE toSQL' #-}
{-# INLINE compileConditionQuery #-}
compileConditionQuery :: Condition -> ByteString
compileConditionQuery :: Condition -> ByteString
compileConditionQuery (VarCondition ByteString
var Action
_) = ByteString
var
compileConditionQuery (OrCondition Condition
a Condition
b) = ByteString
"(" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Condition -> ByteString
compileConditionQuery Condition
a ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
") OR (" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Condition -> ByteString
compileConditionQuery Condition
b ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
")"
compileConditionQuery (AndCondition Condition
a Condition
b) = ByteString
"(" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Condition -> ByteString
compileConditionQuery Condition
a ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
") AND (" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Condition -> ByteString
compileConditionQuery Condition
b ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
")"
{-# INLINE compileConditionArgs #-}
compileConditionArgs :: Condition -> [Action]
compileConditionArgs :: Condition -> [Action]
compileConditionArgs (VarCondition ByteString
_ Action
arg) = [Action
arg]
compileConditionArgs (OrCondition Condition
a Condition
b) = Condition -> [Action]
compileConditionArgs Condition
a [Action] -> [Action] -> [Action]
forall a. Semigroup a => a -> a -> a
<> Condition -> [Action]
compileConditionArgs Condition
b
compileConditionArgs (AndCondition Condition
a Condition
b) = Condition -> [Action]
compileConditionArgs Condition
a [Action] -> [Action] -> [Action]
forall a. Semigroup a => a -> a -> a
<> Condition -> [Action]
compileConditionArgs Condition
b
class FilterPrimaryKey table where
filterWhereId :: Id' table -> QueryBuilder table -> QueryBuilder table
filterWhere :: forall name table model value queryBuilderProvider joinRegister. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, EqOrIsOperator value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => (Proxy name, value) -> queryBuilderProvider table -> queryBuilderProvider table
filterWhere :: forall {k} (name :: Symbol) (table :: Symbol) model value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, EqOrIsOperator value,
model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
(Proxy name, value)
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhere (Proxy name
name, value
value) queryBuilderProvider table
queryBuilderProvider = QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, value -> FilterOperator
forall value. EqOrIsOperator value => value -> FilterOperator
toEqOrIsOperator value
value, value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
{-# INLINE filterWhere #-}
filterWhereJoinedTable :: forall model name table value queryBuilderProvider joinRegister table'. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, EqOrIsOperator value, table ~ GetTableName model, HasQueryBuilder queryBuilderProvider joinRegister, IsJoined model joinRegister, Table model) => (Proxy name, value) -> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereJoinedTable :: forall {k} model (name :: Symbol) (table :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k)
(table' :: Symbol).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, EqOrIsOperator value,
table ~ GetTableName model,
HasQueryBuilder queryBuilderProvider joinRegister,
IsJoined model joinRegister, Table model) =>
(Proxy name, value)
-> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereJoinedTable (Proxy name
name, value
value) queryBuilderProvider table'
queryBuilderProvider = QueryBuilder table' -> queryBuilderProvider table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, value -> FilterOperator
forall value. EqOrIsOperator value => value -> FilterOperator
toEqOrIsOperator value
value, value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table'
queryBuilder = queryBuilderProvider table' -> QueryBuilder table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table'
queryBuilderProvider
{-# INLINE filterWhereJoinedTable #-}
filterWhereNot :: forall name table model value. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, EqOrIsOperator value, model ~ GetModelByTableName table, Table model) => (Proxy name, value) -> QueryBuilder table -> QueryBuilder table
filterWhereNot :: forall (name :: Symbol) (table :: Symbol) model value.
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, EqOrIsOperator value,
model ~ GetModelByTableName table, Table model) =>
(Proxy name, value) -> QueryBuilder table -> QueryBuilder table
filterWhereNot (Proxy name
name, value
value) QueryBuilder table
queryBuilder = FilterByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, FilterOperator -> FilterOperator
negateFilterOperator (value -> FilterOperator
forall value. EqOrIsOperator value => value -> FilterOperator
toEqOrIsOperator value
value), value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
{-# INLINE filterWhereNot #-}
filterWhereNotJoinedTable :: forall model name table value queryBuilderProvider joinRegister table'. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, EqOrIsOperator value, table ~ GetTableName model, HasQueryBuilder queryBuilderProvider joinRegister, IsJoined model joinRegister, Table model) => (Proxy name, value) -> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereNotJoinedTable :: forall {k} model (name :: Symbol) (table :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k)
(table' :: Symbol).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, EqOrIsOperator value,
table ~ GetTableName model,
HasQueryBuilder queryBuilderProvider joinRegister,
IsJoined model joinRegister, Table model) =>
(Proxy name, value)
-> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereNotJoinedTable (Proxy name
name, value
value) queryBuilderProvider table'
queryBuilderProvider = QueryBuilder table' -> queryBuilderProvider table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, FilterOperator -> FilterOperator
negateFilterOperator (value -> FilterOperator
forall value. EqOrIsOperator value => value -> FilterOperator
toEqOrIsOperator value
value), value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table'
queryBuilder = queryBuilderProvider table' -> QueryBuilder table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table'
queryBuilderProvider
{-# INLINE filterWhereNotJoinedTable #-}
filterWhereIn :: forall name table model value queryBuilderProvider (joinRegister :: Type). (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, EqOrIsOperator value, Table model) => (Proxy name, [value]) -> queryBuilderProvider table -> queryBuilderProvider table
filterWhereIn :: forall (name :: Symbol) (table :: Symbol) model value
(queryBuilderProvider :: Symbol -> *) joinRegister.
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister,
EqOrIsOperator value, Table model) =>
(Proxy name, [value])
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhereIn (Proxy name
name, [value]
value) queryBuilderProvider table
queryBuilderProvider =
case [value] -> Maybe value
forall a. [a] -> Maybe a
head [value]
nullValues of
Maybe value
Nothing -> QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder QueryBuilder table
whereInQuery
Just value
nullValue ->
let
isNullValueExpr :: QueryBuilder table
isNullValueExpr = FilterByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, FilterOperator
IsOp, value -> Action
forall a. ToField a => a -> Action
toField value
nullValue), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
in
case [value] -> Maybe value
forall a. [a] -> Maybe a
head [value]
nonNullValues of
Just value
nonNullValue ->
QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder (QueryBuilder table -> queryBuilderProvider table)
-> QueryBuilder table -> queryBuilderProvider table
forall a b. (a -> b) -> a -> b
$ QueryBuilder table -> QueryBuilder table -> QueryBuilder table
forall (table :: Symbol).
QueryBuilder table -> QueryBuilder table -> QueryBuilder table
UnionQueryBuilder
(QueryBuilder table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
injectQueryBuilder QueryBuilder table
whereInQuery)
(QueryBuilder table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
injectQueryBuilder QueryBuilder table
isNullValueExpr)
Maybe value
Nothing -> QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder QueryBuilder table
isNullValueExpr
where
([value]
nonNullValues, [value]
nullValues) = [value]
value [value] -> ([value] -> ([value], [value])) -> ([value], [value])
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> (value -> Bool) -> [value] -> ([value], [value])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (\value
v -> value -> FilterOperator
forall value. EqOrIsOperator value => value -> FilterOperator
toEqOrIsOperator value
v FilterOperator -> FilterOperator -> Bool
forall a. Eq a => a -> a -> Bool
== FilterOperator
EqOp)
whereInQuery :: QueryBuilder table
whereInQuery = FilterByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, FilterOperator
InOp, In [value] -> Action
forall a. ToField a => a -> Action
toField ([value] -> In [value]
forall a. a -> In a
In [value]
nonNullValues)), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
{-# INLINE filterWhereIn #-}
filterWhereInJoinedTable :: forall model name table value queryBuilderProvider joinRegister table'. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, table ~ GetTableName model, HasQueryBuilder queryBuilderProvider joinRegister, IsJoined model joinRegister, Table model) => (Proxy name, [value]) -> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereInJoinedTable :: forall {k} model (name :: Symbol) (table :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k)
(table' :: Symbol).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, table ~ GetTableName model,
HasQueryBuilder queryBuilderProvider joinRegister,
IsJoined model joinRegister, Table model) =>
(Proxy name, [value])
-> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereInJoinedTable (Proxy name
name, [value]
value) queryBuilderProvider table'
queryBuilderProvider = QueryBuilder table' -> queryBuilderProvider table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, FilterOperator
InOp, In [value] -> Action
forall a. ToField a => a -> Action
toField ([value] -> In [value]
forall a. a -> In a
In [value]
value)), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table'
queryBuilder = queryBuilderProvider table' -> QueryBuilder table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table'
queryBuilderProvider
{-# INLINE filterWhereInJoinedTable #-}
filterWhereNotIn :: forall name table model value queryBuilderProvider joinRegister. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, EqOrIsOperator value) => (Proxy name, [value]) -> queryBuilderProvider table -> queryBuilderProvider table
filterWhereNotIn :: forall {k} (name :: Symbol) (table :: Symbol) model value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister,
EqOrIsOperator value) =>
(Proxy name, [value])
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhereNotIn (Proxy name
_, []) queryBuilderProvider table
queryBuilder = queryBuilderProvider table
queryBuilder
filterWhereNotIn (Proxy name
name, [value]
value) queryBuilderProvider table
queryBuilderProvider =
case [value] -> Maybe value
forall a. [a] -> Maybe a
head [value]
nullValues of
Maybe value
Nothing -> QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder QueryBuilder table
whereNotInQuery
Just value
nullValue ->
case [value] -> Maybe value
forall a. [a] -> Maybe a
head [value]
nonNullValues of
Just value
nonNullValue -> QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { queryBuilder :: QueryBuilder table
queryBuilder = QueryBuilder table
whereNotInQuery, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, FilterOperator
IsNotOp, value -> Action
forall a. ToField a => a -> Action
toField value
nullValue), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
Maybe value
Nothing -> QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, FilterOperator
IsNotOp, value -> Action
forall a. ToField a => a -> Action
toField value
nullValue), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
([value]
nonNullValues, [value]
nullValues) = [value]
value [value] -> ([value] -> ([value], [value])) -> ([value], [value])
forall {t1} {t2}. t1 -> (t1 -> t2) -> t2
|> (value -> Bool) -> [value] -> ([value], [value])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (\value
v -> value -> FilterOperator
forall value. EqOrIsOperator value => value -> FilterOperator
toEqOrIsOperator value
v FilterOperator -> FilterOperator -> Bool
forall a. Eq a => a -> a -> Bool
== FilterOperator
EqOp)
whereNotInQuery :: QueryBuilder table
whereNotInQuery = FilterByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, FilterOperator
NotInOp, In [value] -> Action
forall a. ToField a => a -> Action
toField ([value] -> In [value]
forall a. a -> In a
In [value]
nonNullValues)), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
columnName :: ByteString
columnName = Text -> ByteString
Text.encodeUtf8 (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @table) ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
{-# INLINE filterWhereNotIn #-}
filterWhereNotInJoinedTable :: forall model name table value queryBuilderProvider joinRegister table'. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, table ~ GetTableName model, HasQueryBuilder queryBuilderProvider joinRegister, IsJoined model joinRegister, Table model) => (Proxy name, [value]) -> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereNotInJoinedTable :: forall {k} model (name :: Symbol) (table :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k)
(table' :: Symbol).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, table ~ GetTableName model,
HasQueryBuilder queryBuilderProvider joinRegister,
IsJoined model joinRegister, Table model) =>
(Proxy name, [value])
-> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereNotInJoinedTable (Proxy name
_, []) queryBuilderProvider table'
queryBuilderProvider = queryBuilderProvider table'
queryBuilderProvider
filterWhereNotInJoinedTable (Proxy name
name, [value]
value) queryBuilderProvider table'
queryBuilderProvider = QueryBuilder table' -> queryBuilderProvider table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, FilterOperator
NotInOp, In [value] -> Action
forall a. ToField a => a -> Action
toField ([value] -> In [value]
forall a. a -> In a
In [value]
value)), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table'
queryBuilder = queryBuilderProvider table' -> QueryBuilder table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table'
queryBuilderProvider
{-# INLINE filterWhereNotInJoinedTable #-}
filterWhereLike :: forall name table model value queryBuilderProvider joinRegister. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => (Proxy name, value) -> queryBuilderProvider table -> queryBuilderProvider table
filterWhereLike :: forall {k} (name :: Symbol) (table :: Symbol) model value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
(Proxy name, value)
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhereLike (Proxy name
name, value
value) queryBuilderProvider table
queryBuilderProvider = QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, MatchSensitivity -> FilterOperator
LikeOp MatchSensitivity
CaseSensitive, value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
{-# INLINE filterWhereLike #-}
filterWhereLikeJoinedTable :: forall model name table value queryBuilderProvider joinRegister table'. (KnownSymbol name, KnownSymbol table, table ~ GetTableName model, ToField value, HasField name model value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, IsJoined model joinRegister, Table model) => (Proxy name, value) -> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereLikeJoinedTable :: forall {k} model (name :: Symbol) (table :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k)
(table' :: Symbol).
(KnownSymbol name, KnownSymbol table, table ~ GetTableName model,
ToField value, HasField name model value,
model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister,
IsJoined model joinRegister, Table model) =>
(Proxy name, value)
-> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereLikeJoinedTable (Proxy name
name, value
value) queryBuilderProvider table'
queryBuilderProvider = QueryBuilder table' -> queryBuilderProvider table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, MatchSensitivity -> FilterOperator
LikeOp MatchSensitivity
CaseSensitive, value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table'
queryBuilder = queryBuilderProvider table' -> QueryBuilder table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table'
queryBuilderProvider
{-# INLINE filterWhereLikeJoinedTable #-}
filterWhereILike :: forall name table model value queryBuilderProvider joinRegister. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => (Proxy name, value) -> queryBuilderProvider table -> queryBuilderProvider table
filterWhereILike :: forall {k} (name :: Symbol) (table :: Symbol) model value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
(Proxy name, value)
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhereILike (Proxy name
name, value
value) queryBuilderProvider table
queryBuilderProvider = QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, MatchSensitivity -> FilterOperator
LikeOp MatchSensitivity
CaseInsensitive, value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
{-# INLINE filterWhereILike #-}
filterWhereILikeJoinedTable :: forall model table name table' model' value queryBuilderProvider joinRegister. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, table ~ GetTableName model, model' ~ GetModelByTableName table', HasQueryBuilder queryBuilderProvider joinRegister, IsJoined model joinRegister, Table model) => (Proxy name, value) -> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereILikeJoinedTable :: forall {k} model (table :: Symbol) (name :: Symbol)
(table' :: Symbol) model' value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, table ~ GetTableName model,
model' ~ GetModelByTableName table',
HasQueryBuilder queryBuilderProvider joinRegister,
IsJoined model joinRegister, Table model) =>
(Proxy name, value)
-> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereILikeJoinedTable (Proxy name
name, value
value) queryBuilderProvider table'
queryBuilderProvider = QueryBuilder table' -> queryBuilderProvider table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, MatchSensitivity -> FilterOperator
LikeOp MatchSensitivity
CaseInsensitive, value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table'
queryBuilder = queryBuilderProvider table' -> QueryBuilder table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table'
queryBuilderProvider
{-# INLINE filterWhereILikeJoinedTable #-}
filterWhereMatches :: forall name table model value queryBuilderProvider joinRegister. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, table ~ GetTableName model, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => (Proxy name, value) -> queryBuilderProvider table -> queryBuilderProvider table
filterWhereMatches :: forall {k} (name :: Symbol) (table :: Symbol) model value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, table ~ GetTableName model,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
(Proxy name, value)
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhereMatches (Proxy name
name, value
value) queryBuilderProvider table
queryBuilderProvider = QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, MatchSensitivity -> FilterOperator
MatchesOp MatchSensitivity
CaseSensitive, value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
{-# INLINE filterWhereMatches #-}
filterWhereMatchesJoinedTable :: forall model table name value queryBuilderProvider joinRegister table'. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, table ~ GetTableName model, HasQueryBuilder queryBuilderProvider joinRegister, IsJoined model joinRegister, Table model) => (Proxy name, value) -> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereMatchesJoinedTable :: forall {k} model (table :: Symbol) (name :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k)
(table' :: Symbol).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, table ~ GetTableName model,
HasQueryBuilder queryBuilderProvider joinRegister,
IsJoined model joinRegister, Table model) =>
(Proxy name, value)
-> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereMatchesJoinedTable (Proxy name
name, value
value) queryBuilderProvider table'
queryBuilderProvider = QueryBuilder table' -> queryBuilderProvider table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, MatchSensitivity -> FilterOperator
MatchesOp MatchSensitivity
CaseSensitive, value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table'
queryBuilder = queryBuilderProvider table' -> QueryBuilder table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table'
queryBuilderProvider
{-# INLINE filterWhereMatchesJoinedTable #-}
filterWhereIMatches :: forall name table model value queryBuilderProvider joinRegister. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => (Proxy name, value) -> queryBuilderProvider table -> queryBuilderProvider table
filterWhereIMatches :: forall {k} (name :: Symbol) (table :: Symbol) model value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
(Proxy name, value)
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhereIMatches (Proxy name
name, value
value) queryBuilderProvider table
queryBuilderProvider = QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, MatchSensitivity -> FilterOperator
MatchesOp MatchSensitivity
CaseInsensitive, value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
{-# INLINE filterWhereIMatches #-}
filterWhereIMatchesJoinedTable :: forall model table name value queryBuilderProvider joinRegister table'. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, table ~ GetTableName model, HasQueryBuilder queryBuilderProvider joinRegister, IsJoined model joinRegister, Table model) => (Proxy name, value) -> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereIMatchesJoinedTable :: forall {k} model (table :: Symbol) (name :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k)
(table' :: Symbol).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, table ~ GetTableName model,
HasQueryBuilder queryBuilderProvider joinRegister,
IsJoined model joinRegister, Table model) =>
(Proxy name, value)
-> queryBuilderProvider table' -> queryBuilderProvider table'
filterWhereIMatchesJoinedTable (Proxy name
name, value
value) queryBuilderProvider table'
queryBuilderProvider = QueryBuilder table' -> queryBuilderProvider table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder :: QueryBuilder table'
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, MatchSensitivity -> FilterOperator
MatchesOp MatchSensitivity
CaseInsensitive, value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table'
queryBuilder = queryBuilderProvider table' -> QueryBuilder table'
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table'
queryBuilderProvider
{-# INLINE filterWhereIMatchesJoinedTable #-}
filterWherePast
:: ( KnownSymbol table
, KnownSymbol name
, ToField value
, HasField name (GetModelByTableName table) value
, HasQueryBuilder queryBuilderProvider joinRegister
, Table (GetModelByTableName table)
)
=> Proxy name -> queryBuilderProvider table -> queryBuilderProvider table
filterWherePast :: forall {k} (table :: Symbol) (name :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name (GetModelByTableName table) value,
HasQueryBuilder queryBuilderProvider joinRegister,
Table (GetModelByTableName table)) =>
Proxy name
-> queryBuilderProvider table -> queryBuilderProvider table
filterWherePast Proxy name
name = (Proxy name, ByteString)
-> queryBuilderProvider table -> queryBuilderProvider table
forall {k} (name :: Symbol) (table :: Symbol) model value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
(Proxy name, ByteString)
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhereSql (Proxy name
name, ByteString
"<= NOW()")
{-# INLINE filterWherePast #-}
filterWhereFuture
:: ( KnownSymbol table
, KnownSymbol name
, ToField value
, HasField name (GetModelByTableName table) value
, HasQueryBuilder queryBuilderProvider joinRegister
, Table (GetModelByTableName table)
)
=> Proxy name -> queryBuilderProvider table -> queryBuilderProvider table
filterWhereFuture :: forall {k} (table :: Symbol) (name :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name (GetModelByTableName table) value,
HasQueryBuilder queryBuilderProvider joinRegister,
Table (GetModelByTableName table)) =>
Proxy name
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhereFuture Proxy name
name = (Proxy name, ByteString)
-> queryBuilderProvider table -> queryBuilderProvider table
forall {k} (name :: Symbol) (table :: Symbol) model value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
(Proxy name, ByteString)
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhereSql (Proxy name
name, ByteString
"> NOW()")
{-# INLINE filterWhereFuture #-}
filterWhereSql :: forall name table model value queryBuilderProvider joinRegister. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => (Proxy name, ByteString) -> queryBuilderProvider table -> queryBuilderProvider table
filterWhereSql :: forall {k} (name :: Symbol) (table :: Symbol) model value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
(Proxy name, ByteString)
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhereSql (Proxy name
name, ByteString
sqlCondition) queryBuilderProvider table
queryBuilderProvider = QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, FilterOperator
SqlOp, Builder -> Action
Plain (ByteString -> Builder
Builder.byteString ByteString
sqlCondition)), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
{-# INLINE filterWhereSql #-}
filterWhereCaseInsensitive :: forall name table model value queryBuilderProvider joinRegister. (KnownSymbol table, KnownSymbol name, ToField value, HasField name model value, EqOrIsOperator value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => (Proxy name, value) -> queryBuilderProvider table -> queryBuilderProvider table
filterWhereCaseInsensitive :: forall {k} (name :: Symbol) (table :: Symbol) model value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, ToField value,
HasField name model value, EqOrIsOperator value,
model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
(Proxy name, value)
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhereCaseInsensitive (Proxy name
name, value
value) queryBuilderProvider table
queryBuilderProvider = QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder FilterByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
columnName, value -> FilterOperator
forall value. EqOrIsOperator value => value -> FilterOperator
toEqOrIsOperator value
value, value -> Action
forall a. ToField a => a -> Action
toField value
value), applyLeft :: Maybe ByteString
applyLeft = ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
"LOWER", applyRight :: Maybe ByteString
applyRight = ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
"LOWER" }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
{-# INLINE filterWhereCaseInsensitive #-}
filterWhereIdIn :: forall table model queryBuilderProvider (joinRegister :: Type). (KnownSymbol table, Table model, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister) => [Id model] -> queryBuilderProvider table -> queryBuilderProvider table
filterWhereIdIn :: forall (table :: Symbol) model
(queryBuilderProvider :: Symbol -> *) joinRegister.
(KnownSymbol table, Table model, model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister) =>
[Id model]
-> queryBuilderProvider table -> queryBuilderProvider table
filterWhereIdIn [Id model]
values queryBuilderProvider table
queryBuilderProvider =
let
pkConditions :: [Action]
pkConditions = (Id model -> Action) -> [Id model] -> [Action]
forall a b. (a -> b) -> [a] -> [b]
map (forall record. Table record => Id record -> Action
primaryKeyConditionForId @model) [Id model]
values
queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
whereInQuery :: QueryBuilder table
whereInQuery = FilterByQueryBuilder {QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (forall record. Table record => ByteString
primaryKeyConditionColumnSelector @model, FilterOperator
InOp, In [Action] -> Action
forall a. ToField a => a -> Action
toField ([Action] -> In [Action]
forall a. a -> In a
In [Action]
pkConditions)), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing}
in
QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder QueryBuilder table
whereInQuery
{-# INLINE filterWhereIdIn #-}
innerJoin :: forall model' table' name' value' model table name value queryBuilderProvider joinRegister.
(
KnownSymbol name,
KnownSymbol table,
HasField name model value,
KnownSymbol name',
KnownSymbol table',
HasQueryBuilder queryBuilderProvider joinRegister,
ModelList joinRegister,
HasField name' model' value',
value ~ value',
model ~ GetModelByTableName table,
table' ~ GetTableName model'
) => (Proxy name, Proxy name') -> queryBuilderProvider table -> JoinQueryBuilderWrapper (ConsModelList model' joinRegister) table
innerJoin :: forall {k} model' (table' :: Symbol) (name' :: Symbol) value' model
(table :: Symbol) (name :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol name, KnownSymbol table, HasField name model value,
KnownSymbol name', KnownSymbol table',
HasQueryBuilder queryBuilderProvider joinRegister,
ModelList joinRegister, HasField name' model' value',
value ~ value', model ~ GetModelByTableName table,
table' ~ GetTableName model') =>
(Proxy name, Proxy name')
-> queryBuilderProvider table
-> JoinQueryBuilderWrapper
(ConsModelList model' joinRegister) table
innerJoin (Proxy name
name, Proxy name'
name') queryBuilderProvider table
queryBuilderProvider = QueryBuilder table
-> JoinQueryBuilderWrapper
(ConsModelList model' joinRegister) table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table
-> JoinQueryBuilderWrapper
(ConsModelList model' joinRegister) table
injectQueryBuilder (QueryBuilder table
-> JoinQueryBuilderWrapper
(ConsModelList model' joinRegister) table)
-> QueryBuilder table
-> JoinQueryBuilderWrapper
(ConsModelList model' joinRegister) table
forall a b. (a -> b) -> a -> b
$ QueryBuilder table -> Join -> QueryBuilder table
forall (table :: Symbol).
QueryBuilder table -> Join -> QueryBuilder table
JoinQueryBuilder (queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider) (Join -> QueryBuilder table) -> Join -> QueryBuilder table
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString -> ByteString -> Join
Join ByteString
joinTableName ByteString
leftJoinColumn ByteString
rightJoinColumn
where
baseTableName :: ByteString
baseTableName = forall (symbol :: Symbol). KnownSymbol symbol => ByteString
symbolToByteString @table
joinTableName :: ByteString
joinTableName = forall (symbol :: Symbol). KnownSymbol symbol => ByteString
symbolToByteString @table'
leftJoinColumn :: ByteString
leftJoinColumn = ByteString
baseTableName ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> (Text -> ByteString
Text.encodeUtf8 (Text -> ByteString) -> (Text -> Text) -> Text -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> Text
fieldNameToColumnName) (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name)
rightJoinColumn :: ByteString
rightJoinColumn = (Text -> ByteString
Text.encodeUtf8 (Text -> ByteString) -> (Text -> Text) -> Text -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> Text
fieldNameToColumnName) (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name')
{-# INLINE innerJoin #-}
labelResults :: forall foreignModel baseModel foreignTable baseTable name value queryBuilderProvider joinRegister.
(
KnownSymbol foreignTable,
KnownSymbol baseTable,
foreignTable ~ GetTableName foreignModel,
baseModel ~ GetModelByTableName baseTable,
HasField name foreignModel value,
HasQueryBuilder queryBuilderProvider joinRegister,
KnownSymbol name,
IsJoined foreignModel joinRegister
) => Proxy name -> queryBuilderProvider baseTable -> LabeledQueryBuilderWrapper foreignTable name value baseTable
labelResults :: forall {k} foreignModel baseModel (foreignTable :: Symbol)
(baseTable :: Symbol) (name :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol foreignTable, KnownSymbol baseTable,
foreignTable ~ GetTableName foreignModel,
baseModel ~ GetModelByTableName baseTable,
HasField name foreignModel value,
HasQueryBuilder queryBuilderProvider joinRegister,
KnownSymbol name, IsJoined foreignModel joinRegister) =>
Proxy name
-> queryBuilderProvider baseTable
-> LabeledQueryBuilderWrapper foreignTable name value baseTable
labelResults Proxy name
name queryBuilderProvider baseTable
queryBuilderProvider = QueryBuilder baseTable
-> LabeledQueryBuilderWrapper foreignTable name value baseTable
forall {k} {k} {k} (foreignTable :: k) (indexColumn :: k)
(indexValue :: k) (table :: Symbol).
QueryBuilder table
-> LabeledQueryBuilderWrapper
foreignTable indexColumn indexValue table
LabeledQueryBuilderWrapper (QueryBuilder baseTable
-> LabeledQueryBuilderWrapper foreignTable name value baseTable)
-> QueryBuilder baseTable
-> LabeledQueryBuilderWrapper foreignTable name value baseTable
forall a b. (a -> b) -> a -> b
$ queryBuilderProvider baseTable -> QueryBuilder baseTable
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider baseTable
queryBuilderProvider
innerJoinThirdTable :: forall model model' name name' value value' table table' baseTable baseModel queryBuilderProvider joinRegister.
(
KnownSymbol name,
KnownSymbol table,
HasField name model value,
KnownSymbol name',
KnownSymbol table',
HasQueryBuilder queryBuilderProvider joinRegister,
ModelList joinRegister,
HasField name' model' value',
value ~ value',
table ~ GetTableName model,
table' ~ GetTableName model',
baseModel ~ GetModelByTableName baseTable
) => (Proxy name, Proxy name') -> queryBuilderProvider baseTable -> JoinQueryBuilderWrapper (ConsModelList model joinRegister) baseTable
innerJoinThirdTable :: forall {k} model model' (name :: Symbol) (name' :: Symbol) value
value' (table :: Symbol) (table' :: Symbol) (baseTable :: Symbol)
baseModel (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k).
(KnownSymbol name, KnownSymbol table, HasField name model value,
KnownSymbol name', KnownSymbol table',
HasQueryBuilder queryBuilderProvider joinRegister,
ModelList joinRegister, HasField name' model' value',
value ~ value', table ~ GetTableName model,
table' ~ GetTableName model',
baseModel ~ GetModelByTableName baseTable) =>
(Proxy name, Proxy name')
-> queryBuilderProvider baseTable
-> JoinQueryBuilderWrapper
(ConsModelList model joinRegister) baseTable
innerJoinThirdTable (Proxy name
name, Proxy name'
name') queryBuilderProvider baseTable
queryBuilderProvider = QueryBuilder baseTable
-> JoinQueryBuilderWrapper
(ConsModelList model joinRegister) baseTable
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table
-> JoinQueryBuilderWrapper (ConsModelList model joinRegister) table
injectQueryBuilder (QueryBuilder baseTable
-> JoinQueryBuilderWrapper
(ConsModelList model joinRegister) baseTable)
-> QueryBuilder baseTable
-> JoinQueryBuilderWrapper
(ConsModelList model joinRegister) baseTable
forall a b. (a -> b) -> a -> b
$ QueryBuilder baseTable -> Join -> QueryBuilder baseTable
forall (table :: Symbol).
QueryBuilder table -> Join -> QueryBuilder table
JoinQueryBuilder (queryBuilderProvider baseTable -> QueryBuilder baseTable
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider baseTable
queryBuilderProvider) (Join -> QueryBuilder baseTable) -> Join -> QueryBuilder baseTable
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString -> ByteString -> Join
Join ByteString
joinTableName ByteString
leftJoinColumn ByteString
rightJoinColumn
where
baseTableName :: ByteString
baseTableName = forall (symbol :: Symbol). KnownSymbol symbol => ByteString
symbolToByteString @table'
joinTableName :: ByteString
joinTableName = forall (symbol :: Symbol). KnownSymbol symbol => ByteString
symbolToByteString @table
leftJoinColumn :: ByteString
leftJoinColumn = ByteString
baseTableName ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> (Text -> ByteString
Text.encodeUtf8 (Text -> ByteString) -> (Text -> Text) -> Text -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> Text
fieldNameToColumnName) (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name')
rightJoinColumn :: ByteString
rightJoinColumn = (Text -> ByteString
Text.encodeUtf8 (Text -> ByteString) -> (Text -> Text) -> Text -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> Text
fieldNameToColumnName) (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name)
{-# INLINE innerJoinThirdTable #-}
orderByAsc :: forall name model table value queryBuilderProvider joinRegister. (KnownSymbol table, KnownSymbol name, HasField name model value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => Proxy name -> queryBuilderProvider table -> queryBuilderProvider table
orderByAsc :: forall {k} (name :: Symbol) model (table :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, HasField name model value,
model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
Proxy name
-> queryBuilderProvider table -> queryBuilderProvider table
orderByAsc !Proxy name
name queryBuilderProvider table
queryBuilderProvider = QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder OrderByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryOrderByClause :: OrderByClause
queryOrderByClause = OrderByClause { orderByColumn :: ByteString
orderByColumn = ByteString
columnName, orderByDirection :: OrderByDirection
orderByDirection = OrderByDirection
Asc } }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
{-# INLINE orderByAsc #-}
orderByDesc :: forall name model table value queryBuilderProvider joinRegister. (KnownSymbol table, KnownSymbol name, HasField name model value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => Proxy name -> queryBuilderProvider table -> queryBuilderProvider table
orderByDesc :: forall {k} (name :: Symbol) model (table :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, HasField name model value,
model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
Proxy name
-> queryBuilderProvider table -> queryBuilderProvider table
orderByDesc !Proxy name
name queryBuilderProvider table
queryBuilderProvider = QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder OrderByQueryBuilder { QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder :: QueryBuilder table
queryBuilder, queryOrderByClause :: OrderByClause
queryOrderByClause = OrderByClause { orderByColumn :: ByteString
orderByColumn = ByteString
columnName, orderByDirection :: OrderByDirection
orderByDirection = OrderByDirection
Desc } }
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider
{-# INLINE orderByDesc #-}
orderBy :: (KnownSymbol table, KnownSymbol name, HasField name model value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => Proxy name -> queryBuilderProvider table -> queryBuilderProvider table
orderBy :: forall {k} (table :: Symbol) (name :: Symbol) model value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, HasField name model value,
model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
Proxy name
-> queryBuilderProvider table -> queryBuilderProvider table
orderBy !Proxy name
name = Proxy name
-> queryBuilderProvider table -> queryBuilderProvider table
forall {k} (name :: Symbol) model (table :: Symbol) value
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, HasField name model value,
model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
Proxy name
-> queryBuilderProvider table -> queryBuilderProvider table
orderByAsc Proxy name
name
{-# INLINE orderBy #-}
limit :: (HasQueryBuilder queryBuilderProvider joinRegister) => Int -> queryBuilderProvider model -> queryBuilderProvider model
limit :: forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (model :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
Int -> queryBuilderProvider model -> queryBuilderProvider model
limit !Int
queryLimit queryBuilderProvider model
queryBuilderProvider = QueryBuilder model -> queryBuilderProvider model
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder LimitQueryBuilder { QueryBuilder model
queryBuilder :: QueryBuilder model
queryBuilder :: QueryBuilder model
queryBuilder, Int
queryLimit :: Int
queryLimit :: Int
queryLimit }
where
queryBuilder :: QueryBuilder model
queryBuilder = queryBuilderProvider model -> QueryBuilder model
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider model
queryBuilderProvider
{-# INLINE limit #-}
offset :: (HasQueryBuilder queryBuilderProvider joinRegister) => Int -> queryBuilderProvider model -> queryBuilderProvider model
offset :: forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (model :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
Int -> queryBuilderProvider model -> queryBuilderProvider model
offset !Int
queryOffset queryBuilderProvider model
queryBuilderProvider = QueryBuilder model -> queryBuilderProvider model
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder OffsetQueryBuilder { QueryBuilder model
queryBuilder :: QueryBuilder model
queryBuilder :: QueryBuilder model
queryBuilder, Int
queryOffset :: Int
queryOffset :: Int
queryOffset }
where
queryBuilder :: QueryBuilder model
queryBuilder = queryBuilderProvider model -> QueryBuilder model
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider model
queryBuilderProvider
{-# INLINE offset #-}
queryUnion :: (HasQueryBuilder queryBuilderProvider joinRegister, HasQueryBuilder r joinRegister') => queryBuilderProvider model -> r model -> NoJoinQueryBuilderWrapper model
queryUnion :: forall {k} {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (r :: Symbol -> *) (joinRegister' :: k)
(model :: Symbol).
(HasQueryBuilder queryBuilderProvider joinRegister,
HasQueryBuilder r joinRegister') =>
queryBuilderProvider model
-> r model -> NoJoinQueryBuilderWrapper model
queryUnion queryBuilderProvider model
firstQueryBuilderProvider r model
secondQueryBuilderProvider = QueryBuilder model -> NoJoinQueryBuilderWrapper model
forall (table :: Symbol).
QueryBuilder table -> NoJoinQueryBuilderWrapper table
NoJoinQueryBuilderWrapper (UnionQueryBuilder { QueryBuilder model
firstQueryBuilder :: QueryBuilder model
firstQueryBuilder :: QueryBuilder model
firstQueryBuilder, QueryBuilder model
secondQueryBuilder :: QueryBuilder model
secondQueryBuilder :: QueryBuilder model
secondQueryBuilder })
where
firstQueryBuilder :: QueryBuilder model
firstQueryBuilder = queryBuilderProvider model -> QueryBuilder model
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider model
firstQueryBuilderProvider
secondQueryBuilder :: QueryBuilder model
secondQueryBuilder = r model -> QueryBuilder model
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol). r table -> QueryBuilder table
getQueryBuilder r model
secondQueryBuilderProvider
{-# INLINE queryUnion #-}
queryUnionList :: forall table. (Table (GetModelByTableName table), KnownSymbol table, GetTableName (GetModelByTableName table) ~ table) => [QueryBuilder table] -> QueryBuilder table
queryUnionList :: forall (table :: Symbol).
(Table (GetModelByTableName table), KnownSymbol table,
GetTableName (GetModelByTableName table) ~ table) =>
[QueryBuilder table] -> QueryBuilder table
queryUnionList [] = FilterByQueryBuilder { queryBuilder :: QueryBuilder table
queryBuilder = forall model (table :: Symbol).
(table ~ GetTableName model, Table model, DefaultScope table) =>
QueryBuilder table
query @(GetModelByTableName table) @table, queryFilter :: (ByteString, FilterOperator, Action)
queryFilter = (ByteString
"id", FilterOperator
NotEqOp, Builder -> Action
Plain Builder
"id"), applyLeft :: Maybe ByteString
applyLeft = Maybe ByteString
forall a. Maybe a
Nothing, applyRight :: Maybe ByteString
applyRight = Maybe ByteString
forall a. Maybe a
Nothing }
queryUnionList (QueryBuilder table
firstQueryBuilder:QueryBuilder table
secondQueryBuilder:[]) = UnionQueryBuilder { QueryBuilder table
firstQueryBuilder :: QueryBuilder table
firstQueryBuilder :: QueryBuilder table
firstQueryBuilder, QueryBuilder table
secondQueryBuilder :: QueryBuilder table
secondQueryBuilder :: QueryBuilder table
secondQueryBuilder }
queryUnionList (QueryBuilder table
firstQueryBuilder:[QueryBuilder table]
rest) = UnionQueryBuilder { QueryBuilder table
firstQueryBuilder :: QueryBuilder table
firstQueryBuilder :: QueryBuilder table
firstQueryBuilder, secondQueryBuilder :: QueryBuilder table
secondQueryBuilder = forall (table :: Symbol).
(Table (GetModelByTableName table), KnownSymbol table,
GetTableName (GetModelByTableName table) ~ table) =>
[QueryBuilder table] -> QueryBuilder table
queryUnionList @table [QueryBuilder table]
rest }
queryOr :: (HasQueryBuilder queryBuilderProvider joinRegister, HasQueryBuilder queryBuilderProvider'' joinRegister'', HasQueryBuilder queryBuilderProvider''' joinRegister''') => (queryBuilderProvider model -> queryBuilderProvider''' model) -> (queryBuilderProvider model -> queryBuilderProvider'' model) -> queryBuilderProvider model -> queryBuilderProvider model
queryOr :: forall {k} {k} {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (queryBuilderProvider'' :: Symbol -> *)
(joinRegister'' :: k) (queryBuilderProvider''' :: Symbol -> *)
(joinRegister''' :: k) (model :: Symbol).
(HasQueryBuilder queryBuilderProvider joinRegister,
HasQueryBuilder queryBuilderProvider'' joinRegister'',
HasQueryBuilder queryBuilderProvider''' joinRegister''') =>
(queryBuilderProvider model -> queryBuilderProvider''' model)
-> (queryBuilderProvider model -> queryBuilderProvider'' model)
-> queryBuilderProvider model
-> queryBuilderProvider model
queryOr queryBuilderProvider model -> queryBuilderProvider''' model
firstQuery queryBuilderProvider model -> queryBuilderProvider'' model
secondQuery queryBuilderProvider model
queryBuilder = QueryBuilder model -> queryBuilderProvider model
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder
(UnionQueryBuilder {
firstQueryBuilder :: QueryBuilder model
firstQueryBuilder = queryBuilderProvider''' model -> QueryBuilder model
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider''' table -> QueryBuilder table
getQueryBuilder (queryBuilderProvider''' model -> QueryBuilder model)
-> queryBuilderProvider''' model -> QueryBuilder model
forall a b. (a -> b) -> a -> b
$ queryBuilderProvider model -> queryBuilderProvider''' model
firstQuery queryBuilderProvider model
queryBuilder,
secondQueryBuilder :: QueryBuilder model
secondQueryBuilder = queryBuilderProvider'' model -> QueryBuilder model
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider'' table -> QueryBuilder table
getQueryBuilder (queryBuilderProvider'' model -> QueryBuilder model)
-> queryBuilderProvider'' model -> QueryBuilder model
forall a b. (a -> b) -> a -> b
$ queryBuilderProvider model -> queryBuilderProvider'' model
secondQuery queryBuilderProvider model
queryBuilder}
)
{-# INLINE queryOr #-}
distinct :: (HasQueryBuilder queryBuilderProvider joinRegister) => queryBuilderProvider table -> queryBuilderProvider table
distinct :: forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> queryBuilderProvider table
distinct = QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder (QueryBuilder table -> queryBuilderProvider table)
-> (queryBuilderProvider table -> QueryBuilder table)
-> queryBuilderProvider table
-> queryBuilderProvider table
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. QueryBuilder table -> QueryBuilder table
forall (table :: Symbol). QueryBuilder table -> QueryBuilder table
DistinctQueryBuilder (QueryBuilder table -> QueryBuilder table)
-> (queryBuilderProvider table -> QueryBuilder table)
-> queryBuilderProvider table
-> QueryBuilder table
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder
{-# INLINE distinct #-}
distinctOn :: forall name model value table queryBuilderProvider joinRegister. (KnownSymbol table, KnownSymbol name, HasField name model value, model ~ GetModelByTableName table, HasQueryBuilder queryBuilderProvider joinRegister, Table model) => Proxy name -> queryBuilderProvider table -> queryBuilderProvider table
distinctOn :: forall {k} (name :: Symbol) model value (table :: Symbol)
(queryBuilderProvider :: Symbol -> *) (joinRegister :: k).
(KnownSymbol table, KnownSymbol name, HasField name model value,
model ~ GetModelByTableName table,
HasQueryBuilder queryBuilderProvider joinRegister, Table model) =>
Proxy name
-> queryBuilderProvider table -> queryBuilderProvider table
distinctOn !Proxy name
name queryBuilderProvider table
queryBuilderProvider = QueryBuilder table -> queryBuilderProvider table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
QueryBuilder table -> queryBuilderProvider table
forall (table :: Symbol).
QueryBuilder table -> queryBuilderProvider table
injectQueryBuilder DistinctOnQueryBuilder { distinctOnColumn :: ByteString
distinctOnColumn = ByteString
columnName, queryBuilder :: QueryBuilder table
queryBuilder = queryBuilderProvider table -> QueryBuilder table
forall {k} (queryBuilderProvider :: Symbol -> *)
(joinRegister :: k) (table :: Symbol).
HasQueryBuilder queryBuilderProvider joinRegister =>
queryBuilderProvider table -> QueryBuilder table
forall (table :: Symbol).
queryBuilderProvider table -> QueryBuilder table
getQueryBuilder queryBuilderProvider table
queryBuilderProvider}
where
columnName :: ByteString
columnName = forall record. Table record => ByteString
tableNameByteString @model ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
"." ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Text -> ByteString
Text.encodeUtf8 (Text -> Text
fieldNameToColumnName (forall (symbol :: Symbol). KnownSymbol symbol => Text
symbolToText @name))
{-# INLINE distinctOn #-}
class EqOrIsOperator value where toEqOrIsOperator :: value -> FilterOperator
instance {-# OVERLAPS #-} EqOrIsOperator (Maybe something) where toEqOrIsOperator :: Maybe something -> FilterOperator
toEqOrIsOperator Maybe something
Nothing = FilterOperator
IsOp; toEqOrIsOperator (Just something
_) = FilterOperator
EqOp
instance {-# OVERLAPPABLE #-} EqOrIsOperator otherwise where toEqOrIsOperator :: otherwise -> FilterOperator
toEqOrIsOperator otherwise
_ = FilterOperator
EqOp