| Copyright | (c) digitally induced GmbH 2020 |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
IHP.QueryBuilder.Types
Contents
Description
Synopsis
- newtype QueryBuilder (table :: Symbol) = QueryBuilder {}
- data SQLQuery = SQLQuery {
- selectFrom :: !Text
- distinctClause :: !Bool
- distinctOnClause :: !(Maybe Text)
- whereCondition :: !(Maybe Condition)
- orderByClause :: ![OrderByClause]
- limitClause :: !(Maybe Int)
- offsetClause :: !(Maybe Int)
- columns :: ![Text]
- columnsSql :: !Text
- data Condition
- data ConditionValue
- data OrderByClause = OrderByClause {}
- data OrderByDirection
- data FilterOperator
- data MatchSensitivity
- addCondition :: forall (table :: Symbol). Condition -> QueryBuilder table -> QueryBuilder table
- qualifyAndJoinColumns :: Text -> [Text] -> Text
- class DefaultScope (table :: Symbol) where
- defaultScope :: QueryBuilder table -> QueryBuilder table
- class EqOrIsOperator value where
- toEqOrIsOperator :: value -> FilterOperator
- class FilterPrimaryKey (table :: Symbol) where
- filterWhereId :: Id' table -> QueryBuilder table -> QueryBuilder table
Core Types
newtype QueryBuilder (table :: Symbol) Source #
The QueryBuilder is a flat newtype over SQLQuery. Each combinator directly modifies fields of the underlying SQLQuery, avoiding any recursive tree traversal.
Constructors
| QueryBuilder | |
Fields | |
Instances
Represents a complete SQL query after building
Constructors
| SQLQuery | |
Fields
| |
Instances
| Show SQLQuery Source # | |
| SetField "distinctClause" SQLQuery Bool Source # | |
| SetField "selectFrom" SQLQuery Text Source # | |
| SetField "distinctOnClause" SQLQuery (Maybe Text) Source # | |
| SetField "limitClause" SQLQuery (Maybe Int) Source # | |
| SetField "offsetClause" SQLQuery (Maybe Int) Source # | |
| SetField "orderByClause" SQLQuery [OrderByClause] Source # | |
Defined in IHP.QueryBuilder.Types | |
| SetField "whereCondition" SQLQuery (Maybe Condition) Source # | |
Represents a WHERE condition
Constructors
| ColumnCondition !Text !FilterOperator !ConditionValue !(Maybe Text) !(Maybe Text) | |
| OrCondition !Condition !Condition | |
| AndCondition !Condition !Condition |
data ConditionValue Source #
A condition value: either a parameterized encoder or a literal SQL fragment.
Constructors
| Param !(Params ()) | Parameterized value: compiler assigns $N |
| Literal !Text | Raw SQL text (for filterWhereSql, NULL comparisons, etc.) |
Instances
| Show ConditionValue Source # | |
Defined in IHP.QueryBuilder.Types Methods showsPrec :: Int -> ConditionValue -> ShowS # show :: ConditionValue -> String # showList :: [ConditionValue] -> ShowS # | |
| Eq ConditionValue Source # | |
Defined in IHP.QueryBuilder.Types Methods (==) :: ConditionValue -> ConditionValue -> Bool # (/=) :: ConditionValue -> ConditionValue -> Bool # | |
data OrderByClause Source #
Represents an ORDER BY clause component
Constructors
| OrderByClause | |
Fields | |
Instances
| NFData OrderByClause Source # | |||||
Defined in IHP.QueryBuilder.Types Methods rnf :: OrderByClause -> () # | |||||
| Generic OrderByClause Source # | |||||
Defined in IHP.QueryBuilder.Types Associated Types
| |||||
| Show OrderByClause Source # | |||||
Defined in IHP.QueryBuilder.Types Methods showsPrec :: Int -> OrderByClause -> ShowS # show :: OrderByClause -> String # showList :: [OrderByClause] -> ShowS # | |||||
| Eq OrderByClause Source # | |||||
Defined in IHP.QueryBuilder.Types Methods (==) :: OrderByClause -> OrderByClause -> Bool # (/=) :: OrderByClause -> OrderByClause -> Bool # | |||||
| SetField "orderByClause" SQLQuery [OrderByClause] Source # | |||||
Defined in IHP.QueryBuilder.Types | |||||
| type Rep OrderByClause Source # | |||||
Defined in IHP.QueryBuilder.Types type Rep OrderByClause = D1 ('MetaData "OrderByClause" "IHP.QueryBuilder.Types" "ihp-1.5.0-JkJMY5grI1LEXDOsW6DsRv" 'False) (C1 ('MetaCons "OrderByClause" 'PrefixI 'True) (S1 ('MetaSel ('Just "orderByColumn") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Just "orderByDirection") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OrderByDirection))) | |||||
data OrderByDirection Source #
ORDER BY direction
Instances
| NFData OrderByDirection Source # | |||||
Defined in IHP.QueryBuilder.Types Methods rnf :: OrderByDirection -> () # | |||||
| Generic OrderByDirection Source # | |||||
Defined in IHP.QueryBuilder.Types Associated Types
Methods from :: OrderByDirection -> Rep OrderByDirection x # to :: Rep OrderByDirection x -> OrderByDirection # | |||||
| Show OrderByDirection Source # | |||||
Defined in IHP.QueryBuilder.Types Methods showsPrec :: Int -> OrderByDirection -> ShowS # show :: OrderByDirection -> String # showList :: [OrderByDirection] -> ShowS # | |||||
| Eq OrderByDirection Source # | |||||
Defined in IHP.QueryBuilder.Types Methods (==) :: OrderByDirection -> OrderByDirection -> Bool # (/=) :: OrderByDirection -> OrderByDirection -> Bool # | |||||
| type Rep OrderByDirection Source # | |||||
data FilterOperator Source #
Operators used in WHERE clause conditions
Constructors
| EqOp | col = val |
| NotEqOp | col != val |
| InOp | col IN (set) |
| NotInOp | col NOT IN (set) |
| IsOp | col IS val |
| IsNotOp | col IS NOT val |
| LikeOp !MatchSensitivity | col LIKE val |
| NotLikeOp !MatchSensitivity | col NOT LIKE val |
| MatchesOp !MatchSensitivity | col ~ pattern |
| GreaterThanOp | col > val |
| GreaterThanOrEqualToOp | col >= val |
| LessThanOp | col < val |
| LessThanOrEqualToOp | col <= val |
| SqlOp | Used by |
Instances
| Show FilterOperator Source # | |
Defined in IHP.QueryBuilder.Types Methods showsPrec :: Int -> FilterOperator -> ShowS # show :: FilterOperator -> String # showList :: [FilterOperator] -> ShowS # | |
| Eq FilterOperator Source # | |
Defined in IHP.QueryBuilder.Types Methods (==) :: FilterOperator -> FilterOperator -> Bool # (/=) :: FilterOperator -> FilterOperator -> Bool # | |
data MatchSensitivity Source #
Represents whether string matching should be case-sensitive or not
Constructors
| CaseSensitive | |
| CaseInsensitive |
Instances
| Show MatchSensitivity Source # | |
Defined in IHP.QueryBuilder.Types Methods showsPrec :: Int -> MatchSensitivity -> ShowS # show :: MatchSensitivity -> String # showList :: [MatchSensitivity] -> ShowS # | |
| Eq MatchSensitivity Source # | |
Defined in IHP.QueryBuilder.Types Methods (==) :: MatchSensitivity -> MatchSensitivity -> Bool # (/=) :: MatchSensitivity -> MatchSensitivity -> Bool # | |
Helpers
addCondition :: forall (table :: Symbol). Condition -> QueryBuilder table -> QueryBuilder table Source #
Add a WHERE condition to a QueryBuilder, ANDing with any existing condition.
qualifyAndJoinColumns :: Text -> [Text] -> Text Source #
Pre-compute the qualified, comma-separated column selector.
E.g. qualifyAndJoinColumns "users" ["id", "name"] = "users.id, users.name"
Intentionally NOINLINE: call sites (query, def) are lifted to CAFs, so this is evaluated once per table type. NOINLINE prevents GHC from inlining the map/intercalate into every use site of the resulting SQLQuery.
Type Classes
class DefaultScope (table :: Symbol) where Source #
Type class for default scoping of queries
Methods
defaultScope :: QueryBuilder table -> QueryBuilder table Source #
Instances
| DefaultScope table Source # | |
Defined in IHP.QueryBuilder.Types Methods defaultScope :: QueryBuilder table -> QueryBuilder table Source # | |
class EqOrIsOperator value where Source #
Helper to deal with some_field IS NULL and some_field = 'some value'
Methods
toEqOrIsOperator :: value -> FilterOperator Source #
Instances
| EqOrIsOperator otherwise Source # | |
Defined in IHP.QueryBuilder.Types Methods toEqOrIsOperator :: otherwise -> FilterOperator Source # | |
| EqOrIsOperator (Maybe something) Source # | |
Defined in IHP.QueryBuilder.Types Methods toEqOrIsOperator :: Maybe something -> FilterOperator Source # | |
class FilterPrimaryKey (table :: Symbol) where Source #
Type class for filtering by primary key
Methods
filterWhereId :: Id' table -> QueryBuilder table -> QueryBuilder table Source #