groundhog-0.5.1: Type-safe datatype-database mapping library.

Safe HaskellNone

Database.Groundhog.Generic.Sql

Contents

Description

This module defines the functions which are used only for backends creation.

Synopsis

SQL rendering utilities

renderCond :: SqlDb db => RenderConfig -> Cond db r -> Maybe (RenderS db r)Source

Renders conditions for SQL backend. Returns Nothing if the fields don't have any columns.

mkExprWithConf :: (SqlDb db, PersistField a) => (RenderConfig -> Int -> Expr db r a) -> Expr db r aSource

prerenderExpr :: SqlDb db => RenderConfig -> Expr db r a -> Expr db r aSource

If we reuse complex expression several times, prerendering it saves time. RenderConfig can be obtained with mkExprWithConf

intercalateS :: StringLike s => s -> [s] -> sSource

commasJoin :: StringLike s => [s] -> sSource

flatten :: (Utf8 -> Utf8) -> (String, DbType) -> [Utf8] -> [Utf8]Source

data RenderS db r Source

Constructors

RenderS 

Instances

IsString (RenderS db r) 
Monoid (RenderS db r) 
StringLike (RenderS db r) 

newtype Utf8 Source

Datatype for incremental building SQL queries

Constructors

Utf8 Builder 

newtype RenderConfig Source

Constructors

RenderConfig 

Fields

esc :: Utf8 -> Utf8
 

class (Monoid a, IsString a) => StringLike a whereSource

Methods

fromChar :: Char -> aSource

(<>) :: Monoid m => m -> m -> m

An infix synonym for mappend.

function :: SqlDb db => String -> [UntypedExpr db r] -> Snippet db rSource

operator :: (SqlDb db, Expression db r a, Expression db r b) => Int -> String -> a -> b -> Snippet db rSource

parens :: Int -> Int -> RenderS db r -> RenderS db rSource

mkExpr :: SqlDb db => Snippet db r -> Expr db r aSource

newtype Snippet db r Source

Escape function, priority of the outer operator. The result is a list for the embedded data which may expand to several RenderS.

Constructors

Snippet (RenderConfig -> Int -> [RenderS db r]) 

class (DbDescriptor db, QueryRaw db ~ Snippet db) => SqlDb db whereSource

This class distinguishes databases which support SQL-specific expressions. It contains ad hoc members for features whose syntax differs across the databases.

Methods

append :: (ExpressionOf db r a String, ExpressionOf db r b String) => a -> b -> Expr db r StringSource

signum' :: (ExpressionOf db r x a, Num a) => x -> Expr db r aSource

quotRem' :: (ExpressionOf db r x a, ExpressionOf db r y a, Integral a) => x -> y -> (Expr db r a, Expr db r a)Source

equalsOperator :: RenderS db r -> RenderS db r -> RenderS db rSource

notEqualsOperator :: RenderS db r -> RenderS db r -> RenderS db rSource

class SqlDb db => FloatingSqlDb db whereSource

This class distinguishes databases which support trigonometry and other math functions. For example, PostgreSQL has them but Sqlite does not. It contains ad hoc members for features whose syntax differs across the databases.

Methods

log' :: (ExpressionOf db r x a, Floating a) => x -> Expr db r aSource

Natural logarithm

logBase' :: (ExpressionOf db r b a, ExpressionOf db r x a, Floating a) => b -> x -> Expr db r aSource

tableName :: StringLike s => (s -> s) -> EntityDef -> ConstructorDef -> sSource

Returns escaped table name optionally qualified with schema

mainTableName :: StringLike s => (s -> s) -> EntityDef -> sSource

Returns escaped main table name optionally qualified with schema