MetaHDBC-0.1.4: Statically checked database access

Safe HaskellNone
LanguageHaskell98

Database.MetaHDBC.SqlExpr

Contents

Synopsis

Documentation

runStmt Source

Arguments

:: String

Data source name (DSN)

-> String

SQL statement extended with question marks for parameteres

-> ExpQ

The expression has type Connection -> a1 -> ... -> an -> IO [x1, ... xm]), where a1-an are inputs to the statement (due to placeholder arguments), and x1-xm are the outputs from the statement.

If there are no outputs from the statement (e.g. an insert statement) the number of affected rows is returned.

Statically typed one-off (not prepared) SQL statement.

prepareStmt Source

Arguments

:: String

Data source name (DSN)

-> String

SQL statement extended with question marks for parameteres

-> ExpQ

The expression has type Connection -> IO (a1 -> ... -> an -> IO [x1, ... xm]), where a1-an are inputs to the statement (due to placeholder arguments), and x1-xm are the outputs from the statement.

If there are no outputs from the statement (e.g. an insert statement) the number of affected rows is returned.

Statically typed prepared SQL statement.

strict :: IO [a] -> IO [a] Source

Makes the query result from prepareStmt or runStmt strict.

data ExprParts Source

Common parts for both statements run directly (runStmt) and prepared statements.

Constructors

ExprParts 

Fields

parameters :: [Parameter]

Positional parameters

returnTypes :: [SqlColDesc]

Description of values returned from a SQL statement

dbSqlExpr :: String

The SQL expression which is passed on to the database

connectionName :: Name

Name of the Connection parameter.

data Parameter Source

Describing a positional parameter

Constructors

Parameter 

data PrepareParts Source

Parts used in prepared statements

Constructors

PrepareParts 

sqlInfo :: String -> String -> IO String Source

Returns textual information about a query. The returned String is useful as presentation to a user, not for further processing.

makeExprParts :: String -> String -> Q ExprParts Source

Contructs expression-parts. A database is contacted to parse the SQL and infer correct types.

Helper functions to construct directly runned statements (runStmt)

runStmtLHS Source

Arguments

:: ExprParts 
-> ExpQ

Expression which is expected to access the database

-> ExpQ 

Constructs a lambda which given a connection and parameters will execute expr. See runStmtRHS.

runStmtRHS :: ExprParts -> ExpQ Source

Creates an exprresion which runs a SQL statement on a database server. It is expected that the connection variable and parameters has already been bound. See also runStmtLHS.

Helper function to construct prepared statements

makePrepStmtParts :: String -> String -> Q PrepareParts Source

Creates parts for a prepared statement. Calls makeExprParts.

prepStmtLHS :: PrepareParts -> [StmtQ] -> ExpQ Source

Lambda for prepared statements.

prepStmtQ :: PrepareParts -> StmtQ Source

A StmtQ which prepares a statement on a database.

execPrepStmtRHS :: PrepareParts -> StmtQ Source

A StmtQ to execute a statement on a database.

returnExecPrepStmtLHS :: PrepareParts -> [StmtQ] -> StmtQ Source

Creates a StmtQ of type: IO (a1-an -> IO ... ). Where a1-an are the parameters which must be bound.

Multiline quasi quotation