ihp-1.5.0: Haskell Web Framework
Copyright(c) digitally induced GmbH 2020
Safe HaskellNone
LanguageGHC2021

IHP.QueryBuilder.Compiler

Description

This module provides functions to compile a QueryBuilder into SQL.

Synopsis

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)
    |> fetch

buildQuery :: 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 EqOp
NotEqOp

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.