relational-query-0.9.4.1: Typeful, Modular, Relational, algebraic query engine

Copyright2013-2017 Kei Hibino
LicenseBSD3
Maintainerex8k.hibino@gmail.com
Stabilityexperimental
Portabilityunknown
Safe HaskellNone
LanguageHaskell2010

Database.Relational.Query.Projectable

Contents

Description

This module defines operators on various polymorphic projections.

Synopsis

Projectable from SQL strings

class SqlProjectable p where #

Interface to project SQL terms unsafely.

Minimal complete definition

unsafeProjectSqlTerms

Methods

unsafeProjectSqlTerms :: [StringSQL] -> p t #

Unsafely project from SQL expression terms.

unsafeProjectSql' :: SqlProjectable p => StringSQL -> p t #

Unsafely Project single SQL term.

unsafeProjectSql :: SqlProjectable p => String -> p t #

Unsafely Project single SQL string. String interface of unsafeProjectSql'.

Projections of values

value :: (ShowConstantTermsSQL t, OperatorProjectable p) => t -> p t #

Generate polymorphic projection of SQL constant values from Haskell value.

valueTrue :: (OperatorProjectable p, ProjectableMaybe p) => p (Maybe Bool) #

Polymorphic proejction of SQL true value.

valueFalse :: (OperatorProjectable p, ProjectableMaybe p) => p (Maybe Bool) #

Polymorphic proejction of SQL false value.

values :: (ShowConstantTermsSQL t, OperatorProjectable p) => [t] -> ListProjection p t #

Polymorphic proejction of SQL set value from Haskell list.

nothing :: (OperatorProjectable (Projection c), SqlProjectable (Projection c), PersistableWidth a) => Projection c (Maybe a) #

Polymorphic projection of SQL null value. Semantics of comparing is unsafe.

unsafeValueNull :: (OperatorProjectable (Projection c), SqlProjectable (Projection c), PersistableWidth a) => Projection c (Maybe a) #

Deprecated: Use nothing instead of this.

Deprecated. Polymorphic projection of SQL null value.

Placeholders

data PlaceHolders p #

Placeholder parameter type which has real parameter type arguemnt p.

Instances

ProjectableApplicative PlaceHolders #

Compose record type PlaceHolders using applicative style.

Methods

(|*|) :: PlaceHolders (a -> b) -> PlaceHolders a -> PlaceHolders b #

ProjectableFunctor PlaceHolders #

Compose seed of record type PlaceHolders.

Methods

(|$|) :: ProductConstructor (a -> b) => (a -> b) -> PlaceHolders a -> PlaceHolders b #

ProjectableIdZip PlaceHolders #

Zipping except for identity element laws against placeholder parameter type.

Methods

leftId :: PlaceHolders ((), a) -> PlaceHolders a #

rightId :: PlaceHolders (a, ()) -> PlaceHolders a #

ProjectableMaybe PlaceHolders #

Control phantom Maybe type in placeholder parameters.

unsafeAddPlaceHolders :: Functor f => f a -> f (PlaceHolders p, a) #

Unsafely add placeholder parameter to queries.

unsafePlaceHolders :: PlaceHolders p #

Unsafely get placeholder parameter

pwPlaceholder :: SqlProjectable p => PersistableRecordWidth a -> (p a -> b) -> (PlaceHolders a, b) #

Provide scoped placeholder from width and return its parameter object.

placeholder' :: (PersistableWidth t, SqlProjectable p) => (p t -> a) -> (PlaceHolders t, a) #

Provide scoped placeholder and return its parameter object.

placeholder :: (PersistableWidth t, SqlProjectable p, Monad m) => (p t -> m a) -> m (PlaceHolders t, a) #

Provide scoped placeholder and return its parameter object. Monadic version.

unitPlaceHolder :: PlaceHolders () #

No placeholder semantics

unitPH :: PlaceHolders () #

No placeholder semantics. Same as unitPlaceHolder

Projectable into SQL strings

class ProjectableShowSql p where #

Interface to get SQL term from projections.

Minimal complete definition

unsafeShowSql'

Methods

unsafeShowSql' :: p a -> StringSQL #

Unsafely generate SQL expression term from projection object.

Instances

ProjectableShowSql (Projection c) #

Unsafely get SQL term from Proejction.

unsafeShowSql #

Arguments

:: ProjectableShowSql p 
=> p a

Source projection object

-> String

Result SQL expression string.

Unsafely generate SQL expression string from projection object. String interface of unsafeShowSql'.

Operators

(.=.) :: (OperatorProjectable p, ProjectableShowSql p) => p ft -> p ft -> p (Maybe Bool) infix 4 #

Compare operator corresponding SQL = .

(.<.) :: (OperatorProjectable p, ProjectableShowSql p) => p ft -> p ft -> p (Maybe Bool) infix 4 #

Compare operator corresponding SQL < .

(.<=.) :: (OperatorProjectable p, ProjectableShowSql p) => p ft -> p ft -> p (Maybe Bool) infix 4 #

Compare operator corresponding SQL <= .

(.>.) :: (OperatorProjectable p, ProjectableShowSql p) => p ft -> p ft -> p (Maybe Bool) infix 4 #

Compare operator corresponding SQL > .

(.>=.) :: (OperatorProjectable p, ProjectableShowSql p) => p ft -> p ft -> p (Maybe Bool) infix 4 #

Compare operator corresponding SQL >= .

(.<>.) :: (OperatorProjectable p, ProjectableShowSql p) => p ft -> p ft -> p (Maybe Bool) infix 4 #

Compare operator corresponding SQL <> .

and' :: (OperatorProjectable p, ProjectableShowSql p) => p (Maybe Bool) -> p (Maybe Bool) -> p (Maybe Bool) infixr 3 #

Logical operator corresponding SQL AND .

or' :: (OperatorProjectable p, ProjectableShowSql p) => p (Maybe Bool) -> p (Maybe Bool) -> p (Maybe Bool) infixr 2 #

Logical operator corresponding SQL OR .

in' :: (OperatorProjectable p, ProjectableShowSql p) => p t -> ListProjection p t -> p (Maybe Bool) infix 4 #

Binary operator corresponding SQL IN .

(.||.) :: (OperatorProjectable p, ProjectableShowSql p, IsString a) => p a -> p a -> p a infixl 5 #

Concatinate operator corresponding SQL || .

(?||?) :: (OperatorProjectable p, ProjectableShowSql p, IsString a) => p (Maybe a) -> p (Maybe a) -> p (Maybe a) infixl 5 #

Concatinate operator corresponding SQL || . Maybe type version.

like :: (OperatorProjectable p, ProjectableShowSql p, IsString a, ShowConstantTermsSQL a) => p a -> a -> p (Maybe Bool) infix 4 #

String-compare operator corresponding SQL LIKE .

likeMaybe :: (OperatorProjectable p, ProjectableShowSql p, IsString a, ShowConstantTermsSQL a) => p (Maybe a) -> a -> p (Maybe Bool) infix 4 #

String-compare operator corresponding SQL LIKE . Maybe type version.

like' :: (OperatorProjectable p, ProjectableShowSql p, IsString a) => p a -> p a -> p (Maybe Bool) infix 4 #

String-compare operator corresponding SQL LIKE .

likeMaybe' :: (OperatorProjectable p, ProjectableShowSql p, IsString a) => p (Maybe a) -> p (Maybe a) -> p (Maybe Bool) infix 4 #

String-compare operator corresponding SQL LIKE .

(.+.) :: (OperatorProjectable p, ProjectableShowSql p, Num a) => p a -> p a -> p a infixl 6 #

Number operator corresponding SQL + .

(.-.) :: (OperatorProjectable p, ProjectableShowSql p, Num a) => p a -> p a -> p a infixl 6 #

Number operator corresponding SQL - .

(.*.) :: (OperatorProjectable p, ProjectableShowSql p, Num a) => p a -> p a -> p a infixl 7 #

Number operator corresponding SQL * .

(./.) :: (OperatorProjectable p, ProjectableShowSql p, Num a) => p a -> p a -> p a infixl 7 #

Number operator corresponding SQL /// .

(?+?) :: (OperatorProjectable p, ProjectableShowSql p, Num a) => p (Maybe a) -> p (Maybe a) -> p (Maybe a) infixl 6 #

Number operator corresponding SQL + .

(?-?) :: (OperatorProjectable p, ProjectableShowSql p, Num a) => p (Maybe a) -> p (Maybe a) -> p (Maybe a) infixl 6 #

Number operator corresponding SQL - .

(?*?) :: (OperatorProjectable p, ProjectableShowSql p, Num a) => p (Maybe a) -> p (Maybe a) -> p (Maybe a) infixl 7 #

Number operator corresponding SQL * .

(?/?) :: (OperatorProjectable p, ProjectableShowSql p, Num a) => p (Maybe a) -> p (Maybe a) -> p (Maybe a) infixl 7 #

Number operator corresponding SQL /// .

isNothing :: (OperatorProjectable (Projection c), ProjectableShowSql (Projection c), HasColumnConstraint NotNull r) => Projection c (Maybe r) -> Projection c (Maybe Bool) #

Operator corresponding SQL IS NULL , and extended against record types.

isJust :: (OperatorProjectable (Projection c), ProjectableShowSql (Projection c), HasColumnConstraint NotNull r) => Projection c (Maybe r) -> Projection c (Maybe Bool) #

Operator corresponding SQL NOT (... IS NULL) , and extended against record type.

fromMaybe :: (OperatorProjectable (Projection c), ProjectableShowSql (Projection c), HasColumnConstraint NotNull r) => Projection c r -> Projection c (Maybe r) -> Projection c r #

Operator from maybe type using record extended isNull.

not' :: (OperatorProjectable p, ProjectableShowSql p) => p (Maybe Bool) -> p (Maybe Bool) #

Logical operator corresponding SQL NOT .

exists :: (OperatorProjectable p, ProjectableShowSql p) => ListProjection (Projection Exists) r -> p (Maybe Bool) #

Logical operator corresponding SQL EXISTS .

negate' :: (OperatorProjectable p, ProjectableShowSql p, Num a) => p a -> p a #

Number negate uni-operator corresponding SQL -.

fromIntegral' :: (SqlProjectable p, ProjectableShowSql p, Integral a, Num b) => p a -> p b #

Number fromIntegral uni-operator.

showNum :: (SqlProjectable p, ProjectableShowSql p, Num a, IsString b) => p a -> p b #

Unsafely show number into string-like type in projections.

negateMaybe :: (OperatorProjectable p, ProjectableShowSql p, Num a) => p (Maybe a) -> p (Maybe a) #

Number negate uni-operator corresponding SQL -.

fromIntegralMaybe :: (SqlProjectable p, ProjectableShowSql p, Integral a, Num b) => p (Maybe a) -> p (Maybe b) #

Number fromIntegral uni-operator.

showNumMaybe :: (SqlProjectable p, ProjectableShowSql p, Num a, IsString b) => p (Maybe a) -> p (Maybe b) #

Unsafely show number into string-like type in projections.

casesOrElse #

Arguments

:: OperatorProjectable (Projection c) 
=> [(Projection c (Maybe Bool), Projection c a)]

Each when clauses

-> Projection c a

Else result projection

-> Projection c a

Result projection

Same as caseSearch, but you can write like list casesOrElse clause.

casesOrElse' #

Arguments

:: OperatorProjectable (Projection c) 
=> (Projection c a, [(Projection c a, Projection c b)])

Projection value to match and each when clauses list

-> Projection c b

Else result projection

-> Projection c b

Result projection

Uncurry version of case', and you can write like ... casesOrElse' clause.

caseSearch #

Arguments

:: OperatorProjectable (Projection c) 
=> [(Projection c (Maybe Bool), Projection c a)]

Each when clauses

-> Projection c a

Else result projection

-> Projection c a

Result projection

Search case operator correnponding SQL search CASE. Like, CASE WHEN p0 THEN a WHEN p1 THEN b ... ELSE c END

caseSearchMaybe #

Arguments

:: (OperatorProjectable (Projection c), PersistableWidth a) 
=> [(Projection c (Maybe Bool), Projection c (Maybe a))]

Each when clauses

-> Projection c (Maybe a)

Result projection

Null default version of caseSearch.

case' #

Arguments

:: OperatorProjectable (Projection c) 
=> Projection c a

Projection value to match

-> [(Projection c a, Projection c b)]

Each when clauses

-> Projection c b

Else result projection

-> Projection c b

Result projection

Simple case operator correnponding SQL simple CASE. Like, CASE x WHEN v THEN a WHEN w THEN b ... ELSE c END

caseMaybe #

Arguments

:: (OperatorProjectable (Projection c), PersistableWidth b) 
=> Projection c a

Projection value to match

-> [(Projection c a, Projection c (Maybe b))]

Each when clauses

-> Projection c (Maybe b)

Result projection

Null default version of case'.

type SqlBinOp = Keyword -> Keyword -> Keyword #

Binary operator type for SQL String.

unsafeBinOp :: (SqlProjectable p, ProjectableShowSql p) => SqlBinOp -> p a -> p b -> p c #

Unsafely make projection binary operator from string binary operator.

unsafeUniOp :: (ProjectableShowSql p0, SqlProjectable p1) => (Keyword -> Keyword) -> p0 a -> p1 b #

Unsafely make projection unary operator from SQL keyword.

Terms for Window function types

rank :: Integral a => Projection OverWindow a #

RANK() term.

denseRank :: Integral a => Projection OverWindow a #

DENSE_RANK() term.

rowNumber :: Integral a => Projection OverWindow a #

ROW_NUMBER() term.

percentRank :: Projection OverWindow Double #

PERCENT_RANK() term.

cumeDist :: Projection OverWindow Double #

CUME_DIST() term.

Zipping projections

projectZip :: ProjectableApplicative p => p a -> p b -> p (a, b) #

Zipping projections.

(><) :: ProjectableApplicative p => p a -> p b -> p (a, b) infixl 1 #

Binary operator the same as projectZip.

class ProjectableApplicative p => ProjectableIdZip p where #

Zipping except for identity element laws.

Minimal complete definition

leftId, rightId

Methods

leftId :: p ((), a) -> p a #

rightId :: p (a, ()) -> p a #

Instances

ProjectableIdZip PlaceHolders #

Zipping except for identity element laws against placeholder parameter type.

Methods

leftId :: PlaceHolders ((), a) -> PlaceHolders a #

rightId :: PlaceHolders (a, ()) -> PlaceHolders a #

Maybe type projecitoins

class ProjectableMaybe p where #

Interface to control Maybe of phantom type in projections.

Minimal complete definition

just, flattenMaybe

Methods

just :: p a -> p (Maybe a) #

Cast projection phantom type into Maybe.

flattenMaybe :: p (Maybe (Maybe a)) -> p (Maybe a) #

Compose nested Maybe phantom type on projection.

Instances

ProjectableMaybe PlaceHolders #

Control phantom Maybe type in placeholder parameters.

ProjectableMaybe (Projection c) #

Control phantom Maybe type in projection type Projection.

Methods

just :: Projection c a -> Projection c (Maybe a) #

flattenMaybe :: Projection c (Maybe (Maybe a)) -> Projection c (Maybe a) #