relational-record-examples-0.5.1.1: Examples of Haskell Relationa Record

Safe HaskellNone
LanguageHaskell2010

Database.Relational.Query.SQLite3

Synopsis

Documentation

throwSqlError :: SqlError -> IO a #

A utility function to throw a SqlError. The mechanics of throwing such a thing differ between GHC 6.8.x, Hugs, and GHC 6.10. This function takes care of the special cases to make it simpler.

With GHC 6.10, it is a type-restricted alias for throw. On all other systems, it is a type-restricted alias for throwDyn.

quickQuery' :: IConnection conn => conn -> String -> [SqlValue] -> IO [[SqlValue]] #

Strict version of quickQuery.

quickQuery :: IConnection conn => conn -> String -> [SqlValue] -> IO [[SqlValue]] #

A quick way to do a query. Similar to preparing, executing, and then calling fetchAllRows on a statement. See also quickQuery'.

fetchAllRowsMap :: Statement -> IO [Map String SqlValue] #

Like fetchAllRowsAL, but return a list of Maps instead of a list of association lists.

fetchAllRowsAL' :: Statement -> IO [[(String, SqlValue)]] #

Strict version of fetchAllRowsAL

fetchAllRowsAL :: Statement -> IO [[(String, SqlValue)]] #

Like fetchAllRows, but instead of returning a list for each row, return an association list for each row, from column name to value.

See fetchRowAL for more details.

fetchRowMap :: Statement -> IO (Maybe (Map String SqlValue)) #

Similar to fetchRowAL, but return a Map instead of an association list.

fetchRowAL :: Statement -> IO (Maybe [(String, SqlValue)]) #

Like fetchRow, but instead of returning a list, return an association list from column name to value.

The keys of the column names are lowercase versions of the data returned by getColumnNames. Please heed the warnings there. Additionally, results are undefined if multiple columns are returned with identical names.

sFetchAllRows' :: Statement -> IO [[Maybe String]] #

Strict version of sFetchAllRows.

sFetchAllRows :: Statement -> IO [[Maybe String]] #

Like fetchAllRows, but return Maybe Strings instead of SqlValues.

fetchAllRows' :: Statement -> IO [[SqlValue]] #

Strict version of fetchAllRows. Does not have the side-effects of fetchAllRows, but forces the entire result set to be buffered in memory.

fetchAllRows :: Statement -> IO [[SqlValue]] #

Lazily fetch all rows from an executed Statement.

You can think of this as hGetContents applied to a database result set.

The result of this is a lazy list, and each new row will be read, lazily, from the database as the list is processed.

When you have exhausted the list, the Statement will be finished.

Please note that the careless use of this function can lead to some unpleasant behavior. In particular, if you have not consumed the entire list, then attempt to finish or re-execute the statement, and then attempt to consume more elements from the list, the result will almost certainly not be what you want.

But then, similar caveats apply with hGetContents.

Bottom line: this is a very convenient abstraction; use it wisely.

Use fetchAllRows' if you need something that is strict, without all these caveats.

withTransaction :: IConnection conn => conn -> (conn -> IO a) -> IO a #

Execute some code. If any uncaught exception occurs, run rollback and re-raise it. Otherwise, run commit and return.

This function, therefore, encapsulates the logical property that a transaction is all about: all or nothing.

The IConnection object passed in is passed directly to the specified function as a convenience.

This function traps all uncaught exceptions, not just SqlErrors. Therefore, you will get a rollback for any exception that you don't handle. That's probably what you want anyway.

Since all operations in HDBC are done in a transaction, this function doesn't issue an explicit "begin" to the server. You should ideally have called commit or rollback before calling this function. If you haven't, this function will commit or rollback more than just the changes made in the included action.

If there was an error while running rollback, this error will not be reported since the original exception will be propogated back. (You'd probably like to know about the root cause for all of this anyway.) Feedback on this behavior is solicited.

sFetchRow :: Statement -> IO (Maybe [Maybe String]) #

Like fetchRow, but return a list of Maybe Strings instead of SqlValues.

sExecuteMany :: Statement -> [[Maybe String]] -> IO () #

Like executeMany, but take a list of Maybe Strings instead of SqlValues.

sExecute :: Statement -> [Maybe String] -> IO Integer #

Like execute, but take a list of Maybe Strings instead of SqlValues.

sRun :: IConnection conn => conn -> String -> [Maybe String] -> IO Integer #

Like run, but take a list of Maybe Strings instead of SqlValues.

handleSqlError :: IO a -> IO a #

Catches SqlErrors, and re-raises them as IO errors with fail. Useful if you don't care to catch SQL errors, but want to see a sane error message if one happens. One would often use this as a high-level wrapper around SQL calls.

sqlExceptions :: SqlError -> Maybe SqlError #

Given an Exception, return Just SqlError if it was an SqlError, or Nothing otherwise. Useful with functions like catchJust.

handleSql :: (SqlError -> IO a) -> IO a -> IO a #

Like catchSql, with the order of arguments reversed.

catchSql :: IO a -> (SqlError -> IO a) -> IO a #

Execute the given IO action.

If it raises a SqlError, then execute the supplied handler and return its return value. Otherwise, proceed as normal.

withWConn :: ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b #

Unwrap a ConnWrapper and pass the embedded IConnection to a function. Example:

withWConn wrapped run $ "SELECT * from foo where bar = 1" []

class IConnection conn where #

Main database handle object.

An IConnection object is created by specific functions in the module for an individual database. That is, the connect function -- which creates this object -- is not standardized through the HDBC interface.

A connection is closed by a call to disconnect.

A call to commit is required to make sure that your changes get committed to the database. In other words, HDBC has no support for autocommit, which we consider an outdated notion.

Methods

disconnect :: conn -> IO () #

Disconnect from the remote database.

You do not need to explicitly close an IConnection object, but you may do so if you so desire. If you don't, the object will disconnect from the database in a sane way when it is garbage-collected. However, a disconnection may raise an error, so you are encouraged to explicitly call disconnect. Also, garbage collection may not run when the program terminates, and some databases really like an explicit disconnect.

So, bottom line is, you're best off calling disconnect directly, but the world won't end if you forget.

This function discards any data not committed already. Database driver implementators should explicitly call rollback if their databases don't do this automatically on disconnect.

Bad Things (TM) could happen if you call this while you have Statements active. In more precise language, the results in such situations are undefined and vary by database. So don't do it.

commit :: conn -> IO () #

Commit any pending data to the database.

Required to make any changes take effect.

rollback :: conn -> IO () #

Roll back to the state the database was in prior to the last commit or rollback.

runRaw :: conn -> String -> IO () #

Execute an SQL string, which may contain multiple queries. This is intended for situations where you need to run DML or DDL queries and aren't interested in results.

prepare :: conn -> String -> IO Statement #

Prepares a statement for execution.

Question marks in the statement will be replaced by positional parameters in a later call to execute.

Please note that, depending on the database and the driver, errors in your SQL may be raised either here or by execute. Make sure you handle exceptions both places if necessary.

clone :: conn -> IO conn #

Create a new Connection object, pointed at the same server as this object is. This will generally establish a separate physical connection.

When you wish to establish multiple connections to a single server, the correct way to do so is to establish the first connection with the driver-specific connection function, and then clone it for each additional connection.

This can be important when a database doesn't provide much thread support itself, and the HDBC driver module must serialize access to a particular database.

This can also be a handy utility function whenever you need a separate connection to whatever database you are connected to already.

hdbcDriverName :: conn -> String #

The name of the HDBC driver module for this connection. Ideally would be the same as the database name portion of the Cabal package name. For instance, "sqlite3" or "odbc". This is the layer that is bound most tightly to HDBC.

hdbcClientVer :: conn -> String #

The version of the C (or whatever) client library that the HDBC driver module is bound to. The meaning of this is driver-specific. For an ODBC or similar proxying driver, this should be the version of the ODBC library, not the eventual DB client driver.

proxiedClientName :: conn -> String #

In the case of a system such as ODBC, the name of the database client/server in use, if available. For others, identical to hdbcDriverName.

proxiedClientVer :: conn -> String #

In the case of a system such as ODBC, the version of the database client in use, if available. For others, identical to hdbcClientVer. This is the next layer out past the HDBC driver.

dbServerVer :: conn -> String #

The version of the database server, if available.

dbTransactionSupport :: conn -> Bool #

Whether or not the current database supports transactions. If False, then commit and rollback should be expected to raise errors.

MySQL is the only commonly-used database that is known to not support transactions entirely. Please see the MySQL notes in the ODBC driver for more information.

getTables :: conn -> IO [String] #

The names of all tables accessible by the current connection, excluding special meta-tables (system tables).

You should expect this to be returned in the same manner as a result from fetchAllRows'.

All results should be converted to lowercase for you before you see them.

describeTable :: conn -> String -> IO [(String, SqlColDesc)] #

Obtain information about the columns in a specific table. The String in the result set is the column name.

You should expect this to be returned in the same manner as a result from fetchAllRows'.

All results should be converted to lowercase for you before you see them.

data ConnWrapper where #

Sometimes, it is annoying to use typeclasses with Haskell's type system. In those situations, you can use a ConnWrapper. You can create one with:

let wrapped = ConnWrapper iconn

You can then use this directly, since a ConnWrapper is also an IConnection. However, you will not be able to use private database functions on it.

Or, you can use withWConn.

Constructors

ConnWrapper :: ConnWrapper 

data SqlError #

The main HDBC exception object. As much information as possible is passed from the database through to the application through this object.

Errors generated in the Haskell layer will have seNativeError set to -1.

Constructors

SqlError 

posixToSql :: POSIXTime -> SqlValue #

Convenience function for converting POSIXTime to a SqlValue, because toSql cannot do the correct thing in this instance.

iToSql :: Int -> SqlValue #

Convenience function for using numeric literals in your program.

nToSql :: Integral a => a -> SqlValue #

Converts any Integral type to a SqlValue by using toInteger.

fromSql :: Convertible SqlValue a => SqlValue -> a #

Convert from an SqlValue to a Haskell value. Any problem is indicated by calling error. This function is simply a restricted-type wrapper around convert. See extended notes on SqlValue.

safeFromSql :: Convertible SqlValue a => SqlValue -> ConvertResult a #

Conversions to and from SqlValues and standard Haskell types.

This function converts from an SqlValue to a Haskell value. Many people will use the simpler fromSql instead. This function is simply a restricted-type wrapper around safeConvert.

toSql :: Convertible a SqlValue => a -> SqlValue #

Convert a value to an SqlValue. This function is simply a restricted-type wrapper around convert. See extended notes on SqlValue.

data SqlValue #

SqlValue is the main type for expressing Haskell values to SQL databases.

INTRODUCTION TO SQLVALUE

This type is used to marshall Haskell data to and from database APIs. HDBC driver interfaces will do their best to use the most accurate and efficient way to send a particular value to the database server.

Values read back from the server are constructed with the most appropriate SqlValue constructor. fromSql or safeFromSql can then be used to convert them into whatever type is needed locally in Haskell.

Most people will use toSql and fromSql instead of manipulating SqlValues directly.

EASY CONVERSIONS BETWEEN HASKELL TYPES

Conversions are powerful; for instance, you can call fromSql on a SqlInt32 and get a String or a Double out of it. This class attempts to Do The Right Thing whenever possible, and will raise an error when asked to do something incorrect. In particular, when converting to any type except a Maybe, SqlNull as the input will cause an error to be raised.

Conversions are implemented in terms of the Data.Convertible module, part of the convertible package. You can refer to its documentation, and import that module, if you wish to parse the Left result from safeFromSql yourself, or write your own conversion instances.

Here are some notes about conversion:

  • Fractions of a second are not preserved on time values
  • There is no safeToSql because toSql never fails.

See also toSql, safeFromSql, fromSql, nToSql, iToSql, posixToSql.

ERROR CONDITIONS

There may sometimes be an error during conversion. For instance, if you have a SqlString and are attempting to convert it to an Integer, but it doesn't parse as an Integer, you will get an error. This will be indicated as an exception if using fromSql, or a Left result if using safeFromSql.

SPECIAL NOTE ON POSIXTIME

Note that a NominalDiffTime or POSIXTime is converted to SqlDiffTime by toSql. HDBC cannot differentiate between NominalDiffTime and POSIXTime since they are the same underlying type. You must construct SqlPOSIXTime manually or via posixToSql, or use SqlUTCTime.

DETAILS ON SQL TYPES

HDBC database backends are expected to marshal date and time data back and forth using the appropriate representation for the underlying database engine. Databases such as PostgreSQL with builtin date and time types should see automatic conversion between these Haskell types to database types. Other databases will be presented with an integer or a string. Care should be taken to use the same type on the Haskell side as you use on the database side. For instance, if your database type lacks timezone information, you ought not to use ZonedTime, but instead LocalTime or UTCTime. Database type systems are not always as rich as Haskell. For instance, for data stored in a TIMESTAMP WITHOUT TIME ZONE column, HDBC may not be able to tell if it is intended as UTCTime or LocalTime data, and will happily convert it to both, upon your request. It is your responsibility to ensure that you treat timezone issues with due care.

This behavior also exists for other types. For instance, many databases do not have a Rational type, so they will just use the show function and store a Rational as a string.

The conversion between Haskell types and database types is complex, and generic code in HDBC or its backends cannot possibly accomodate every possible situation. In some cases, you may be best served by converting your Haskell type to a String, and passing that to the database.

UNICODE AND BYTESTRINGS

Beginning with HDBC v2.0, interactions with a database are presumed to occur in UTF-8.

To accomplish this, whenever a ByteString must be converted to or from a String, the ByteString is assumed to be in UTF-8 encoding, and will be decoded or encoded as appropriate. Database drivers will generally present text or string data they have received from the database as a SqlValue holding a ByteString, which fromSql will automatically convert to a String, and thus automatically decode UTF-8, when you need it. In the other direction, database drivers will generally convert a SqlString to a ByteString in UTF-8 encoding before passing it to the database engine.

If you are handling some sort of binary data that is not in UTF-8, you can of course work with the ByteString directly, which will bypass any conversion.

Due to lack of support by database engines, lazy ByteStrings are not passed to database drivers. When you use toSql on a lazy ByteString, it will be converted to a strict ByteString for storage. Similarly, fromSql will convert a strict ByteString to a lazy ByteString if you demand it.

EQUALITY OF SQLVALUE

Two SqlValues are considered to be equal if one of these hold. The first comparison that can be made is controlling; if none of these comparisons can be made, then they are not equal:

  • Both are NULL
  • Both represent the same type and the encapsulated values are considered equal by applying (==) to them
  • The values of each, when converted to a string, are equal

STRING VERSIONS OF TIMES

Default string representations are given as comments below where such are non-obvious. These are used for fromSql when a String is desired. They are also defaults for representing data to SQL backends, though individual backends may override them when a different format is demanded by the underlying database. Date and time formats use ISO8601 date format, with HH:MM:SS added for time, and -HHMM added for timezone offsets.

DEPRECATED CONSTRUCTORS

SqlEpochTime and SqlTimeDiff are no longer created automatically by any toSql or fromSql functions or database backends. They may still be manually constructed, but are expected to be removed in a future version. Although these two constructures will be removed, support for marshalling to and from the old System.Time data will be maintained as long as System.Time is, simply using the newer data types for conversion.

Constructors

SqlString String 
SqlByteString ByteString 
SqlWord32 Word32 
SqlWord64 Word64 
SqlInt32 Int32 
SqlInt64 Int64 
SqlInteger Integer 
SqlChar Char 
SqlBool Bool 
SqlDouble Double 
SqlRational Rational 
SqlLocalDate Day

Local YYYY-MM-DD (no timezone).

SqlLocalTimeOfDay TimeOfDay

Local HH:MM:SS (no timezone).

SqlZonedLocalTimeOfDay TimeOfDay TimeZone

Local HH:MM:SS -HHMM. Converts to and from (TimeOfDay, TimeZone).

SqlLocalTime LocalTime

Local YYYY-MM-DD HH:MM:SS (no timezone).

SqlZonedTime ZonedTime

Local YYYY-MM-DD HH:MM:SS -HHMM. Considered equal if both convert to the same UTC time.

SqlUTCTime UTCTime

UTC YYYY-MM-DD HH:MM:SS.

SqlDiffTime NominalDiffTime

Calendar diff between seconds. Rendered as Integer when converted to String, but greater precision may be preserved for other types or to underlying database.

SqlPOSIXTime POSIXTime

Time as seconds since midnight Jan 1 1970 UTC. Integer rendering as for SqlDiffTime.

SqlEpochTime Integer

DEPRECATED Representation of ClockTime or CalendarTime. Use SqlPOSIXTime instead.

SqlTimeDiff Integer

DEPRECATED Representation of TimeDiff. Use SqlDiffTime instead.

SqlNull

NULL in SQL or Nothing in Haskell.

Instances
Eq SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Show SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Bool SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Char SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Double SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Int SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Int32 SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Int64 SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Integer SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Rational SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Word32 SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Word64 SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible String SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible NominalDiffTime SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Bool 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Char 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Double 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Int 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Int32 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Int64 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Integer 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Rational 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Word32 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Word64 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue String 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue NominalDiffTime 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue ByteString 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue ByteString 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue ClockTime 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue CalendarTime 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue TimeDiff 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Text 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Text 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue Day 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue TimeOfDay 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue LocalTime 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue ZonedTime 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue UTCTime 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue DiffTime 
Instance details

Defined in Database.HDBC.SqlValue

Convertible ByteString SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible ByteString SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible ClockTime SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible CalendarTime SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible TimeDiff SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Text SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Text SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible Day SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible TimeOfDay SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible LocalTime SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible ZonedTime SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible UTCTime SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible DiffTime SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

ToSql SqlValue Customer # 
Instance details

Defined in Customer

ToSql SqlValue Business # 
Instance details

Defined in Business

ToSql SqlValue Branch # 
Instance details

Defined in Branch

ToSql SqlValue Account # 
Instance details

Defined in Account

ToSql SqlValue Department # 
Instance details

Defined in Department

ToSql SqlValue Employee # 
Instance details

Defined in Employee

ToSql SqlValue Individual # 
Instance details

Defined in Individual

ToSql SqlValue Officer # 
Instance details

Defined in Officer

ToSql SqlValue Product # 
Instance details

Defined in Product

ToSql SqlValue ProductType # 
Instance details

Defined in ProductType

ToSql SqlValue Transaction0 # 
Instance details

Defined in Transaction

FromSql SqlValue Customer # 
Instance details

Defined in Customer

FromSql SqlValue Business # 
Instance details

Defined in Business

FromSql SqlValue Branch # 
Instance details

Defined in Branch

FromSql SqlValue Account # 
Instance details

Defined in Account

FromSql SqlValue Department # 
Instance details

Defined in Department

FromSql SqlValue Employee # 
Instance details

Defined in Employee

FromSql SqlValue Individual # 
Instance details

Defined in Individual

FromSql SqlValue Officer # 
Instance details

Defined in Officer

FromSql SqlValue Product # 
Instance details

Defined in Product

FromSql SqlValue ProductType # 
Instance details

Defined in ProductType

FromSql SqlValue Transaction0 # 
Instance details

Defined in Transaction

Convertible SqlValue a => Convertible SqlValue (Maybe a) 
Instance details

Defined in Database.HDBC.SqlValue

Convertible SqlValue (TimeOfDay, TimeZone) 
Instance details

Defined in Database.HDBC.SqlValue

Convertible a SqlValue => Convertible (Maybe a) SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

Convertible (TimeOfDay, TimeZone) SqlValue 
Instance details

Defined in Database.HDBC.SqlValue

data SqlColDesc #

The description of a column.

Fields are Nothing if the database backend cannot supply the requested information.

The colSize field works like this:

For character types, the maximum width of the column. For numeric types, the total number of digits allowed. See the ODBC manual for more.

The colOctetLength field is defined for character and binary types, and gives the number of bytes the column requires, regardless of encoding.

Constructors

SqlColDesc 

Fields

data SqlTypeId #

The type identifier for a given column.

This represents the type of data stored in the column in the underlying SQL engine. It does not form the entire column type; see SqlColDesc for that.

These types correspond mainly to those defined by ODBC.

Constructors

SqlCharT

Fixed-width character strings

SqlVarCharT

Variable-width character strings

SqlLongVarCharT

Variable-width character strings, max length implementation dependant

SqlWCharT

Fixed-width Unicode strings

SqlWVarCharT

Variable-width Unicode strings

SqlWLongVarCharT

Variable-width Unicode strings, max length implementation dependant

SqlDecimalT

Signed exact values

SqlNumericT

Signed exact integer values

SqlSmallIntT

16-bit integer values

SqlIntegerT

32-bit integer values

SqlRealT 
SqlFloatT

Signed inexact floating-point values

SqlDoubleT

Signed inexact double-precision values

SqlBitT

A single bit

SqlTinyIntT

8-bit integer values

SqlBigIntT

64-bit integer values

SqlBinaryT

Fixed-length binary data

SqlVarBinaryT

Variable-length binary data

SqlLongVarBinaryT

Variable-length binary data, max length implementation dependant

SqlDateT

A date

SqlTimeT

A time, no timezone

SqlTimeWithZoneT

A time, with timezone

SqlTimestampT

Combined date and time, no timezone

SqlTimestampWithZoneT

Combined date and time, with timezone

SqlUTCDateTimeT

UTC date/time

SqlUTCTimeT

UTC time

SqlIntervalT SqlInterval

A time or date difference

SqlGUIDT

Global unique identifier

SqlUnknownT String

A type not represented here; implementation-specific information in the String

data SqlInterval #

The different types of intervals in SQL.

Constructors

SqlIntervalMonthT

Difference in months

SqlIntervalYearT

Difference in years

SqlIntervalYearToMonthT

Difference in years+months

SqlIntervalDayT

Difference in days

SqlIntervalHourT

Difference in hours

SqlIntervalMinuteT

Difference in minutes

SqlIntervalSecondT

Difference in seconds

SqlIntervalDayToHourT

Difference in days+hours

SqlIntervalDayToMinuteT

Difference in days+minutes

SqlIntervalDayToSecondT

Difference in days+seconds

SqlIntervalHourToMinuteT

Difference in hours+minutes

SqlIntervalHourToSecondT

Difference in hours+seconds

SqlIntervalMinuteToSecondT

Difference in minutes+seconds

inlineVerifiedQuery #

Arguments

:: IConnection conn 
=> IO conn

Connect action to system catalog database

-> Name

Top-level variable name which has Relation type

-> Relation p r

Object which has Relation type

-> Config

Configuration to generate SQL

-> QuerySuffix

suffix SQL words

-> String

Variable name to define as inlined query

-> Q [Dec]

Result declarations

Verify composed Query and inline it in compile type.

defineTableFromDB #

Arguments

:: IConnection conn 
=> IO conn

Connect action to system catalog database

-> Driver conn

Driver definition

-> String

Schema name

-> String

Table name

-> [Name]

Derivings

-> Q [Dec]

Result declaration

Generate all HDBC templates using system catalog informations.

defineTableFromDB' #

Arguments

:: IConnection conn 
=> IO conn

Connect action to system catalog database

-> Driver conn

Driver definition

-> String

Schema name

-> String

Table name

-> [(String, TypeQ)]

Additional column-name and column-type mapping to overwrite default

-> [Name]

Derivings

-> Q [Dec]

Result declaration

Generate all HDBC templates using system catalog informations with specified config.

defineTableDefault #

Arguments

:: Config

Configuration to generate query with

-> String

Schema name

-> String

Table name

-> [(String, TypeQ)]

List of column name and type

-> [Name]

Derivings

-> [Int]

Indexes to represent primary key

-> Maybe Int

Index of not-null key

-> Q [Dec]

Result declaration

Generate all HDBC templates about table.

defineTableDefault' #

Arguments

:: Config

Configuration to generate query with

-> String

Schema name

-> String

Table name

-> [(String, TypeQ)]

List of column name and type

-> [Name]

Derivings

-> Q [Dec]

Result declaration

Generate all HDBC templates about table except for constraint keys.

makeRelationalRecord' #

Arguments

:: Config 
-> Name

Type constructor name

-> Q [Dec]

Result declaration

Generate all persistable templates against defined record like type constructor.

mapUpdate :: (IConnection conn, ToSql SqlValue a) => conn -> Update a -> [a] -> IO [Integer] #

Prepare and update with each parameter list.

runUpdate :: (IConnection conn, ToSql SqlValue p) => conn -> Update p -> p -> IO Integer #

Prepare update statement, bind parameters, execute statement and get execution result.

runPreparedUpdate :: ToSql SqlValue p => PreparedUpdate p -> p -> IO Integer #

Bind parameters, execute statement and get execution result.

withPrepareUpdate :: IConnection conn => conn -> Update p -> (PreparedUpdate p -> IO a) -> IO a #

Bracketed prepare operation.

prepareUpdate :: IConnection conn => conn -> Update p -> IO (PreparedUpdate p) #

Same as prepare.

type PreparedUpdate p = PreparedStatement p () #

Typed prepared update type.

runDelete :: (IConnection conn, ToSql SqlValue p) => conn -> Delete p -> p -> IO Integer #

Prepare delete statement, bind parameters, execute statement and get execution result.

runPreparedDelete :: ToSql SqlValue p => PreparedDelete p -> p -> IO Integer #

Bind parameters, execute statement and get execution result.

withPrepareDelete :: IConnection conn => conn -> Delete p -> (PreparedDelete p -> IO a) -> IO a #

Bracketed prepare operation.

prepareDelete :: IConnection conn => conn -> Delete p -> IO (PreparedDelete p) #

Same as prepare.

type PreparedDelete p = PreparedStatement p () #

Typed prepared delete type.

chunksInsert :: (IConnection conn, ToSql SqlValue a) => conn -> Insert a -> [a] -> IO [[Integer]] #

Deprecated. Use bulkInsert' instead of this. Prepare and insert using chunk insert statement.

bulkInsert' :: (IConnection conn, ToSql SqlValue a) => conn -> Insert a -> [a] -> IO ([Integer], [Integer]) #

Prepare and insert using chunk insert statement, with the results of insert statements.

bulkInsert :: (IConnection conn, ToSql SqlValue a) => conn -> Insert a -> [a] -> IO () #

Prepare and insert using chunk insert statement.

bulkInsertInterleave :: (IConnection conn, ToSql SqlValue a) => conn -> Insert a -> [a] -> IO ([Integer], [Integer]) #

Prepare and insert using chunk insert statement, with the Lazy-IO results of insert statements.

mapInsert :: (IConnection conn, ToSql SqlValue a) => conn -> Insert a -> [a] -> IO [Integer] #

Prepare and insert each record.

runInsert :: (IConnection conn, ToSql SqlValue a) => conn -> Insert a -> a -> IO Integer #

Prepare insert statement, bind parameters, execute statement and get execution result.

runPreparedInsert :: ToSql SqlValue a => PreparedInsert a -> a -> IO Integer #

Bind parameters, execute statement and get execution result.

prepareInsert :: IConnection conn => conn -> Insert a -> IO (PreparedInsert a) #

Same as prepare.

type PreparedInsert a = PreparedStatement a () #

Typed prepared insert type.

runInsertQuery :: (IConnection conn, ToSql SqlValue p) => conn -> InsertQuery p -> p -> IO Integer #

Prepare insert statement, bind parameters, execute statement and get execution result.

runPreparedInsertQuery :: ToSql SqlValue p => PreparedInsertQuery p -> p -> IO Integer #

Bind parameters, execute statement and get execution result.

withPrepareInsertQuery :: IConnection conn => conn -> InsertQuery p -> (PreparedInsertQuery p -> IO a) -> IO a #

Bracketed prepare operation.

type PreparedInsertQuery p = PreparedStatement p () #

Typed prepared insert query type.

runKeyUpdate :: (IConnection conn, ToSql SqlValue a) => conn -> KeyUpdate p a -> a -> IO Integer #

Prepare insert statement, bind parameters, execute statement and get execution result.

runPreparedKeyUpdate :: ToSql SqlValue a => PreparedKeyUpdate p a -> a -> IO Integer #

Bind parameters, execute statement and get execution result.

bindKeyUpdate :: ToSql SqlValue a => PreparedKeyUpdate p a -> a -> BoundStatement () #

Typed operation to bind parameters for PreparedKeyUpdate type.

withPrepareKeyUpdate :: IConnection conn => conn -> KeyUpdate p a -> (PreparedKeyUpdate p a -> IO b) -> IO b #

Bracketed prepare operation.

prepareKeyUpdate :: IConnection conn => conn -> KeyUpdate p a -> IO (PreparedKeyUpdate p a) #

Same as prepare.

data PreparedKeyUpdate p a #

Typed prepared key-update type.

runQuery' #

Arguments

:: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a) 
=> conn

Database connection

-> Query p a

Query to get record type a requires parameter p

-> p

Parameter type

-> IO [a]

Action to get records

Prepare SQL, bind parameters, execute statement and strictly fetch all records.

runQuery #

Arguments

:: (IConnection conn, ToSql SqlValue p, FromSql SqlValue a) 
=> conn

Database connection

-> Query p a

Query to get record type a requires parameter p

-> p

Parameter type

-> IO [a]

Action to get records

Lazy-IO version of runQuery'.

runPreparedQuery' #

Arguments

:: (ToSql SqlValue p, FromSql SqlValue a) 
=> PreparedQuery p a

Statement to bind to

-> p

Parameter type

-> IO [a]

Action to get records

Bind parameters, execute statement and strictly fetch all records.

runPreparedQuery #

Arguments

:: (ToSql SqlValue p, FromSql SqlValue a) 
=> PreparedQuery p a

Statement to bind to

-> p

Parameter type

-> IO [a]

Action to get records

Lazy-IO version of runPreparedQuery'.

runStatement' :: FromSql SqlValue a => BoundStatement a -> IO [a] #

Execute a parameter-bounded statement and strictly fetch all records.

runStatement :: FromSql SqlValue a => BoundStatement a -> IO [a] #

Lazy-IO version of runStatement'.

fetchUnique' :: FromSql SqlValue a => ExecutedStatement a -> IO (Maybe a) #

Fetch all records but get only first record. Expecting result records is unique. Error when records count is more than one.

listToUnique :: [a] -> IO (Maybe a) #

Fetch expecting result records is unique.

fetchUnique :: FromSql SqlValue a => ExecutedStatement a -> IO (Maybe a) #

Fetch all records but get only first record. Expecting result records is unique.

fetchAll' :: FromSql SqlValue a => ExecutedStatement a -> IO [a] #

Strictly fetch all records.

fetchAll :: FromSql SqlValue a => ExecutedStatement a -> IO [a] #

Lazy-IO version of fetchAll'.

fetch :: FromSql SqlValue a => ExecutedStatement a -> IO (Maybe a) #

Fetch a record.

withPrepareQuery #

Arguments

:: IConnection conn 
=> conn

Database connection

-> Query p a

Typed query

-> (PreparedQuery p a -> IO b)

Body action to use prepared statement

-> IO b

Result action

Bracketed prepare operation.

prepareQuery #

Arguments

:: IConnection conn 
=> conn

Database connection

-> Query p a

Typed query

-> IO (PreparedQuery p a)

Result typed prepared query with parameter type p and result type a

Same as prepare.

type PreparedQuery p a = PreparedStatement p a #

Typed prepared query type.

mapNoFetch :: (UntypeableNoFetch s, IConnection conn, ToSql SqlValue a) => conn -> s a -> [a] -> IO [Integer] #

Prepare and run it against each parameter list.

runNoFetch :: (UntypeableNoFetch s, IConnection conn, ToSql SqlValue a) => conn -> s a -> a -> IO Integer #

Prepare and run sequence for polymorphic no-fetch statement.

executeNoFetch :: ToSql SqlValue a => PreparedStatement a () -> a -> IO Integer #

Bind parameters, execute prepared statement and get execution result.

executeBoundNoFetch :: BoundStatement () -> IO Integer #

Typed execute operation. Only get result.

executeBound :: BoundStatement a -> IO (ExecutedStatement a) #

Typed execute operation.

bindTo :: ToSql SqlValue p => p -> PreparedStatement p a -> BoundStatement a #

Same as bind except for argument is flipped.

bind #

Arguments

:: ToSql SqlValue p 
=> PreparedStatement p a

Prepared query to bind to

-> p

Parameter to bind

-> BoundStatement a

Result parameter bound statement

Typed operation to bind parameters. Inferred ToSql is used.

withPrepareNoFetch :: (UntypeableNoFetch s, IConnection conn) => conn -> s p -> (PreparedStatement p () -> IO a) -> IO a #

Bracketed prepare operation. Generalized prepare inferred from UntypeableNoFetch instance.

withUnsafePrepare #

Arguments

:: IConnection conn 
=> conn

Database connection

-> String

Raw SQL String

-> (PreparedStatement p a -> IO b) 
-> IO b 

Bracketed prepare operation. Unsafely make Typed prepared statement.

prepareNoFetch :: (UntypeableNoFetch s, IConnection conn) => conn -> s p -> IO (PreparedStatement p ()) #

Generalized prepare inferred from UntypeableNoFetch instance.

unsafePrepare #

Arguments

:: IConnection conn 
=> conn

Database connection

-> String

Raw SQL String

-> IO (PreparedStatement p a)

Result typed prepared query with parameter type p and result type a

Run prepare and unsafely make Typed prepared statement.

untypePrepared :: PreparedStatement p a -> Statement #

Unsafely untype prepared statement.

data PreparedStatement p a #

Typed prepared statement type.

data BoundStatement a #

Typed prepared statement which has bound placeholder parameters.

Constructors

BoundStatement 

Fields

data ExecutedStatement a #

Typed executed statement.

updateValuesByPrimary :: (HasKeyConstraint Primary ra, ToSql q ra) => ra -> [q] #

Convert like updateValuesByUnique' using implicit RecordToSql and ColumnConstraint.

updateValuesByUnique #

Arguments

:: ToSql q ra 
=> KeyConstraint Unique ra

Unique key table constraint printer function object.

-> ra 
-> [q] 

Convert from Haskell type ra into database value q list expected by update form like

  UPDATE table SET c0 = ?, c1 = ?, c2 = ? ... WHERE key0 = ? AND key1 = ? AND key2 = ? ...

using printer function object infered by ToSql ra q.

valueRecordToSql :: (a -> q) -> RecordToSql q a #

Derivation rule of RecordToSql printer function object for value convert function.

fromRecord :: ToSql q a => a -> [q] #

Run implicit RecordToSql printer function object. Convert from haskell type a into list of database value type [q].

putEmpty :: () -> ToSqlM q () #

Run RecordToSql empty printer.

putRecord :: ToSql q a => a -> ToSqlM q () #

Run implicit RecordToSql printer function object. Context to convert haskell record type a into lib of database value type [q].

type ToSqlM q a = Writer (DList q) a #

Context type to convert into database value list.

data RecordToSql q a #

RecordToSql q a is data-type wrapping function to convert from Haskell type a into list of database value type (to send to database) [q].

This structure is similar to printer. While running RecordToSql behavior is the same as list printer. which appends list of database value type [q] stream.

class PersistableWidth a => ToSql q a where #

ToSql q a is implicit rule to derive RecordToSql q a record printer function for type a.

Generic programming (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming) with default signature is available for ToSql class, so you can make instance like below:

  {-# LANGUAGE DeriveGeneric #-}
  import GHC.Generics (Generic)
  import Database.HDBC (SqlValue)
  --
  data Foo = Foo { ... } deriving Generic
  instance ToSql SqlValue Foo

To make instances of ToSql manually, ToSql q a and RecordToSql 'q a are composable with monadic context. When, you have data constructor and objects like below.

  data MyRecord = MyRecord Foo Bar Baz
  instance ToSql SqlValue Foo where
    ...
  instance ToSql SqlValue Bar where
    ...
  instance ToSql SqlValue Baz where
    ...

You can get composed ToSql implicit rule like below.

  instance ToSql SqlValue MyRecord where
    recordToSql =
    recordToSql = wrapToSql $ \ (MyRecord x y z) -> do
      putRecord x
      putRecord y
      putRecord z

Methods

recordToSql :: RecordToSql q a #

Derived RecordToSql printer function object.

Instances
ToSql q ()

Implicit derivation rule of RecordToSql printer function object which can convert from Haskell unit () type into empty list of database value type [q].

Instance details

Defined in Database.Record.ToSql

Methods

recordToSql :: RecordToSql q () #

ToSql SqlValue Customer # 
Instance details

Defined in Customer

ToSql SqlValue Business # 
Instance details

Defined in Business

ToSql SqlValue Branch # 
Instance details

Defined in Branch

ToSql SqlValue Account # 
Instance details

Defined in Account

ToSql SqlValue Department # 
Instance details

Defined in Department

ToSql SqlValue Employee # 
Instance details

Defined in Employee

ToSql SqlValue Individual # 
Instance details

Defined in Individual

ToSql SqlValue Officer # 
Instance details

Defined in Officer

ToSql SqlValue Product # 
Instance details

Defined in Product

ToSql SqlValue ProductType # 
Instance details

Defined in ProductType

ToSql SqlValue Transaction0 # 
Instance details

Defined in Transaction

(PersistableType q, ToSql q a) => ToSql q (Maybe a)

Implicit derivation rule of RecordToSql printer function object which can convert from Haskell Maybe type into list of database value type [q].

Instance details

Defined in Database.Record.ToSql

Methods

recordToSql :: RecordToSql q (Maybe a) #

valueRecordFromSql :: (q -> a) -> RecordFromSql q a #

Derivation rule of RecordFromSql parser function object for value convert function.

toRecord :: FromSql q a => [q] -> a #

Run implicit RecordFromSql parser function object. Convert from list of database value type [q] into haskell type a.

takeRecord :: FromSql q a => [q] -> (a, [q]) #

Run implicit RecordFromSql parser function object. Convert from list of database value type [q] into haskell type a and rest of list [q].

data RecordFromSql q a #

RecordFromSql q a is data-type wrapping function to convert from list of database value type (to receive from database) [q] into Haskell type a

This structure is similar to parser. While running RecordFromSql behavior is the same as non-fail-able parser which parse list of database value type [q] stream.

So, RecordFromSql q is Monad and Applicative instance like parser monad. When, you have data constructor and objects like below.

  data MyRecord = MyRecord Foo Bar Baz
  foo :: RecordFromSql SqlValue Foo
  foo =  ...
  bar :: RecordFromSql SqlValue Bar
  bar =  ...
  baz :: RecordFromSql SqlValue Baz
  baz =  ...

You can get composed RecordFromSql like below.

  myRecord :: RecordFromSql SqlValue MyRecord
  myRecord =  MyRecord <$> foo <*> bar <*> baz
Instances
Monad (RecordFromSql q)

Monad instance like parser Monad.

Instance details

Defined in Database.Record.FromSql

Methods

(>>=) :: RecordFromSql q a -> (a -> RecordFromSql q b) -> RecordFromSql q b #

(>>) :: RecordFromSql q a -> RecordFromSql q b -> RecordFromSql q b #

return :: a -> RecordFromSql q a #

fail :: String -> RecordFromSql q a #

Functor (RecordFromSql q)

Derived Functor instance from Monad instance

Instance details

Defined in Database.Record.FromSql

Methods

fmap :: (a -> b) -> RecordFromSql q a -> RecordFromSql q b #

(<$) :: a -> RecordFromSql q b -> RecordFromSql q a #

Applicative (RecordFromSql q)

Derived Applicative instance from Monad instance

Instance details

Defined in Database.Record.FromSql

Methods

pure :: a -> RecordFromSql q a #

(<*>) :: RecordFromSql q (a -> b) -> RecordFromSql q a -> RecordFromSql q b #

liftA2 :: (a -> b -> c) -> RecordFromSql q a -> RecordFromSql q b -> RecordFromSql q c #

(*>) :: RecordFromSql q a -> RecordFromSql q b -> RecordFromSql q b #

(<*) :: RecordFromSql q a -> RecordFromSql q b -> RecordFromSql q a #

class FromSql q a where #

FromSql q a is implicit rule to derive RecordFromSql q a record parser function against type a.

Generic programming (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming) with default signature is available for FromSql class, so you can make instance like below:

  {-# LANGUAGE DeriveGeneric #-}
  import GHC.Generics (Generic)
  import Database.HDBC (SqlValue)
  --
  data Foo = Foo { ... } deriving Generic
  instance FromSql SqlValue Foo

Methods

recordFromSql :: RecordFromSql q a #

RecordFromSql q a record parser function.

Instances
FromSql q ()

Implicit derivation rule of RecordFromSql parser function object which can convert from empty list of database value type [q] into Haskell unit () type.

Instance details

Defined in Database.Record.FromSql

FromSql SqlValue Customer # 
Instance details

Defined in Customer

FromSql SqlValue Business # 
Instance details

Defined in Business

FromSql SqlValue Branch # 
Instance details

Defined in Branch

FromSql SqlValue Account # 
Instance details

Defined in Account

FromSql SqlValue Department # 
Instance details

Defined in Department

FromSql SqlValue Employee # 
Instance details

Defined in Employee

FromSql SqlValue Individual # 
Instance details

Defined in Individual

FromSql SqlValue Officer # 
Instance details

Defined in Officer

FromSql SqlValue Product # 
Instance details

Defined in Product

FromSql SqlValue ProductType # 
Instance details

Defined in ProductType

FromSql SqlValue Transaction0 # 
Instance details

Defined in Transaction

(HasColumnConstraint NotNull a, FromSql q a, PersistableType q) => FromSql q (Maybe a)

Implicit derivation rule of RecordFromSql parser function object which can convert from list of database value type [q] into Haskell Maybe type.

Instance details

Defined in Database.Record.FromSql

derivedWidth :: PersistableWidth a => (PersistableRecordWidth a, Int) #

Pass type parameter and inferred width value.

sqlNullValue :: PersistableType q => q #

Implicitly derived null value of database value type.

data PersistableSqlType q #

Proposition to specify type q is database value type, contains null value

type PersistableRecordWidth a = ProductConst (Sum Int) a #

Proposition to specify width of Haskell type a. The width is length of database value list which is converted from Haskell type a.

class Eq q => PersistableType q where #

Interface of derivation rule for PersistableSqlType.

Minimal complete definition

persistableType

class PersistableWidth a where #

PersistableWidth a is implicit rule to derive PersistableRecordWidth a width proposition for type a.

Generic programming (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming) with default signature is available for PersistableWidth class, so you can make instance like below:

  {-# LANGUAGE DeriveGeneric #-}
  import GHC.Generics (Generic)
  --
  data Foo = Foo { ... } deriving Generic
  instance PersistableWidth Foo
Instances
PersistableWidth ()

Inference rule of PersistableRecordWidth for Haskell unit () type. Derive from axiom.

Instance details

Defined in Database.Record.Persistable

PersistableWidth TableInfo 
Instance details

Defined in Database.Relational.Schema.SQLite3Syscat.TableInfo

PersistableWidth IndexList 
Instance details

Defined in Database.Relational.Schema.SQLite3Syscat.IndexList

PersistableWidth IndexInfo 
Instance details

Defined in Database.Relational.Schema.SQLite3Syscat.IndexInfo

PersistableWidth Customer # 
Instance details

Defined in Customer

PersistableWidth Business # 
Instance details

Defined in Business

PersistableWidth Branch # 
Instance details

Defined in Branch

PersistableWidth Account # 
Instance details

Defined in Account

PersistableWidth Department # 
Instance details

Defined in Department

PersistableWidth Employee # 
Instance details

Defined in Employee

PersistableWidth Individual # 
Instance details

Defined in Individual

PersistableWidth Officer # 
Instance details

Defined in Officer

PersistableWidth Product # 
Instance details

Defined in Product

PersistableWidth ProductType # 
Instance details

Defined in ProductType

PersistableWidth Transaction0 # 
Instance details

Defined in Transaction

PersistableWidth a => PersistableWidth (Maybe a)

Inference rule of PersistableRecordWidth proof object for Maybe type.

Instance details

Defined in Database.Record.Persistable

derivedUniqueConstraint :: HasKeyConstraint Primary r => UniqueConstraint r #

Inferred UniqueConstraint proof object. Record type r has unique key which is derived r has primary key.

derivedCompositePrimary :: HasColumnConstraint Primary r => PrimaryConstraint r #

Inferred PrimaryConstraint proof object. Record type r has composite primary key which is derived r has single column primary key.

deriveComposite :: ColumnConstraint c r -> KeyConstraint c r #

Derivation rule for KeyConstraint. Derive from ColumnConstraint.

derivedNotNullColumnConstraint :: HasColumnConstraint Primary r => NotNullColumnConstraint r #

Inferred NotNullColumnConstraint proof object. Record type r has not-null key which is derived r has primary key.

derivedUniqueColumnConstraint :: HasColumnConstraint Primary r => UniqueColumnConstraint r #

Inferred UniqueColumnConstraint proof object. Record type r has unique key which is derived r has primary key.

notNullColumn :: PrimaryColumnConstraint r -> NotNullColumnConstraint r #

Derivation rule for NotNullColumnConstraint. Derive NotNull from Primary.

uniqueColumn :: PrimaryColumnConstraint r -> UniqueColumnConstraint r #

Derivation rule for UniqueColumnConstraint. Derive Unique from Primary.

data ColumnConstraint c r #

Proof object to specify table constraint for table record type r and constraint c specified by a single column.

data Unique #

Constraint type. Unique key.

data NotNull #

Constraint type. Not-null key.

Instances
HasColumnConstraint NotNull Customer # 
Instance details

Defined in Customer

HasColumnConstraint NotNull Business # 
Instance details

Defined in Business

HasColumnConstraint NotNull Branch # 
Instance details

Defined in Branch

HasColumnConstraint NotNull Account # 
Instance details

Defined in Account

HasColumnConstraint NotNull Department # 
Instance details

Defined in Department

HasColumnConstraint NotNull Employee # 
Instance details

Defined in Employee

HasColumnConstraint NotNull Individual # 
Instance details

Defined in Individual

HasColumnConstraint NotNull Officer # 
Instance details

Defined in Officer

HasColumnConstraint NotNull Product # 
Instance details

Defined in Product

HasColumnConstraint NotNull ProductType # 
Instance details

Defined in ProductType

HasColumnConstraint NotNull Transaction0 # 
Instance details

Defined in Transaction

HasColumnConstraint NotNull a => HasColumnConstraint NotNull (a, b)

Inference rule of ColumnConstraint NotNull for tuple (,) type.

Instance details

Defined in Database.Record.KeyConstraint

data Primary #

Constraint type. Primary key.

Instances
HasColumnConstraint Primary Customer # 
Instance details

Defined in Customer

HasColumnConstraint Primary Business # 
Instance details

Defined in Business

HasColumnConstraint Primary Branch # 
Instance details

Defined in Branch

HasColumnConstraint Primary Account # 
Instance details

Defined in Account

HasColumnConstraint Primary Department # 
Instance details

Defined in Department

HasColumnConstraint Primary Employee # 
Instance details

Defined in Employee

HasColumnConstraint Primary Individual # 
Instance details

Defined in Individual

HasColumnConstraint Primary Officer # 
Instance details

Defined in Officer

HasColumnConstraint Primary Product # 
Instance details

Defined in Product

HasColumnConstraint Primary ProductType # 
Instance details

Defined in ProductType

HasColumnConstraint Primary Transaction0 # 
Instance details

Defined in Transaction

HasKeyConstraint Primary Customer # 
Instance details

Defined in Customer

HasKeyConstraint Primary Business # 
Instance details

Defined in Business

HasKeyConstraint Primary Branch # 
Instance details

Defined in Branch

HasKeyConstraint Primary Account # 
Instance details

Defined in Account

HasKeyConstraint Primary Department # 
Instance details

Defined in Department

HasKeyConstraint Primary Employee # 
Instance details

Defined in Employee

HasKeyConstraint Primary Individual # 
Instance details

Defined in Individual

HasKeyConstraint Primary Officer # 
Instance details

Defined in Officer

HasKeyConstraint Primary Product # 
Instance details

Defined in Product

HasKeyConstraint Primary ProductType # 
Instance details

Defined in ProductType

HasKeyConstraint Primary Transaction0 # 
Instance details

Defined in Transaction

HasConstraintKey Primary Customer Int # 
Instance details

Defined in Customer

HasConstraintKey Primary Business Int # 
Instance details

Defined in Business

HasConstraintKey Primary Branch Int # 
Instance details

Defined in Branch

HasConstraintKey Primary Account Int # 
Instance details

Defined in Account

HasConstraintKey Primary Department Int # 
Instance details

Defined in Department

HasConstraintKey Primary Employee Int # 
Instance details

Defined in Employee

HasConstraintKey Primary Individual Int # 
Instance details

Defined in Individual

HasConstraintKey Primary Officer Int # 
Instance details

Defined in Officer

HasConstraintKey Primary Product String # 
Instance details

Defined in Product

HasConstraintKey Primary ProductType String # 
Instance details

Defined in ProductType

HasConstraintKey Primary Transaction0 Int # 
Instance details

Defined in Transaction

type UniqueColumnConstraint = ColumnConstraint Unique #

Specialized unique constraint.

type NotNullColumnConstraint = ColumnConstraint NotNull #

Specialized not-null constraint.

type PrimaryColumnConstraint = ColumnConstraint Primary #

Specialized primary constraint.

class HasColumnConstraint c a where #

Interface of inference rule for ColumnConstraint proof object.

Minimal complete definition

columnConstraint

Methods

columnConstraint :: ColumnConstraint c a #

Infer ColumnConstraint proof object.

Instances
HasColumnConstraint NotNull Customer # 
Instance details

Defined in Customer

HasColumnConstraint NotNull Business # 
Instance details

Defined in Business

HasColumnConstraint NotNull Branch # 
Instance details

Defined in Branch

HasColumnConstraint NotNull Account # 
Instance details

Defined in Account

HasColumnConstraint NotNull Department # 
Instance details

Defined in Department

HasColumnConstraint NotNull Employee # 
Instance details

Defined in Employee

HasColumnConstraint NotNull Individual # 
Instance details

Defined in Individual

HasColumnConstraint NotNull Officer # 
Instance details

Defined in Officer

HasColumnConstraint NotNull Product # 
Instance details

Defined in Product

HasColumnConstraint NotNull ProductType # 
Instance details

Defined in ProductType

HasColumnConstraint NotNull Transaction0 # 
Instance details

Defined in Transaction

HasColumnConstraint Primary Customer # 
Instance details

Defined in Customer

HasColumnConstraint Primary Business # 
Instance details

Defined in Business

HasColumnConstraint Primary Branch # 
Instance details

Defined in Branch

HasColumnConstraint Primary Account # 
Instance details

Defined in Account

HasColumnConstraint Primary Department # 
Instance details

Defined in Department

HasColumnConstraint Primary Employee # 
Instance details

Defined in Employee

HasColumnConstraint Primary Individual # 
Instance details

Defined in Individual

HasColumnConstraint Primary Officer # 
Instance details

Defined in Officer

HasColumnConstraint Primary Product # 
Instance details

Defined in Product

HasColumnConstraint Primary ProductType # 
Instance details

Defined in ProductType

HasColumnConstraint Primary Transaction0 # 
Instance details

Defined in Transaction

HasColumnConstraint NotNull a => HasColumnConstraint NotNull (a, b)

Inference rule of ColumnConstraint NotNull for tuple (,) type.

Instance details

Defined in Database.Record.KeyConstraint

data KeyConstraint c r #

Proof object to specify table constraint for table record type r and constraint c. Constraint is specified by composite key.

type UniqueConstraint = KeyConstraint Unique #

Specialized unique constraint.

type PrimaryConstraint = KeyConstraint Primary #

Specialized primary constraint.

class HasKeyConstraint c a where #

Interface of inference rule for KeyConstraint proof object.

Minimal complete definition

keyConstraint

Methods

keyConstraint :: KeyConstraint c a #

Infer ColumnConstraint proof object.

data Unique #

Constraint type. Unique key.

data NotNull #

Constraint type. Not-null key.

Instances
HasColumnConstraint NotNull Customer # 
Instance details

Defined in Customer

HasColumnConstraint NotNull Business # 
Instance details

Defined in Business

HasColumnConstraint NotNull Branch # 
Instance details

Defined in Branch

HasColumnConstraint NotNull Account # 
Instance details

Defined in Account

HasColumnConstraint NotNull Department # 
Instance details

Defined in Department

HasColumnConstraint NotNull Employee # 
Instance details

Defined in Employee

HasColumnConstraint NotNull Individual # 
Instance details

Defined in Individual

HasColumnConstraint NotNull Officer # 
Instance details

Defined in Officer

HasColumnConstraint NotNull Product # 
Instance details

Defined in Product

HasColumnConstraint NotNull ProductType # 
Instance details

Defined in ProductType

HasColumnConstraint NotNull Transaction0 # 
Instance details

Defined in Transaction

HasColumnConstraint NotNull a => HasColumnConstraint NotNull (a, b)

Inference rule of ColumnConstraint NotNull for tuple (,) type.

Instance details

Defined in Database.Record.KeyConstraint

data Primary #

Constraint type. Primary key.

Instances
HasColumnConstraint Primary Customer # 
Instance details

Defined in Customer

HasColumnConstraint Primary Business # 
Instance details

Defined in Business

HasColumnConstraint Primary Branch # 
Instance details

Defined in Branch

HasColumnConstraint Primary Account # 
Instance details

Defined in Account

HasColumnConstraint Primary Department # 
Instance details

Defined in Department

HasColumnConstraint Primary Employee # 
Instance details

Defined in Employee

HasColumnConstraint Primary Individual # 
Instance details

Defined in Individual

HasColumnConstraint Primary Officer # 
Instance details

Defined in Officer

HasColumnConstraint Primary Product # 
Instance details

Defined in Product

HasColumnConstraint Primary ProductType # 
Instance details

Defined in ProductType

HasColumnConstraint Primary Transaction0 # 
Instance details

Defined in Transaction

HasKeyConstraint Primary Customer # 
Instance details

Defined in Customer

HasKeyConstraint Primary Business # 
Instance details

Defined in Business

HasKeyConstraint Primary Branch # 
Instance details

Defined in Branch

HasKeyConstraint Primary Account # 
Instance details

Defined in Account

HasKeyConstraint Primary Department # 
Instance details

Defined in Department

HasKeyConstraint Primary Employee # 
Instance details

Defined in Employee

HasKeyConstraint Primary Individual # 
Instance details

Defined in Individual

HasKeyConstraint Primary Officer # 
Instance details

Defined in Officer

HasKeyConstraint Primary Product # 
Instance details

Defined in Product

HasKeyConstraint Primary ProductType # 
Instance details

Defined in ProductType

HasKeyConstraint Primary Transaction0 # 
Instance details

Defined in Transaction

HasConstraintKey Primary Customer Int # 
Instance details

Defined in Customer

HasConstraintKey Primary Business Int # 
Instance details

Defined in Business

HasConstraintKey Primary Branch Int # 
Instance details

Defined in Branch

HasConstraintKey Primary Account Int # 
Instance details

Defined in Account

HasConstraintKey Primary Department Int # 
Instance details

Defined in Department

HasConstraintKey Primary Employee Int # 
Instance details

Defined in Employee

HasConstraintKey Primary Individual Int # 
Instance details

Defined in Individual

HasConstraintKey Primary Officer Int # 
Instance details

Defined in Officer

HasConstraintKey Primary Product String # 
Instance details

Defined in Product

HasConstraintKey Primary ProductType String # 
Instance details

Defined in ProductType

HasConstraintKey Primary Transaction0 Int # 
Instance details

Defined in Transaction

derivedUniqueRelation #

Arguments

:: TableDerivable r 
=> Key Unique r k

Unique key proof object which record type is a and key type is p.

-> Record c k

Unique key value to specify.

-> UniqueRelation () c r

Result restricted Relation

UniqueRelation inferred from table.

primaryUpdate #

Arguments

:: HasConstraintKey Primary r p 
=> Table r

Table to update

-> KeyUpdate p r

Result typed Update

Typed KeyUpdate using inferred primary key.

updateByConstraintKey #

Arguments

:: Table r

Table to update

-> Key c r p

Key with constraint c, record type r and columns type p

-> KeyUpdate p r

Result typed Update

Typed KeyUpdate using specified constraint key.

updateValuesWithKey :: ToSql q r => Pi r p -> r -> [q] #

Convert from Haskell type r into SQL value q list expected by update form like

UPDATE table SET c0 = ?, c1 = ?, ..., cn = ? WHERE key0 = ? AND key1 = ? AND key2 = ? ...

using derived RecordToSql proof object.

primary :: HasConstraintKey Primary a p => Relation () a -> Relation p a #

Deprecated.

primarySelect #

Arguments

:: HasConstraintKey Primary a p 
=> Relation () a

Relation to add restriction.

-> Relation p a

Result restricted Relation

Query restricted with inferred primary key.

primary' #

Arguments

:: PersistableWidth p 
=> Key Primary a p

Primary key proof object which record type is a and key type is p.

-> Relation () a

Relation to add restriction.

-> Relation p a

Result restricted Relation

Deprecated.

uniqueSelect #

Arguments

:: PersistableWidth p 
=> Key Unique a p

Unique key proof object which record type is a and key type is p.

-> Relation () a

Relation to add restriction.

-> Relation p a

Result restricted Relation

Query restricted with specified unique key.

specifiedKey #

Arguments

:: PersistableWidth p 
=> Pi a p

Projection path

-> Relation () a

Relation to add restriction.

-> Relation p a

Result restricted Relation

Query restricted with specified key.

updateNumber #

Arguments

:: (PersistableWidth s, Integral i, LiteralSQL i) 
=> i

sequence number to set. expect not SQL injectable.

-> Sequence s i

sequence table

-> Update () 

Update statement for sequence table

updateNumber' #

Arguments

:: (PersistableWidth s, Integral i, LiteralSQL i) 
=> Config 
-> i

sequence number to set. expect not SQL injectable.

-> Sequence s i

sequence table

-> Update () 

Update statement for sequence table

($$) #

Arguments

:: Binding r s i 
=> (i -> r)

sequence number should be passed to proper field of record

-> Number r i 
-> r 

Unsafely apply sequence number. Only safe to build corresponding record type.

($$!) #

Arguments

:: (i -> r)

sequence number should be passed to proper field of record

-> Number r i 
-> r 

Unsafely apply sequence number.

extractNumber :: Number r i -> i #

Get untyped sequence number.

unsafeSpecifyNumber :: Binding r s i => i -> Number r i #

Unsafely specify sequence number.

fromRelation :: Binding r s i => Relation () r -> Sequence s i #

Derive Sequence from corresponding Relation

primaryBinding :: (TableDerivable r, SequenceDerivable s i, HasConstraintKey Primary r i) => SeqBinding r s i #

Derive binding using primary key.

unsafeSpecifyBinding :: (TableDerivable r, SequenceDerivable s i) => Pi r i -> SeqBinding r s i #

Unsafely specify binding between normal-table and sequence-table.

seqRelation :: TableDerivable s => Sequence s i -> Relation () s #

Infer Relation of sequence table

unsafeSpecifySequence :: TableDerivable s => (s -> i) -> Pi s i -> Sequence s i #

Unsafely specify sequence table.

data Sequence s i #

Basic record to express sequence-table. actual sequence-table is a table which has only one column of integer type.

class TableDerivable s => SequenceDerivable s i | s -> i where #

Sequence derivation rule

Minimal complete definition

derivedSequence

Methods

derivedSequence :: Sequence s i #

data SeqBinding r s i #

Record to express binding between normal-table and sequence-table.

class (TableDerivable r, SequenceDerivable s i) => Binding r s i | r -> s where #

Derivation rule for binding between Table and Sequence

Methods

binding :: SeqBinding r s i #

data Number r i #

Sequence number type for record type r

Instances
Eq i => Eq (Number r i) 
Instance details

Defined in Database.Relational.Sequence

Methods

(==) :: Number r i -> Number r i -> Bool #

(/=) :: Number r i -> Number r i -> Bool #

Ord i => Ord (Number r i) 
Instance details

Defined in Database.Relational.Sequence

Methods

compare :: Number r i -> Number r i -> Ordering #

(<) :: Number r i -> Number r i -> Bool #

(<=) :: Number r i -> Number r i -> Bool #

(>) :: Number r i -> Number r i -> Bool #

(>=) :: Number r i -> Number r i -> Bool #

max :: Number r i -> Number r i -> Number r i #

min :: Number r i -> Number r i -> Number r i #

Show i => Show (Number r i) 
Instance details

Defined in Database.Relational.Sequence

Methods

showsPrec :: Int -> Number r i -> ShowS #

show :: Number r i -> String #

showList :: [Number r i] -> ShowS #

derivedDelete :: TableDerivable r => RestrictedStatement r (PlaceHolders p) -> Delete p #

Make typed Delete from defaultConfig, derived table and RestrictContext

deleteNoPH :: TableDerivable r => RestrictedStatement r () -> Delete () #

Make typed Delete from defaultConfig, derived table and RestrictContext with no(unit) placeholder.

delete :: TableDerivable r => RestrictedStatement r (PlaceHolders p) -> Delete p #

Make typed Delete from defaultConfig, derived table and RestrictContext

derivedDelete' :: TableDerivable r => Config -> RestrictedStatement r (PlaceHolders p) -> Delete p #

Make typed Delete from Config, derived table and RestrictContext

delete' :: TableDerivable r => Config -> RestrictedStatement r (PlaceHolders p) -> Delete p #

Make typed Delete from Config, derived table and RestrictContext

typedDelete :: Table r -> Restriction p r -> Delete p #

Make typed Delete from Table and Restriction.

typedDelete' :: Config -> Table r -> Restriction p r -> Delete p #

Make typed Delete from Config, Table and Restriction.

deleteSQL :: Config -> Table r -> Restriction p r -> String #

Make untyped delete SQL string from Table and Restriction.

derivedInsertQuery :: TableDerivable r => Pi r r' -> Relation p r' -> InsertQuery p #

Table type inferred InsertQuery.

insertQuery :: TableDerivable r => Pi r r' -> Relation p r' -> InsertQuery p #

Table type inferred InsertQuery.

typedInsertQuery :: Table r -> Pi r r' -> Relation p r' -> InsertQuery p #

Make typed InsertQuery from columns selector Table, Pi and Relation.

typedInsertQuery' :: Config -> Table r -> Pi r r' -> Relation p r' -> InsertQuery p #

Make typed InsertQuery from columns selector Table, Pi and Relation with configuration parameter.

insertQuerySQL :: Config -> Table r -> Pi r r' -> Relation p r' -> String #

Make untyped insert select SQL string from Table, Pi and Relation.

insertValueList :: (TableDerivable r, LiteralSQL r') => Pi r r' -> [r'] -> [Insert ()] #

Make typed Insert list from records list.

insertValueList' :: (TableDerivable r, LiteralSQL r') => Config -> Pi r r' -> [r'] -> [Insert ()] #

Make typed Insert list from Config and records list.

derivedInsertValue :: TableDerivable r => Register r (PlaceHolders p) -> Insert p #

Make typed Insert from defaultConfig, derived table and monadic builded Register object.

insertValueNoPH :: TableDerivable r => Register r () -> Insert () #

Make typed Insert from defaultConfig, derived table and monadic builded Register object with no(unit) placeholder.

insertValue :: TableDerivable r => Register r (PlaceHolders p) -> Insert p #

Make typed Insert from defaultConfig, derived table and monadic builded Register object.

derivedInsertValue' :: TableDerivable r => Config -> Register r (PlaceHolders p) -> Insert p #

Make typed Insert from Config, derived table and monadic builded Register object.

insertValue' :: TableDerivable r => Config -> Register r (PlaceHolders p) -> Insert p #

Make typed Insert from Config, derived table and monadic builded Register object.

typedInsertValue :: Table r -> InsertTarget p r -> Insert p #

Make typed Insert from Table and monadic builded InsertTarget object.

typedInsertValue' :: Config -> Table r -> InsertTarget p r -> Insert p #

Make typed Insert from Config, Table and monadic builded InsertTarget object.

derivedInsert :: (PersistableWidth r, TableDerivable r) => Pi r r' -> Insert r' #

Table type inferred Insert.

insert :: (PersistableWidth r, TableDerivable r) => Pi r r' -> Insert r' #

Table type inferred Insert.

typedInsert :: PersistableWidth r => Table r -> Pi r r' -> Insert r' #

Make typed Insert from Table and columns selector Pi.

typedInsert' :: PersistableWidth r => Config -> Table r -> Pi r r' -> Insert r' #

Make typed Insert from Table and columns selector Pi with configuration parameter.

unsafeTypedInsert' :: String -> String -> Int -> Insert a #

Unsafely make typed Insert from single insert and chunked insert SQL.

chunkSizeOfInsert :: Insert a -> Int #

Size to use chunked insert

untypeChunkInsert :: Insert a -> String #

Statement to use chunked insert

derivedUpdateAllColumn :: (PersistableWidth r, TableDerivable r) => RestrictedStatement r (PlaceHolders p) -> Update (r, p) #

Make typed Update from defaultConfig, derived table and AssignStatement. Update target is all column.

updateAllColumnNoPH :: (PersistableWidth r, TableDerivable r) => RestrictedStatement r () -> Update r #

Make typed Update from defaultConfig, derived table and AssignStatement without placeholder other than target table columns. Update target is all column.

updateAllColumn :: (PersistableWidth r, TableDerivable r) => RestrictedStatement r (PlaceHolders p) -> Update (r, p) #

Make typed Update from defaultConfig, derived table and AssignStatement. Update target is all column.

derivedUpdateAllColumn' :: (PersistableWidth r, TableDerivable r) => Config -> RestrictedStatement r (PlaceHolders p) -> Update (r, p) #

Make typed Update from Config, derived table and AssignStatement. Update target is all column.

updateAllColumn' :: (PersistableWidth r, TableDerivable r) => Config -> RestrictedStatement r (PlaceHolders p) -> Update (r, p) #

Make typed Update from Config, derived table and AssignStatement. Update target is all column.

typedUpdateAllColumn :: PersistableWidth r => Table r -> Restriction p r -> Update (r, p) #

Make typed Update from Table and Restriction. Update target is all column.

updateNoPH :: TableDerivable r => AssignStatement r () -> Update () #

Make typed Update from defaultConfig, derived table and AssignStatement with no(unit) placeholder.

update :: TableDerivable r => AssignStatement r (PlaceHolders p) -> Update p #

Make typed Update from defaultConfig, derived table and AssignStatement

derivedUpdate' :: TableDerivable r => Config -> AssignStatement r (PlaceHolders p) -> Update p #

Make typed Update from Config, derived table and AssignStatement

update' :: TableDerivable r => Config -> AssignStatement r (PlaceHolders p) -> Update p #

Make typed Update from Config, derived table and AssignStatement

typedUpdate' :: Config -> Table r -> UpdateTarget p r -> Update p #

Make typed Update from Config, Table and UpdateTarget.

updateSQL :: Config -> Table r -> UpdateTarget p r -> String #

Make untyped update SQL string from Table and UpdateTarget.

unsafeTypedUpdate :: String -> Update p #

Unsafely make typed Update from SQL string.

derivedKeyUpdate :: TableDerivable r => Pi r p -> KeyUpdate p r #

Make typed KeyUpdate from derived table and key columns selector Pi.

keyUpdate :: TableDerivable r => Pi r p -> KeyUpdate p r #

Make typed KeyUpdate from derived table and key columns selector Pi.

typedKeyUpdateTable :: TableDerivable r => Relation () r -> Pi r p -> KeyUpdate p r #

Make typed KeyUpdate object using derived info specified by Relation type.

typedKeyUpdate :: Table a -> Pi a p -> KeyUpdate p a #

Make typed KeyUpdate from Table and key columns selector Pi.

relationalQuery :: Relation p r -> Query p r #

From Relation into typed Query.

relationalQuery' :: Relation p r -> QuerySuffix -> Query p r #

From Relation into typed Query with suffix SQL words.

relationalQuerySQL :: Config -> Relation p r -> QuerySuffix -> String #

From Relation into untyped SQL query string.

unsafeTypedQuery #

Arguments

:: String

Query SQL to type

-> Query p a

Typed result

Unsafely make typed Query from SQL string.

newtype Query p a #

Query type with place-holder parameter p and query result type a.

Constructors

Query 

Fields

Instances
Show (Query p a)

Show query SQL string

Instance details

Defined in Database.Relational.Type

Methods

showsPrec :: Int -> Query p a -> ShowS #

show :: Query p a -> String #

showList :: [Query p a] -> ShowS #

data KeyUpdate p a #

Update type with key type p and update record type a. Columns to update are record columns other than key columns, So place-holder parameter type is the same as record type a.

Constructors

KeyUpdate 

Fields

Instances
Show (KeyUpdate p a)

Show update SQL string

Instance details

Defined in Database.Relational.Type

Methods

showsPrec :: Int -> KeyUpdate p a -> ShowS #

show :: KeyUpdate p a -> String #

showList :: [KeyUpdate p a] -> ShowS #

newtype Update p #

Update type with place-holder parameter p.

Constructors

Update 

Fields

Instances
UntypeableNoFetch Update 
Instance details

Defined in Database.Relational.Type

Methods

untypeNoFetch :: Update p -> String #

Show (Update p)

Show update SQL string

Instance details

Defined in Database.Relational.Type

Methods

showsPrec :: Int -> Update p -> ShowS #

show :: Update p -> String #

showList :: [Update p] -> ShowS #

data Insert a #

Insert type to insert record type a.

Constructors

Insert 
Instances
UntypeableNoFetch Insert 
Instance details

Defined in Database.Relational.Type

Methods

untypeNoFetch :: Insert p -> String #

Show (Insert a)

Show insert SQL string.

Instance details

Defined in Database.Relational.Type

Methods

showsPrec :: Int -> Insert a -> ShowS #

show :: Insert a -> String #

showList :: [Insert a] -> ShowS #

newtype InsertQuery p #

InsertQuery type.

Constructors

InsertQuery 
Instances
UntypeableNoFetch InsertQuery 
Instance details

Defined in Database.Relational.Type

Show (InsertQuery p)

Show insert SQL string.

Instance details

Defined in Database.Relational.Type

newtype Delete p #

Delete type with place-holder parameter p.

Constructors

Delete 

Fields

Instances
UntypeableNoFetch Delete 
Instance details

Defined in Database.Relational.Type

Methods

untypeNoFetch :: Delete p -> String #

Show (Delete p)

Show delete SQL string

Instance details

Defined in Database.Relational.Type

Methods

showsPrec :: Int -> Delete p -> ShowS #

show :: Delete p -> String #

showList :: [Delete p] -> ShowS #

class UntypeableNoFetch (s :: * -> *) where #

Untype interface for typed no-result type statments with single type parameter which represents place-holder parameter p.

Minimal complete definition

untypeNoFetch

Methods

untypeNoFetch :: s p -> String #

Instances
UntypeableNoFetch Update 
Instance details

Defined in Database.Relational.Type

Methods

untypeNoFetch :: Update p -> String #

UntypeableNoFetch Insert 
Instance details

Defined in Database.Relational.Type

Methods

untypeNoFetch :: Insert p -> String #

UntypeableNoFetch InsertQuery 
Instance details

Defined in Database.Relational.Type

UntypeableNoFetch Delete 
Instance details

Defined in Database.Relational.Type

Methods

untypeNoFetch :: Delete p -> String #

sqlChunksFromRecordList :: LiteralSQL r' => Config -> Table r -> Pi r r' -> [r'] -> [StringSQL] #

Make StringSQL strings of SQL INSERT strings from records list

sqlFromInsertTarget :: Config -> Table r -> InsertTarget p r -> StringSQL #

Make StringSQL string of SQL INSERT statement from InsertTarget

sqlChunkFromInsertTarget :: Config -> Table r -> InsertTarget p r -> (StringSQL, Int) #

Make StringSQL string of SQL INSERT record chunk statement from InsertTarget

piRegister :: PersistableWidth r => Pi r r' -> Register r (PlaceHolders r') #

parametalized Register monad from Pi

insertTarget' :: Register r (PlaceHolders p) -> InsertTarget p r #

Finalize Target monad and generate UpdateTarget with place-holder parameter p.

insertTarget :: Register r () -> InsertTarget () r #

Finalize Register monad and generate InsertTarget.

sqlFromUpdateTarget :: Config -> Table r -> UpdateTarget p r -> StringSQL #

SQL SET clause and WHERE clause StringSQL string from UpdateTarget

updateTargetAllColumn' :: PersistableWidth r => RestrictedStatement r (PlaceHolders p) -> UpdateTarget (r, p) r #

Finalize Restrict monad and generate UpdateTarget. Update target columns are all. With placefolder type p.

updateTargetAllColumn :: PersistableWidth r => RestrictedStatement r () -> UpdateTarget r r #

Finalize Restrict monad and generate UpdateTarget. Update target columns are all.

liftTargetAllColumn' :: PersistableWidth r => Restriction p r -> UpdateTarget (r, p) r #

Lift Restriction to UpdateTarget. Update target columns are all. With placefolder type p.

liftTargetAllColumn :: PersistableWidth r => Restriction () r -> UpdateTarget r r #

Lift Restriction to UpdateTarget. Update target columns are all.

updateTarget' :: AssignStatement r (PlaceHolders p) -> UpdateTarget p r #

Finalize Target monad and generate UpdateTarget with place-holder parameter p.

updateTarget :: AssignStatement r () -> UpdateTarget () r #

Finalize Target monad and generate UpdateTarget.

sqlWhereFromRestriction :: Config -> Table r -> Restriction p r -> StringSQL #

SQL WHERE clause StringSQL string from Restriction.

restriction' :: RestrictedStatement r (PlaceHolders p) -> Restriction p r #

Finalize Restrict monad and generate Restriction with place-holder parameter p

restriction :: RestrictedStatement r () -> Restriction () r #

Finalize Restrict monad and generate Restriction.

data Restriction p r #

Restriction type with place-holder parameter p and projected record type r.

Instances
TableDerivable r => Show (Restriction p r)

Show where clause.

Instance details

Defined in Database.Relational.Effect

Methods

showsPrec :: Int -> Restriction p r -> ShowS #

show :: Restriction p r -> String #

showList :: [Restriction p r] -> ShowS #

data UpdateTarget p r #

UpdateTarget type with place-holder parameter p and projected record type r.

Instances
TableDerivable r => Show (UpdateTarget p r) 
Instance details

Defined in Database.Relational.Effect

data InsertTarget p r #

InsertTarget type with place-holder parameter p and projected record type r.

intersectAll' :: Relation p a -> Relation q a -> Relation (p, q) a infixl 8 #

Intersection of two relations with place-holder parameters. Not distinct.

intersect' :: Relation p a -> Relation q a -> Relation (p, q) a infixl 8 #

Intersection of two relations with place-holder parameters.

exceptAll' :: Relation p a -> Relation q a -> Relation (p, q) a infixl 7 #

Subtraction of two relations with place-holder parameters. Not distinct.

except' :: Relation p a -> Relation q a -> Relation (p, q) a infixl 7 #

Subtraction of two relations with place-holder parameters.

unionAll' :: Relation p a -> Relation q a -> Relation (p, q) a infixl 7 #

Union of two relations with place-holder parameters. Not distinct.

union' :: Relation p a -> Relation q a -> Relation (p, q) a infixl 7 #

Union of two relations with place-holder parameters.

intersectAll :: Relation () a -> Relation () a -> Relation () a infixl 8 #

Intersection of two relations. Not distinct.

intersect :: Relation () a -> Relation () a -> Relation () a infixl 8 #

Intersection of two relations.

exceptAll :: Relation () a -> Relation () a -> Relation () a infixl 7 #

Subtraction of two relations. Not distinct.

except :: Relation () a -> Relation () a -> Relation () a infixl 7 #

Subtraction of two relations.

unionAll :: Relation () a -> Relation () a -> Relation () a infixl 7 #

Union of two relations. Not distinct.

union :: Relation () a -> Relation () a -> Relation () a infixl 7 #

Union of two relations.

on' :: ([JoinRestriction a b] -> Relation pc (a, b)) -> [JoinRestriction a b] -> Relation pc (a, b) infixl 8 #

Apply restriction for direct join style.

full infixl 8 #

Arguments

:: Relation () a

Left query to join

-> Relation () b

Right query to join

-> [JoinRestriction (Maybe a) (Maybe b)]

Join restrictions

-> Relation () (Maybe a, Maybe b)

Result joined relation

Direct full outer join.

right infixl 8 #

Arguments

:: Relation () a

Left query to join

-> Relation () b

Right query to join

-> [JoinRestriction (Maybe a) b]

Join restrictions

-> Relation () (Maybe a, b)

Result joined relation

Direct right outer join.

left infixl 8 #

Arguments

:: Relation () a

Left query to join

-> Relation () b

Right query to join

-> [JoinRestriction a (Maybe b)]

Join restrictions

-> Relation () (a, Maybe b)

Result joined relation

Direct left outer join.

inner infixl 8 #

Arguments

:: Relation () a

Left query to join

-> Relation () b

Right query to join

-> [JoinRestriction a b]

Join restrictions

-> Relation () (a, b)

Result joined relation

Direct inner join.

full' infixl 8 #

Arguments

:: Relation pa a

Left query to join

-> Relation pb b

Right query to join

-> [JoinRestriction (Maybe a) (Maybe b)]

Join restrictions

-> Relation (pa, pb) (Maybe a, Maybe b)

Result joined relation

Direct full outer join with place-holder parameters.

right' infixl 8 #

Arguments

:: Relation pa a

Left query to join

-> Relation pb b

Right query to join

-> [JoinRestriction (Maybe a) b]

Join restrictions

-> Relation (pa, pb) (Maybe a, b)

Result joined relation

Direct right outer join with place-holder parameters.

left' infixl 8 #

Arguments

:: Relation pa a

Left query to join

-> Relation pb b

Right query to join

-> [JoinRestriction a (Maybe b)]

Join restrictions

-> Relation (pa, pb) (a, Maybe b)

Result joined relation

Direct left outer join with place-holder parameters.

inner' infixl 8 #

Arguments

:: Relation pa a

Left query to join

-> Relation pb b

Right query to join

-> [JoinRestriction a b]

Join restrictions

-> Relation (pa, pb) (a, b)

Result joined relation

Direct inner join with place-holder parameters.

type JoinRestriction a b = Record Flat a -> Record Flat b -> Predicate Flat #

Restriction predicate function type for direct style join operator, used on predicates of direct join style as follows.

  do xy <- query $
           relX inner relY on' [ x y -> ... ] -- this lambda form has JoinRestriction type
     ...

queryScalar :: (MonadQualify ConfigureQuery m, ScalarDegree r) => UniqueRelation () c r -> m (Record c (Maybe r)) #

Scalar sub-query.

queryScalar' :: (MonadQualify ConfigureQuery m, ScalarDegree r) => UniqueRelation p c r -> m (PlaceHolders p, Record c (Maybe r)) #

Scalar sub-query with place-holder parameter p.

uniqueRelation' :: QueryUnique (PlaceHolders p, Record c r) -> UniqueRelation p c r #

Finalize QueryUnique monad and generate UniqueRelation.

uniqueQueryMaybe' :: UniqueRelation p c r -> QueryUnique (PlaceHolders p, Record c (Maybe r)) #

Join unique sub-query with place-holder parameter p. Query result is Maybe.

uniqueQuery' :: UniqueRelation p c r -> QueryUnique (PlaceHolders p, Record c r) #

Join unique sub-query with place-holder parameter p.

unUnique :: UniqueRelation p c r -> Relation p r #

Discard unique attribute.

unsafeUnique :: Relation p r -> UniqueRelation p c r #

Unsafely specify unique relation.

aggregateRelation' :: AggregatedQuery p r -> Relation p r #

Finalize QueryAggregate monad and geneate Relation with place-holder parameter p.

relation :: QuerySimple (Record Flat r) -> Relation () r #

Finalize QuerySimple monad and generate Relation.

relation' :: SimpleQuery p r -> Relation p r #

Finalize QuerySimple monad and generate Relation with place-holder parameter p.

queryList :: MonadQualify ConfigureQuery m => Relation () r -> m (RecordList (Record c) r) #

List sub-query, for IN and EXIST.

queryList' :: MonadQualify ConfigureQuery m => Relation p r -> m (PlaceHolders p, RecordList (Record c) r) #

List sub-query, for IN and EXIST with place-holder parameter p.

queryMaybe :: (MonadQualify ConfigureQuery m, MonadQuery m) => Relation () r -> m (Record Flat (Maybe r)) #

Join sub-query. Query result is Maybe. The combinations of query and queryMaybe express inner joins, left outer joins, right outer joins, and full outer joins. Here is an example of a right outer join:

  outerJoin = relation $ do
    e <- queryMaybe employee
    d <- query department
    on $ e ?! E.deptId' .=. just (d ! D.deptId')
    return $ (,) |$| e |*| d

query :: (MonadQualify ConfigureQuery m, MonadQuery m) => Relation () r -> m (Record Flat r) #

Join sub-query. Query result is not Maybe.

tableOf :: TableDerivable r => Relation () r -> Table r #

Interface to derive Table type object.

table :: Table r -> Relation () r #

Simple Relation from Table.

data UniqueRelation p c r #

Unique relation type to compose scalar queries.

over :: SqlContext c => Record OverWindow a -> Window c () -> Record c a infix 8 #

Operator to make record of window function result using built Window monad.

type Window c = Orderings c (PartitioningSet c) #

Partition monad type for partition-by clause.

groupingSets :: AggregatingSetList a -> AggregateKey a #

Finalize grouping set list.

cube :: AggregatingPowerSet a -> AggregateKey a #

Finalize grouping power set as cube power set.

rollup :: AggregatingPowerSet a -> AggregateKey a #

Finalize grouping power set as rollup power set.

bkey :: Record Flat r -> AggregatingPowerSet (Record Aggregated (Maybe r)) #

Specify key of rollup and cube power set.

set :: AggregatingSet a -> AggregatingSetList a #

Finalize and specify single grouping set.

key' :: AggregateKey a -> AggregatingSet a #

Specify key of single grouping set.

key :: Record Flat r -> AggregatingSet (Record Aggregated (Maybe r)) #

Specify key of single grouping set from Record.

type Assign r = Assignings r Restrict #

Target update monad type used from update statement and merge statement.

type Register r = Assignings r ConfigureQuery #

Target register monad type used from insert statement.

(<-#) :: Monad m => AssignTarget r v -> Record Flat v -> Assignings r m () infix 4 #

Add and assginment.

assignTo :: Monad m => Record Flat v -> AssignTarget r v -> Assignings r m () #

Add an assignment.

type QuerySimple = Orderings Flat QueryCore #

Simple (not-aggregated) query monad type.

type SimpleQuery p r = OrderedQuery Flat QueryCore p r #

Simple (not-aggregated) query type. SimpleQuery' p r == QuerySimple (PlaceHolders p, Record r).

type QueryCore = Restrictings Flat (QueryJoin ConfigureQuery) #

Core query monad type used from flat(not-aggregated) query and aggregated query.

type OrderedQuery c (m :: * -> *) p r = Orderings c m (PlaceHolders p, Record c r) #

OrderedQuery monad type with placeholder type p. Record must be the same as Orderings context type parameter c.

desc #

Arguments

:: Monad m 
=> Record c t

Ordering terms to add

-> Orderings c m ()

Result context with ordering

Add descendant ordering term.

asc #

Arguments

:: Monad m 
=> Record c t

Ordering terms to add

-> Orderings c m ()

Result context with ordering

Add ascendant ordering term.

orderBy #

Arguments

:: Monad m 
=> Record c t

Ordering terms to add

-> Order

Order direction

-> Orderings c m ()

Result context with ordering

Add ordering terms.

orderBy' #

Arguments

:: Monad m 
=> Record c t

Ordering terms to add

-> Order

Order direction

-> Nulls

Order of null

-> Orderings c m ()

Result context with ordering

Add ordering terms with null ordering.

type Restrict = Restrictings Flat ConfigureQuery #

Restrict only monad type used from update statement and delete statement.

having :: MonadRestrict Aggregated m => Predicate Aggregated -> m () #

Add restriction to this aggregated query. Aggregated Record type version.

wheres :: MonadRestrict Flat m => Predicate Flat -> m () #

Add restriction to this not aggregated query.

on :: MonadQuery m => Predicate Flat -> m () #

Add restriction to last join. Record type version.

distinct :: MonadQuery m => m () #

Specify DISTINCT attribute to query context.

all' :: MonadQuery m => m () #

Specify ALL attribute to query context.

class (Functor m, Monad m) => MonadRestrict c (m :: * -> *) where #

Restrict context interface

Minimal complete definition

restrict

Methods

restrict #

Arguments

:: Predicate c

Record which represent restriction

-> m ()

Restricted query context

Add restriction to this context.

Instances
MonadRestrict c m => MonadRestrict c (AggregatingSetT m)

Aggregated MonadRestrict.

Instance details

Defined in Database.Relational.Monad.Trans.Aggregating

Methods

restrict :: Predicate c -> AggregatingSetT m () #

MonadRestrict rc m => MonadRestrict rc (Orderings c m)

MonadRestrict with ordering.

Instance details

Defined in Database.Relational.Monad.Trans.Ordering

Methods

restrict :: Predicate rc -> Orderings c m () #

MonadRestrict c m => MonadRestrict c (Assignings r m)

MonadRestrict with assigning.

Instance details

Defined in Database.Relational.Monad.Trans.Assigning

Methods

restrict :: Predicate c -> Assignings r m () #

class (Functor m, Monad m, MonadQualify ConfigureQuery m) => MonadQuery (m :: * -> *) where #

Query building interface.

Minimal complete definition

setDuplication, restrictJoin, query', queryMaybe'

Methods

query' :: Relation p r -> m (PlaceHolders p, Record Flat r) #

Join sub-query with place-holder parameter p. query result is not Maybe.

queryMaybe' :: Relation p r -> m (PlaceHolders p, Record Flat (Maybe r)) #

Join sub-query with place-holder parameter p. Query result is Maybe.

class (Functor q, Monad q, Functor m, Monad m) => MonadQualify (q :: * -> *) (m :: * -> *) #

Lift interface from base qualify monad.

Minimal complete definition

liftQualify

Instances
(Functor q, Monad q) => MonadQualify q q 
Instance details

Defined in Database.Relational.Monad.Class

Methods

liftQualify :: q a -> q a #

MonadQualify ConfigureQuery QueryUnique 
Instance details

Defined in Database.Relational.Monad.Unique

MonadQualify q m => MonadQualify q (AggregatingSetT m)

Aggregated MonadQualify.

Instance details

Defined in Database.Relational.Monad.Trans.Aggregating

Methods

liftQualify :: q a -> AggregatingSetT m a #

MonadQualify q m => MonadQualify q (Orderings c m)

MonadQualify with ordering.

Instance details

Defined in Database.Relational.Monad.Trans.Ordering

Methods

liftQualify :: q a -> Orderings c m a #

MonadQualify q m => MonadQualify q (Assignings r m)

MonadQualify with assigning.

Instance details

Defined in Database.Relational.Monad.Trans.Assigning

Methods

liftQualify :: q a -> Assignings r m a #

class MonadQuery m => MonadAggregate (m :: * -> *) where #

Aggregated query building interface extends MonadQuery.

Minimal complete definition

groupBy, groupBy'

Methods

groupBy #

Arguments

:: Record Flat r

Record to add into group by

-> m (Record Aggregated r)

Result context and aggregated record | Add GROUP BY term into context and get aggregated record. Non-traditional group-by version.

Add GROUP BY term into context and get aggregated record.

groupBy' #

Arguments

:: AggregateKey (Record Aggregated r)

Key to aggretate for non-traditional group-by interface

-> m (Record Aggregated r)

Result context and aggregated record

class Monad m => MonadPartition c (m :: * -> *) where #

Window specification building interface.

Minimal complete definition

partitionBy

Methods

partitionBy :: Record c r -> m () #

Add PARTITION BY term into context.

Instances
MonadPartition c m => MonadPartition c (Orderings c m)

MonadPartition with ordering.

Instance details

Defined in Database.Relational.Monad.Trans.Ordering

Methods

partitionBy :: Record c r -> Orderings c m () #

Monad m => MonadPartition c (PartitioningSetT c m)

Partition clause instance

Instance details

Defined in Database.Relational.Monad.Trans.Aggregating

Methods

partitionBy :: Record c r -> PartitioningSetT c m () #

(??) infixl 8 #

Arguments

:: PersistableWidth a 
=> Record c (Maybe a)

Source Record. Maybe phantom type

-> Pi a (Maybe b)

Record path. Maybe type leaf

-> Record c (Maybe b)

Narrower projected object. Maybe phantom type result

Same as '(?!?)'. Use this operator like '(?? #foo) mayX'.

(?) infixl 8 #

Arguments

:: PersistableWidth a 
=> Record c (Maybe a)

Source Record. Maybe type

-> Pi a b

Record path

-> Record c (Maybe b)

Narrower projected object. Maybe type result

Same as '(?!)'. Use this operator like '(? #foo) mayX'.

(!??) infixl 8 #

Arguments

:: (PersistableWidth a, ProjectableFlattenMaybe (Maybe b) c) 
=> Record cont (Maybe a)

Source Record. Maybe phantom type

-> Pi a b

Projection path

-> Record cont c

Narrower flatten and projected object.

Get narrower record with flatten leaf phantom Maybe types along with projection path.

flattenPiMaybe #

Arguments

:: (PersistableWidth a, ProjectableFlattenMaybe (Maybe b) c) 
=> Record cont (Maybe a)

Source Record. Maybe phantom type

-> Pi a b

Projection path

-> Record cont c

Narrower Record. Flatten Maybe phantom type

Get narrower record with flatten leaf phantom Maybe types along with projection path.

(?!?) infixl 8 #

Arguments

:: PersistableWidth a 
=> Record c (Maybe a)

Source Record. Maybe phantom type

-> Pi a (Maybe b)

Record path. Maybe type leaf

-> Record c (Maybe b)

Narrower projected object. Maybe phantom type result

Get narrower record along with projection path and project into result record type. Source record Maybe phantom functor and projection path leaf Maybe functor are join-ed.

(?!) infixl 8 #

Arguments

:: PersistableWidth a 
=> Record c (Maybe a)

Source Record. Maybe type

-> Pi a b

Record path

-> Record c (Maybe b)

Narrower projected object. Maybe type result

Get narrower record along with projection path Maybe phantom functor is map-ed.

(!) infixl 8 #

Arguments

:: PersistableWidth a 
=> Record c a

Source Record

-> Pi a b

Record path

-> Record c b

Narrower projected object

Get narrower record along with projection path.

some' :: (AggregatedContext ac, SqlContext ac) => Predicate Flat -> Record ac (Maybe Bool) #

Aggregation function SOME.

any' :: (AggregatedContext ac, SqlContext ac) => Predicate Flat -> Record ac (Maybe Bool) #

Aggregation function ANY.

every :: (AggregatedContext ac, SqlContext ac) => Predicate Flat -> Record ac (Maybe Bool) #

Aggregation function EVERY.

min' :: (Ord a, AggregatedContext ac, SqlContext ac) => Record Flat a -> Record ac (Maybe a) #

Aggregation function MIN.

minMaybe :: (Ord a, AggregatedContext ac, SqlContext ac) => Record Flat (Maybe a) -> Record ac (Maybe a) #

Aggregation function MIN.

max' :: (Ord a, AggregatedContext ac, SqlContext ac) => Record Flat a -> Record ac (Maybe a) #

Aggregation function MAX.

maxMaybe :: (Ord a, AggregatedContext ac, SqlContext ac) => Record Flat (Maybe a) -> Record ac (Maybe a) #

Aggregation function MAX.

avg :: (Num a, Fractional b, AggregatedContext ac, SqlContext ac) => Record Flat a -> Record ac (Maybe b) #

Aggregation function AVG.

avgMaybe :: (Num a, Fractional b, AggregatedContext ac, SqlContext ac) => Record Flat (Maybe a) -> Record ac (Maybe b) #

Aggregation function AVG.

sum' :: (Num a, AggregatedContext ac, SqlContext ac) => Record Flat a -> Record ac (Maybe a) #

Aggregation function SUM.

sumMaybe :: (Num a, AggregatedContext ac, SqlContext ac) => Record Flat (Maybe a) -> Record ac (Maybe a) #

Aggregation function SUM.

count :: (Integral b, AggregatedContext ac, SqlContext ac) => Record Flat a -> Record ac b #

Aggregation function COUNT.

unsafeAggregateOp :: (AggregatedContext ac, SqlContext ac) => Keyword -> Record Flat a -> Record ac b #

Unsafely make aggregation uni-operator from SQL keyword.

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

Binary operator the same as projectZip.

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

Zipping projections.

placeholder :: (PersistableWidth t, SqlContext c, Monad m) => (Record c t -> m a) -> m (PlaceHolders t, a) #

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

placeholder' :: (PersistableWidth t, SqlContext c) => (Record c t -> a) -> (PlaceHolders t, a) #

Provide scoped placeholder and return its parameter object.

pwPlaceholder :: SqlContext c => PersistableRecordWidth a -> (Record c a -> b) -> (PlaceHolders a, b) #

Provide scoped placeholder from width and return its parameter object.

unitPH :: PlaceHolders () #

No placeholder semantics. Same as unitPlaceHolder

unitPlaceHolder :: PlaceHolders () #

No placeholder semantics

unsafePlaceHolders :: PlaceHolders p #

Unsafely get placeholder parameter

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

Unsafely add placeholder parameter to queries.

cumeDist :: Record OverWindow Double #

CUME_DIST() term.

percentRank :: Record OverWindow Double #

PERCENT_RANK() term.

rowNumber :: Integral a => Record OverWindow a #

ROW_NUMBER() term.

denseRank :: Integral a => Record OverWindow a #

DENSE_RANK() term.

rank :: Integral a => Record OverWindow a #

RANK() term.

fromMaybe :: (OperatorContext c, HasColumnConstraint NotNull r) => Record c r -> Record c (Maybe r) -> Record c r #

Operator from maybe type using record extended isNull.

isJust :: (OperatorContext c, HasColumnConstraint NotNull r) => Record c (Maybe r) -> Predicate c #

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

isNothing :: (OperatorContext c, HasColumnConstraint NotNull r) => Record c (Maybe r) -> Predicate c #

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

in' :: OperatorContext c => Record c t -> RecordList (Record c) t -> Record c (Maybe Bool) infix 4 #

Binary operator corresponding SQL IN .

caseMaybe #

Arguments

:: (OperatorContext c, PersistableWidth b) 
=> Record c a

Record value to match

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

Each when clauses

-> Record c (Maybe b)

Result record

Null default version of case'.

casesOrElse' #

Arguments

:: OperatorContext c 
=> (Record c a, [(Record c a, Record c b)])

Record value to match and each when clauses list

-> Record c b

Else result record

-> Record c b

Result record

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

case' #

Arguments

:: OperatorContext c 
=> Record c a

Record value to match

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

Each when clauses

-> Record c b

Else result record

-> Record c b

Result record

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

caseSearchMaybe #

Arguments

:: (OperatorContext c, PersistableWidth a) 
=> [(Predicate c, Record c (Maybe a))]

Each when clauses

-> Record c (Maybe a)

Result record

Null default version of caseSearch.

casesOrElse #

Arguments

:: OperatorContext c 
=> [(Predicate c, Record c a)]

Each when clauses

-> Record c a

Else result record

-> Record c a

Result record

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

caseSearch #

Arguments

:: OperatorContext c 
=> [(Predicate c, Record c a)]

Each when clauses

-> Record c a

Else result record

-> Record c a

Result record

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

showNumMaybe :: (SqlContext c, Num a, IsString b) => Record c (Maybe a) -> Record c (Maybe b) #

Unsafely show number into string-like type in records.

fromIntegralMaybe :: (SqlContext c, Integral a, Num b) => Record c (Maybe a) -> Record c (Maybe b) #

Number fromIntegral uni-operator.

negateMaybe :: (OperatorContext c, Num a) => Record c (Maybe a) -> Record c (Maybe a) #

Number negate uni-operator corresponding SQL -.

(?*?) :: (OperatorContext c, Num a) => Record c (Maybe a) -> Record c (Maybe a) -> Record c (Maybe a) infixl 7 #

Number operator corresponding SQL * .

(?/?) :: (OperatorContext c, Num a) => Record c (Maybe a) -> Record c (Maybe a) -> Record c (Maybe a) infixl 7 #

Number operator corresponding SQL /// .

(?-?) :: (OperatorContext c, Num a) => Record c (Maybe a) -> Record c (Maybe a) -> Record c (Maybe a) infixl 6 #

Number operator corresponding SQL - .

(?+?) :: (OperatorContext c, Num a) => Record c (Maybe a) -> Record c (Maybe a) -> Record c (Maybe a) infixl 6 #

Number operator corresponding SQL + .

showNum :: (SqlContext c, Num a, IsString b) => Record c a -> Record c b #

Unsafely show number into string-like type in records.

fromIntegral' :: (SqlContext c, Integral a, Num b) => Record c a -> Record c b #

Number fromIntegral uni-operator.

negate' :: (OperatorContext c, Num a) => Record c a -> Record c a #

Number negate uni-operator corresponding SQL -.

(.*.) :: (OperatorContext c, Num a) => Record c a -> Record c a -> Record c a infixl 7 #

Number operator corresponding SQL * .

(./.) :: (OperatorContext c, Num a) => Record c a -> Record c a -> Record c a infixl 7 #

Number operator corresponding SQL /// .

(.-.) :: (OperatorContext c, Num a) => Record c a -> Record c a -> Record c a infixl 6 #

Number operator corresponding SQL - .

(.+.) :: (OperatorContext c, Num a) => Record c a -> Record c a -> Record c a infixl 6 #

Number operator corresponding SQL + .

likeMaybe :: (OperatorContext c, IsString a, LiteralSQL a) => Record c (Maybe a) -> a -> Record c (Maybe Bool) infix 4 #

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

like :: (OperatorContext c, IsString a, LiteralSQL a) => Record c a -> a -> Record c (Maybe Bool) infix 4 #

String-compare operator corresponding SQL LIKE .

likeMaybe' :: (OperatorContext c, IsString a) => Record c (Maybe a) -> Record c (Maybe a) -> Record c (Maybe Bool) infix 4 #

String-compare operator corresponding SQL LIKE .

like' :: (OperatorContext c, IsString a) => Record c a -> Record c a -> Record c (Maybe Bool) infix 4 #

String-compare operator corresponding SQL LIKE .

(?||?) :: (OperatorContext c, IsString a) => Record c (Maybe a) -> Record c (Maybe a) -> Record c (Maybe a) infixl 5 #

Concatinate operator corresponding SQL || . Maybe type version.

(.||.) :: OperatorContext c => Record c a -> Record c a -> Record c a infixl 5 #

Concatinate operator corresponding SQL || .

exists :: OperatorContext c => RecordList (Record Exists) r -> Record c (Maybe Bool) #

Logical operator corresponding SQL EXISTS .

not' :: OperatorContext c => Record c (Maybe Bool) -> Record c (Maybe Bool) #

Logical operator corresponding SQL NOT .

or' :: OperatorContext c => Record c (Maybe Bool) -> Record c (Maybe Bool) -> Record c (Maybe Bool) infixr 2 #

Logical operator corresponding SQL OR .

and' :: OperatorContext c => Record c (Maybe Bool) -> Record c (Maybe Bool) -> Record c (Maybe Bool) infixr 3 #

Logical operator corresponding SQL AND .

(.<>.) :: OperatorContext c => Record c ft -> Record c ft -> Record c (Maybe Bool) infix 4 #

Compare operator corresponding SQL <> .

(.>=.) :: OperatorContext c => Record c ft -> Record c ft -> Record c (Maybe Bool) infix 4 #

Compare operator corresponding SQL >= .

(.>.) :: OperatorContext c => Record c ft -> Record c ft -> Record c (Maybe Bool) infix 4 #

Compare operator corresponding SQL > .

(.<=.) :: OperatorContext c => Record c ft -> Record c ft -> Record c (Maybe Bool) infix 4 #

Compare operator corresponding SQL <= .

(.<.) :: OperatorContext c => Record c ft -> Record c ft -> Record c (Maybe Bool) infix 4 #

Compare operator corresponding SQL < .

(.=.) :: OperatorContext c => Record c ft -> Record c ft -> Record c (Maybe Bool) infix 4 #

Compare operator corresponding SQL = .

unsafeBinOp :: SqlContext k => SqlBinOp -> Record k a -> Record k b -> Record k c #

Unsafely make binary operator for records from string binary operator.

unsafeUniOp :: SqlContext c2 => (Keyword -> Keyword) -> Record c1 a -> Record c2 b #

Unsafely make unary operator for records from SQL keyword.

unsafeShowSql #

Arguments

:: Record c a

Source record object

-> String

Result SQL expression string.

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

unsafeShowSql' :: Record c a -> StringSQL #

Unsafely generate SQL expression term from record object.

values :: (LiteralSQL t, OperatorContext c) => [t] -> RecordList (Record c) t #

RecordList with polymorphic type of SQL set value from Haskell list.

valueFalse :: OperatorContext c => Record c (Maybe Bool) #

Record with polymorphic type of SQL false value.

valueTrue :: OperatorContext c => Record c (Maybe Bool) #

Record with polymorphic type of SQL true value.

value :: (LiteralSQL t, OperatorContext c) => t -> Record c t #

Generate record with polymorphic type of SQL constant values from Haskell value.

nothing :: (OperatorContext c, SqlContext c, PersistableWidth a) => Record c (Maybe a) #

Record with polymorphic phantom type of SQL null value. Semantics of comparing is unsafe.

unsafeProjectSql :: SqlContext c => String -> Record c t #

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

unsafeProjectSql' :: SqlContext c => StringSQL -> Record c t #

Unsafely Project single SQL term.

type SqlBinOp = Keyword -> Keyword -> Keyword #

Binary operator type for SQL String.

class ProjectableMaybe (p :: * -> *) where #

Interface to control Maybe of phantom type in records.

Minimal complete definition

just, flattenMaybe

Methods

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

Cast record phantom type into Maybe.

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

Compose nested Maybe phantom type on record.

Instances
ProjectableMaybe PlaceHolders

Control phantom Maybe type in placeholder parameters.

Instance details

Defined in Database.Relational.Projectable

ProjectableMaybe (Record c)

Control phantom Maybe type in record type Record.

Instance details

Defined in Database.Relational.Projectable

Methods

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

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

class ProjectableFlattenMaybe a b where #

Interface to compose phantom Maybe nested type.

Minimal complete definition

flatten

Methods

flatten :: ProjectableMaybe p => p a -> p b #

Instances
ProjectableFlattenMaybe (Maybe a) b => ProjectableFlattenMaybe (Maybe (Maybe a)) b

Compose Maybe type in record phantom type.

Instance details

Defined in Database.Relational.Projectable

Methods

flatten :: ProjectableMaybe p => p (Maybe (Maybe a)) -> p b #

ProjectableFlattenMaybe (Maybe a) (Maybe a)

Not Maybe type is not processed.

Instance details

Defined in Database.Relational.Projectable

Methods

flatten :: ProjectableMaybe p => p (Maybe a) -> p (Maybe a) #

snd' :: (PersistableWidth a, PersistableWidth b) => Pi (a, b) b #

Projection path for snd of tuple.

fst' :: (PersistableWidth a, PersistableWidth b) => Pi (a, b) a #

Projection path for fst of tuple.

tuplePi2_1' :: (PersistableWidth a1, PersistableWidth a2) => Pi (a1, a2) a2 #

tuplePi2_0' :: (PersistableWidth a1, PersistableWidth a2) => Pi (a1, a2) a1 #

updateOtherThanKeySQL #

Arguments

:: Table r

Table metadata

-> Pi r p

Key columns

-> String

Result SQL

Generate update SQL specified by single key.

type QuerySuffix = [Keyword] #

Type for query suffix words

list :: [p t] -> RecordList p t #

Make projected record list from Record list.

data RecordList (p :: * -> *) t #

Projected record list type for row list.

data Table r #

Phantom typed table type

class PersistableWidth r => TableDerivable r where #

Inference rule of Table existence.

Minimal complete definition

derivedTable

Methods

derivedTable :: Table r #

Instances
TableDerivable TableInfo 
Instance details

Defined in Database.Relational.Schema.SQLite3Syscat.TableInfo

TableDerivable IndexList 
Instance details

Defined in Database.Relational.Schema.SQLite3Syscat.IndexList

TableDerivable IndexInfo 
Instance details

Defined in Database.Relational.Schema.SQLite3Syscat.IndexInfo

TableDerivable Customer # 
Instance details

Defined in Customer

TableDerivable Business # 
Instance details

Defined in Business

TableDerivable Branch # 
Instance details

Defined in Branch

TableDerivable Account # 
Instance details

Defined in Account

TableDerivable Department # 
Instance details

Defined in Department

TableDerivable Employee # 
Instance details

Defined in Employee

TableDerivable Individual # 
Instance details

Defined in Individual

TableDerivable Officer # 
Instance details

Defined in Officer

TableDerivable Product # 
Instance details

Defined in Product

TableDerivable ProductType # 
Instance details

Defined in ProductType

TableDerivable Transaction0 # 
Instance details

Defined in Transaction

dump :: Relation p r -> String #

Dump internal structure tree.

sqlFromRelation :: Relation p r -> StringSQL #

SQL string from Relation.

sqlFromRelationWith :: Relation p r -> Config -> StringSQL #

Generate SQL string from Relation with configuration.

leftPh :: Relation (p, ()) r -> Relation p r #

Simplify placeholder type applying right identity element.

rightPh :: Relation ((), p) r -> Relation p r #

Simplify placeholder type applying left identity element.

untypeRelation :: Relation p r -> ConfigureQuery SubQuery #

Sub-query Qualify monad from relation.

unsafeTypeRelation :: ConfigureQuery SubQuery -> Relation p r #

Unsafely type qualified subquery into record typed relation type.

askConfig :: ConfigureQuery Config #

Read configuration.

qualifyQuery :: a -> ConfigureQuery (Qualified a) #

Get qualifyed table form query.

configureQuery :: ConfigureQuery q -> Config -> q #

Run ConfigureQuery monad with initial state to get only result.

type ConfigureQuery = Qualify (QueryConfig Identity) #

Thin monad type for untyped structure.

data Relation p r #

Relation type with place-holder parameter p and query result type r.

Instances
Show (Relation p r) 
Instance details

Defined in Database.Relational.Monad.BaseType

Methods

showsPrec :: Int -> Relation p r -> ShowS #

show :: Relation p r -> String #

showList :: [Relation p r] -> ShowS #

class SqlContext c where #

Interface to project SQL terms unsafely.

Minimal complete definition

unsafeProjectSqlTerms

Methods

unsafeProjectSqlTerms :: [StringSQL] -> Record c t #

Unsafely project from SQL expression terms.

data PlaceHolders p #

Placeholder parameter type which has real parameter type arguemnt p.

Instances
ProjectableMaybe PlaceHolders

Control phantom Maybe type in placeholder parameters.

Instance details

Defined in Database.Relational.Projectable

unitSQL :: SubQuery -> String #

SQL string for nested-qeury.

queryWidth :: Qualified SubQuery -> Int #

Width of Qualified SubQUery.

data Order #

Order direction. Ascendant or Descendant.

Constructors

Asc 
Desc 
Instances
Show Order 
Instance details

Defined in Database.Relational.SqlSyntax.Types

Methods

showsPrec :: Int -> Order -> ShowS #

show :: Order -> String #

showList :: [Order] -> ShowS #

data Nulls #

Order of null.

Constructors

NullsFirst 
NullsLast 
Instances
Show Nulls 
Instance details

Defined in Database.Relational.SqlSyntax.Types

Methods

showsPrec :: Int -> Nulls -> ShowS #

show :: Nulls -> String #

showList :: [Nulls] -> ShowS #

data AggregateKey a #

Typeful aggregate element.

data SubQuery #

Sub-query type

Instances
Show SubQuery 
Instance details

Defined in Database.Relational.SqlSyntax.Types

data Record c t #

Phantom typed record. Projected into Haskell record type t.

Instances
ProjectableMaybe (Record c)

Control phantom Maybe type in record type Record.

Instance details

Defined in Database.Relational.Projectable

Methods

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

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

Show (Record c t) 
Instance details

Defined in Database.Relational.SqlSyntax.Types

Methods

showsPrec :: Int -> Record c t -> ShowS #

show :: Record c t -> String #

showList :: [Record c t] -> ShowS #

type Predicate c = Record c (Maybe Bool) #

Type for predicate to restrict of query result.

type PI c a b = Record c a -> Record c b #

Type for projection function.

class PersistableWidth ct => ScalarDegree ct #

Constraint which represents scalar degree.

Instances
ScalarDegree ct => ScalarDegree (Maybe ct) 
Instance details

Defined in Database.Relational.Scalar

showLiteral :: LiteralSQL a => a -> [StringSQL] #

Convert from haskell record to SQL literal row-value.

class LiteralSQL a where #

LiteralSQL a is implicit rule to derive function to convert from haskell record type a into SQL literal row-value.

Generic programming (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generic-programming) with default signature is available for LiteralSQL class, so you can make instance like below:

  {-# LANGUAGE DeriveGeneric #-}
  import GHC.Generics (Generic)
  --
  data Foo = Foo { ... } deriving Generic
  instance LiteralSQL Foo

Methods

showLiteral' :: a -> DList StringSQL #

Instances
LiteralSQL TableInfo 
Instance details

Defined in Database.Relational.Schema.SQLite3Syscat.TableInfo

LiteralSQL IndexList 
Instance details

Defined in Database.Relational.Schema.SQLite3Syscat.IndexList

LiteralSQL IndexInfo 
Instance details

Defined in Database.Relational.Schema.SQLite3Syscat.IndexInfo

LiteralSQL Customer # 
Instance details

Defined in Customer

LiteralSQL Business # 
Instance details

Defined in Business

LiteralSQL Branch # 
Instance details

Defined in Branch

LiteralSQL Account # 
Instance details

Defined in Account

LiteralSQL Department # 
Instance details

Defined in Department

LiteralSQL Employee # 
Instance details

Defined in Employee

LiteralSQL Individual # 
Instance details

Defined in Individual

LiteralSQL Officer # 
Instance details

Defined in Officer

LiteralSQL Product # 
Instance details

Defined in Product

LiteralSQL ProductType # 
Instance details

Defined in ProductType

LiteralSQL Transaction0 # 
Instance details

Defined in Transaction

derivedUniqueKey :: HasConstraintKey Primary r ct => Key Unique r ct #

Inferred Unique constraint Key. Record type r has unique key which type is ct derived from primay key.

uniqueKey :: PersistableWidth ct => Key Primary r ct -> Key Unique r ct #

Derive Unique constraint Key from Primary constraint Key

projectionKey :: Key c r ct -> Pi r ct #

Get projection path proof object from constraint Key.

tableConstraint :: Key c r ct -> KeyConstraint c r #

Get table constraint KeyConstraint proof object from constraint Key.

data Key c r ct #

Constraint Key proof object. Constraint type c, record type r and columns type ct.

class PersistableWidth ct => HasConstraintKey c r ct where #

Constraint Key inference interface.

Minimal complete definition

constraintKey

Methods

constraintKey :: Key c r ct #

Infer constraint key.

id' :: Pi a a #

Identity projection path.

(<?.?>) :: Pi a (Maybe b) -> Pi b (Maybe c) -> Pi a (Maybe c) infixl 8 #

Compose projection path. Maybe phantom functors are join-ed like >=>.

(<?.>) :: Pi a (Maybe b) -> Pi b c -> Pi a (Maybe c) infixl 8 #

Compose projection path. Maybe phantom functor is map-ed.

(<.>) :: Pi a b -> Pi b c -> Pi a c infixl 8 #

Compose projection path.

data Pi r0 r1 #

Projection path from type r0 into type r1. This type also indicate key object which type is r1 for record type r0.

Instances
ProductIsoFunctor (Pi a)

Map projection path Pi which has record result type.

Instance details

Defined in Database.Relational.Pi.Unsafe

Methods

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

ProductIsoApplicative (Pi a)

Compose projection path Pi which has record result type using applicative style.

Instance details

Defined in Database.Relational.Pi.Unsafe

Methods

pureP :: ProductConstructor a0 => a0 -> Pi a a0 #

(|*|) :: Pi a (a0 -> b) -> Pi a a0 -> Pi a b #

Category Pi 
Instance details

Defined in Database.Relational.Pi.Unsafe

Methods

id :: Pi a a #

(.) :: Pi b c -> Pi a b -> Pi a c #

ProductIsoEmpty (Pi a) () 
Instance details

Defined in Database.Relational.Pi.Unsafe

Methods

pureE :: Pi a () #

peRight :: Pi a (a0, ()) -> Pi a a0 #

peLeft :: Pi a ((), a0) -> Pi a a0 #

PersistableWidth r0 => Show (Pi r0 r1) 
Instance details

Defined in Database.Relational.Pi.Unsafe

Methods

showsPrec :: Int -> Pi r0 r1 -> ShowS #

show :: Pi r0 r1 -> String #

showList :: [Pi r0 r1] -> ShowS #

type StringSQL = Keyword #

String wrap type for SQL strings.

data Flat #

Type tag for flat (not-aggregated) query

data Aggregated #

Type tag for aggregated query

data Exists #

Type tag for exists predicate

data OverWindow #

Type tag for window function building

data SetList #

Type tag for aggregatings GROUPING SETS

data Power #

Type tag for aggregatings power set

defaultConfig :: Config #

Default configuration of Config. To change some behaviour of relational-query, use record update syntax:

  defaultConfig
    { productUnitSupport            =  PUSupported
    , chunksInsertSize              =  256
    , schemaNameMode                =  SchemaQualified
    , normalizedTableName           =  True
    , verboseAsCompilerWarning      =  False
    , disableOverloadedProjection   =  False
    , disableSpecializedProjection  =  False
    , identifierQuotation           =  NoQuotation
    , nameConfig                    =
       defaultNameConfig
       { recordConfig     =  defaultNameConfig
       , relationVarName  =  \schema table -> varCamelcaseName $ table ++ "_" ++ scheme
       -- ^ append the table name after the schema name. e.g. "schemaTable"
       }
    }

defaultNameConfig :: NameConfig #

Default implementation of NameConfig type.

data NameConfig #

NameConfig type to customize names of expanded templates.

data ProductUnitSupport #

Unit of product is supported or not.

data SchemaNameMode #

Schema name qualify mode in SQL string.

Constructors

SchemaQualified

Schema qualified table name in SQL string

SchemaNotQualified

Not qualified table name in SQL string

data IdentifierQuotation #

Configuration for quotation of identifiers of SQL.

Constructors

NoQuotation 
Quotation Char 

data Config #

Configuration type.

Instances
Show Config 
Instance details

Defined in Database.Relational.Internal.Config

runRelation :: (ToSql SqlValue p, IConnection conn, FromSql SqlValue a) => conn -> Relation p a -> p -> IO [a] Source #