| Copyright | (c) digitally induced GmbH 2020 |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
IHP.QueryBuilder.Compiler
Description
This module provides functions to compile a QueryBuilder into SQL.
Synopsis
- query :: forall model (table :: Symbol). (table ~ GetTableName model, Table model, DefaultScope table) => QueryBuilder table
- buildQuery :: forall (table :: Symbol). KnownSymbol table => QueryBuilder table -> SQLQuery
- negateFilterOperator :: FilterOperator -> FilterOperator
- qualifiedColumnName :: Text -> Text -> Text
Documentation
query :: forall model (table :: Symbol). (table ~ GetTableName model, Table model, DefaultScope table) => QueryBuilder table Source #
Represent's a SELECT * FROM .. query. It's the starting point to build a query.
Used together with the other functions to compose a sql query.
Example: Fetching all users
allUsers <- query @User |> fetch -- Runs a 'SELECT * FROM users' query
You can use it together with filterWhere:
activeUsers :: [User] <-
query @User
|> filterWhere (#active, True)
|> fetchbuildQuery :: forall (table :: Symbol). KnownSymbol table => QueryBuilder table -> SQLQuery Source #
Extract the SQLQuery from a QueryBuilder.
negateFilterOperator :: FilterOperator -> FilterOperator Source #
Returns the NOT version of an operator
>>>negateFilterOperator EqOpNotEqOp
qualifiedColumnName :: Text -> Text -> Text Source #
Build a qualified column name like tablename.column_name from a table name
and a camelCase field name. The field name is converted to snake_case via
fieldNameToColumnName.
This is intentionally NOINLINE: the call sites in filterWhere, orderBy, etc. are always lifted to CAFs (evaluated once at program start), so inlining only duplicates the Text.Inflections parsing logic and Text concatenation without any runtime benefit.