QueryDsl
- Package
- purescript-querydsl
- Repository
- Dretch/purescript-querydsl
A type-safe and composable SQL query builder.
#Constant Source
data Constant
Values that can be stored in database columns
Constructors
StringConstant String
IntConstant Int
NumberConstant Number
DateTimeConstant DateTime
BufferConstant ImmutableBuffer
NullConstant
Instances
#FromConstantConfig Source
type FromConstantConfig = { unformatDateTime :: String -> Maybe DateTime }
Passed to fromConstant
to configure how values are converted from constants.
#defaultFromConstantConfig Source
defaultFromConstantConfig :: FromConstantConfig
The default configuration does nothing.
#Column Source
newtype Column typ (required :: Boolean)
A column within a table, with the column type and optionality represented in the type of the Column
Instances
ToExpression (Column typ required) typ
(ApplyTableColumns colsRLTail colsRTail, SqlType typ, IsSymbol name, Cons name (Column typ required) colsRTail colsR, Lacks name colsRTail) => ApplyTableColumns (Cons name (Column typ required) colsRLTail) colsR
(ApplyInsertExpressions colsRLTail exprsRLTail exprsRTail, IsSymbol name, SqlType typ, Cons name typ exprsRTail exprsR, Lacks name exprsRTail) => ApplyInsertExpressions (Cons name (Column typ False) colsRLTail) (Cons name typ exprsRLTail) exprsR
(ApplyInsertExpressions colsRLTail exprsRL exprsR) => ApplyInsertExpressions (Cons name (Column typ False) colsRLTail) exprsRL exprsR
(ApplyInsertExpressions colsRLTail exprsRLTail exprsRTail, IsSymbol name, SqlType typ, Cons name typ exprsRTail exprsR, Lacks name exprsRTail) => ApplyInsertExpressions (Cons name (Column typ True) colsRLTail) (Cons name typ exprsRLTail) exprsR
(ApplyUpdateExpressions colsRLTail exprsRLTail exprsRTail, IsSymbol name, ToExpression toExpr typ, Cons name toExpr exprsRTail exprsR, Lacks name exprsRTail) => ApplyUpdateExpressions (Cons name (Column typ required) colsRLTail) (Cons name toExpr exprsRLTail) exprsR
#SelectQuery Source
type SelectQuery results = SelectTableBuilder (SelectEndpoint results)
A query that selects data, with the type of the columns in the result represented in the type of the SelectQuery
#SelectTableBuilder Source
#SelectEndpoint Source
data SelectEndpoint (results :: Row Type)
The select columns and the where-clause/order-by/limit/etc part of a select query
Instances
Query (SelectTableBuilder (SelectEndpoint results))
#UntypedExpression Source
data UntypedExpression
#ToExpression Source
class ToExpression a result | a -> result where
Members
toExpression :: a -> Expression result
Instances
ToExpression (Column typ required) typ
ToExpression (Expression result) result
(SqlType a) => ToExpression a a
#BinaryOperator Source
type BinaryOperator a b input result = ToExpression a input => ToExpression b input => a -> b -> Expression result
#UnaryOperator Source
type UnaryOperator a input result = ToExpression a input => a -> Expression result
#ParameterizedSql Source
#ErrorMessage Source
type ErrorMessage = String
#alwaysTrue Source
alwaysTrue :: Expression Boolean
An expression that always evaluates to true
. This is useful when a filtering
expression argument is required but you don't want to actually filter the result.
#TableColumns Source
class TableColumns (cols :: Row Type) where
An instance of this type class is automatically derived by the compiler for
rows where each field in the row matches name: Column typ required
, representing
a database table column called name
, having a database type compatible with
the Purescript type typ
, and being required or optional on insert according to required
Members
getTableColumns :: RProxy cols -> TableName -> Record cols
Instances
(RowToList colsR colsRL, ApplyTableColumns colsRL colsR) => TableColumns colsR
#ApplyTableColumns Source
class ApplyTableColumns (colsRL :: RowList) (colsR :: Row Type) | colsRL -> colsR where
Members
getTableColumns' :: RLProxy colsRL -> RProxy colsR -> TableName -> Builder (Record ()) (Record colsR)
Instances
ApplyTableColumns Nil ()
(ApplyTableColumns colsRLTail colsRTail, SqlType typ, IsSymbol name, Cons name (Column typ required) colsRTail colsR, Lacks name colsRTail) => ApplyTableColumns (Cons name (Column typ required) colsRLTail) colsR
#makeTable Source
makeTable :: forall cols. TableColumns cols => String -> Table cols
Makes a table with a given name, taking the column information from the declared type.
#from Source
from :: forall cols. Table cols -> SelectTableBuilder (Record cols)
Starts a SelectTableBuilder by specifying the initial table.
#innerJoin Source
innerJoin :: forall cols. Table cols -> (Record cols -> Expression Boolean) -> SelectTableBuilder (Record cols)
Extends a SelectTableBuilder by specifying an (inner) join table.
#leftJoin Source
leftJoin :: forall cols. Table cols -> (Record cols -> Expression Boolean) -> SelectTableBuilder (Record cols)
Extends a SelectTableBuilder by specifying a (left outer) join table.
#crossJoin Source
crossJoin :: forall cols. Table cols -> SelectTableBuilder (Record cols)
Extends a SelectTableBuilder by specifying a (cross) join table.
#select Source
select :: forall results exprs. SelectExpressions exprs results => Record exprs -> SelectEndpoint results
Creates a new SelectEndpoint with the given selected columns
#where_ Source
where_ :: forall results. SelectEndpoint results -> Expression Boolean -> SelectEndpoint results
Sets the where clause to use on the SelectEndpoint
#limit Source
limit :: forall results. SelectEndpoint results -> Int -> SelectEndpoint results
Sets the limit (maximum number of rows in the result) to use on the SelectEndpoint.
#offset Source
offset :: forall results. SelectEndpoint results -> Int -> SelectEndpoint results
Sets the offset (how many rows to skip from the result) to use on the SelectEndpoint.
#OrderingExpression Source
data OrderingExpression
An expression that determines how the results are ordered.
#asc Source
asc :: forall b a. ToExpression a b => a -> OrderingExpression
Create an OrderingExpression that says to order by the given expression in ascending order
#desc Source
desc :: forall b a. ToExpression a b => a -> OrderingExpression
Create an OrderingExpression that says to order by the given expression in descending order
#orderBy Source
orderBy :: forall results. SelectEndpoint results -> Array OrderingExpression -> SelectEndpoint results
Sets the ordering to use on the SelectEndpoint
#groupBy Source
groupBy :: forall b a results. ToExpression a b => SelectEndpoint results -> a -> SelectEndpoint results
Adds a column to the group by clause - note this function is cumulative: call it multiple times to group by more than one expression.
#having Source
having :: forall results. SelectEndpoint results -> Expression Boolean -> SelectEndpoint results
Sets the having expression to use on the SelectEndpoint.
#update Source
update :: forall exprs cols. UpdateExpressions cols exprs => Table cols -> Record exprs -> Expression Boolean -> UpdateQuery
#insertInto Source
insertInto :: forall exprs cols. InsertExpressions cols exprs => Table cols -> Record exprs -> InsertQuery
#deleteFrom Source
deleteFrom :: forall cols. Table cols -> Expression Boolean -> DeleteQuery
#InsertExpressions Source
class InsertExpressions (cols :: Row Type) (exprs :: Row Type) | cols -> exprs, exprs -> cols where
Instances of this type class are automatically derived by the compiler for
pairs of row types where each field in exprs
matches a column in cols
Members
getInsertExpressions :: Record exprs -> List (Tuple ColumnName Constant)
Instances
(RowToList colsR colsRL, RowToList exprsR exprsRL, ApplyInsertExpressions colsRL exprsRL exprsR) => InsertExpressions colsR exprsR
#ApplyInsertExpressions Source
class ApplyInsertExpressions (colsRL :: RowList) (exprsRL :: RowList) (exprsR :: Row Type) where
Members
getInsertExpressions' :: RLProxy colsRL -> RLProxy exprsRL -> RProxy exprsR -> Record exprsR -> List (Tuple ColumnName Constant)
Instances
ApplyInsertExpressions Nil Nil exprsR
(ApplyInsertExpressions colsRLTail exprsRLTail exprsRTail, IsSymbol name, SqlType typ, Cons name typ exprsRTail exprsR, Lacks name exprsRTail) => ApplyInsertExpressions (Cons name (Column typ False) colsRLTail) (Cons name typ exprsRLTail) exprsR
(ApplyInsertExpressions colsRLTail exprsRL exprsR) => ApplyInsertExpressions (Cons name (Column typ False) colsRLTail) exprsRL exprsR
(ApplyInsertExpressions colsRLTail exprsRLTail exprsRTail, IsSymbol name, SqlType typ, Cons name typ exprsRTail exprsR, Lacks name exprsRTail) => ApplyInsertExpressions (Cons name (Column typ True) colsRLTail) (Cons name typ exprsRLTail) exprsR
#SelectExpressions Source
class SelectExpressions (exprs :: Row Type) (result :: Row Type) | exprs -> result where
Members
getSelectExpressions :: Record exprs -> List (Tuple ColumnName UntypedExpression)
Instances
(RowToList exprsR exprsRL, RowToList resultsR resultsRL, ApplySelectExpressions exprsRL exprsR resultsRL) => SelectExpressions exprsR resultsR
#ApplySelectExpressions Source
class ApplySelectExpressions (exprsRL :: RowList) (exprsR :: Row Type) (resultsRL :: RowList) where
Members
getSelectExpressions' :: RLProxy exprsRL -> Record exprsR -> RLProxy resultsRL -> List (Tuple ColumnName UntypedExpression)
Instances
ApplySelectExpressions Nil exprsR Nil
(ApplySelectExpressions exprsRLTail exprsRTail resultsRLTail, IsSymbol name, ToExpression toExpr typ, Cons name toExpr exprsRTail exprsR, Lacks name exprsRTail) => ApplySelectExpressions (Cons name toExpr exprsRLTail) exprsR (Cons name typ resultsRLTail)
#UpdateExpressions Source
class UpdateExpressions (cols :: Row Type) (exprs :: Row Type) where
An instance of this type class is automatically derived by the compiler when
each item in exprs
matches a column of the same name and type in cols
.
Members
getUpdateExpressions :: Record cols -> Record exprs -> List (Tuple ColumnName UntypedExpression)
Instances
(RowToList colsR colsRL, RowToList exprsR exprsRL, ApplyUpdateExpressions colsRL exprsRL exprsR) => UpdateExpressions colsR exprsR
#ApplyUpdateExpressions Source
class ApplyUpdateExpressions (colsRL :: RowList) (exprsRL :: RowList) (exprsR :: Row Type) where
Members
getUpdateExpressions' :: RLProxy colsRL -> RLProxy exprsRL -> Record exprsR -> List (Tuple ColumnName UntypedExpression)
Instances
ApplyUpdateExpressions colsRL Nil exprsR
(ApplyUpdateExpressions colsRLTail exprsRLTail exprsRTail, IsSymbol name, ToExpression toExpr typ, Cons name toExpr exprsRTail exprsR, Lacks name exprsRTail) => ApplyUpdateExpressions (Cons name (Column typ required) colsRLTail) (Cons name toExpr exprsRLTail) exprsR
#prefixOperator Source
prefixOperator :: forall result input a. String -> UnaryOperator a input result
#postfixOperator Source
postfixOperator :: forall result input a. String -> UnaryOperator a input result
#binaryOperator Source
binaryOperator :: forall result input b a. String -> BinaryOperator a b input result
#unaryAggregateFunction Source
unaryAggregateFunction :: forall result input a. String -> Boolean -> UnaryOperator a input result
#nullaryFunction Source
nullaryFunction :: forall result. String -> Expression result
#Query Source
#expressionSql Source
expressionSql :: forall result. Expression result -> Either ErrorMessage ParameterizedSql
#ConstantsToRecord Source
class ConstantsToRecord (r :: Row Type) where
Members
constantsToRecord :: RProxy r -> FromConstantConfig -> Map String Constant -> Either ErrorMessage (Record r)
Create a Record value of the required type from a dynamically typed Map of fields (e.g. returned from running a database query), if possible, otherwise provide an error message.
Instances
(RowToList r rl, ApplyConstantsToRecord r rl) => ConstantsToRecord r
#ApplyConstantsToRecord Source
class ApplyConstantsToRecord (r :: Row Type) (rl :: RowList) | rl -> r where
Members
constantsToRecord' :: RLProxy rl -> FromConstantConfig -> Map String Constant -> Either ErrorMessage (Builder (Record ()) (Record r))
Instances
ApplyConstantsToRecord () Nil
(ApplyConstantsToRecord rTail rlTail, IsSymbol name, SqlType typ, Cons name typ rTail r, Lacks name rTail) => ApplyConstantsToRecord r (Cons name typ rlTail)
Gets some SQL to be run against an actual database.