| 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 {k} (table :: Symbol) queryBuilderProvider (joinRegister :: k). (KnownSymbol table, HasQueryBuilder queryBuilderProvider joinRegister) => queryBuilderProvider table -> SQLQuery
- negateFilterOperator :: FilterOperator -> FilterOperator
- compileSQLQuery :: forall (table :: Symbol). Maybe Text -> QueryBuilder table -> SQLQuery
- 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 {k} (table :: Symbol) queryBuilderProvider (joinRegister :: k). (KnownSymbol table, HasQueryBuilder queryBuilderProvider joinRegister) => queryBuilderProvider table -> SQLQuery Source #
negateFilterOperator :: FilterOperator -> FilterOperator Source #
Returns the NOT version of an operator
>>>negateFilterOperator EqOpNotEqOp
compileSQLQuery :: forall (table :: Symbol). Maybe Text -> QueryBuilder table -> SQLQuery Source #
Traverse a QueryBuilder tree and produce an SQLQuery.
Defined at the top level so the recursive case analysis is shared across
all inlined call sites of buildQuery. The tiny buildQuery wrapper
stays INLINE to resolve the HasQueryBuilder dictionary, then hands off
to this shared worker.
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.