Module Database.CDBI.ER

This is the main CDBI-module. It provides datatypes and functions to do Database-Queries working with Entities (ER-Model)

Author: Mike Tallarek, extensions by Julia Krone, Michael Hanus

Version: 0.2

Summary of exported operations:

insertEntry :: a -> EntityDescription a -> Connection -> IO (Either DBError ())   
Inserts an entry into the database.
saveEntry :: a -> EntityDescription a -> Connection -> IO (Either DBError ())   
Saves an entry to the database (only for backward compatibility).
insertEntries :: [a] -> EntityDescription a -> Connection -> IO (Either DBError ())   
Inserts several entries into the database.
saveMultipleEntries :: [a] -> EntityDescription a -> Connection -> IO (Either DBError ())   
Saves multiple entries to the database (only for backward compatibility).
restoreEntries :: [a] -> EntityDescription a -> Connection -> IO (Either DBError ())   
Stores entries with their current keys in the database.
getEntries :: Specifier -> EntityDescription a -> Criteria -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [a])   
Gets entries from the database.
getColumn :: [SetOp] -> [SingleColumnSelect a] -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [a])   
Gets a single Column from the database.
getColumnTuple :: [SetOp] -> [TupleColumnSelect a b] -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [(a,b)])   
Gets two Columns from the database.
getColumnTriple :: [SetOp] -> [TripleColumnSelect a b c] -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [(a,b,c)])   
Gets three Columns from the database.
getColumnFourTuple :: [SetOp] -> [FourColumnSelect a b c d] -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [(a,b,c,d)])   
Gets four Columns from the database.
getColumnFiveTuple :: [SetOp] -> [FiveColumnSelect a b c d e] -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [(a,b,c,d,e)])   
Gets five Columns from the database.
getEntriesCombined :: Specifier -> CombinedDescription a -> [Join] -> Criteria -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [a])   
Gets combined entries from the database.
insertEntryCombined :: a -> CombinedDescription a -> Connection -> IO (Either DBError ())   
Inserts combined entries.
saveEntryCombined :: a -> CombinedDescription a -> Connection -> IO (Either DBError ())   
Saves combined entries (for backward compatibility).
updateEntries :: EntityDescription a -> [ColVal] -> Constraint -> Connection -> IO (Either DBError ())   
Updates entries depending on wether they fulfill the criteria or not
updateEntry :: a -> EntityDescription a -> Connection -> IO (Either DBError ())   
Updates an entry by ID.
updateEntryCombined :: a -> CombinedDescription a -> Connection -> IO (Either DBError ())   
Same as updateEntry but for combined Data
deleteEntries :: EntityDescription a -> Maybe Constraint -> Connection -> IO (Either DBError ())   
Deletes entries depending on wether they fulfill the criteria or not

Exported operations:

insertEntry :: a -> EntityDescription a -> Connection -> IO (Either DBError ())   

Inserts an entry into the database.

Example call:
(insertEntry a en conn)
Parameters:
  • a : The entry to save
  • en : The EntityDescription that describes the entity to be saved
  • conn : A Connection to a database which will be used for this
Returns:
A Result without parameter if saving worked or an Error if there was a problem

saveEntry :: a -> EntityDescription a -> Connection -> IO (Either DBError ())   

Saves an entry to the database (only for backward compatibility).

insertEntries :: [a] -> EntityDescription a -> Connection -> IO (Either DBError ())   

Inserts several entries into the database.

Example call:
(insertEntries xs en conn)
Parameters:
  • xs : The list of entries to save
  • en : The EntityDescription that describes the entities to be saved
  • conn : A Connection to a database which will be used for this
Returns:
A Result without parameter if saving worked or an Error if there was a problem. If one saving operation reports an error, every following saving operation will be aborted but every saving operation up to that point will be executed. If these executed saving operations should also be discarded withTransaction or begin/commit/rollback should be used

saveMultipleEntries :: [a] -> EntityDescription a -> Connection -> IO (Either DBError ())   

Saves multiple entries to the database (only for backward compatibility).

restoreEntries :: [a] -> EntityDescription a -> Connection -> IO (Either DBError ())   

Stores entries with their current keys in the database. It is an error if entries with the same key are already in the database. Thus, this operation is useful only to restore a database with saved data.

Example call:
(restoreEntries xs en conn)
Parameters:
  • xs : The list of entries to save
  • en : The EntityDescription that describes the entities to be saved
  • conn : A Connection to a database which will be used for this
Returns:
A Result without parameter if saving worked or an Error if there was a problem. If one saving operation reports an error, every following saving operation will be aborted but every saving operation up to that point will be executed. If these executed saving operations should also be discarded withTransaction or begin/commit/rollback should be used

getEntries :: Specifier -> EntityDescription a -> Criteria -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [a])   

Gets entries from the database.

Example call:
(getEntries spec en crit op limit conn)
Parameters:
  • spec : Specifier All or Distinct
  • en : The EntityDescription that describes the entity
  • crit : Criteria for the query
  • op : oreder-by clause
  • limit : int value to limit number of entities returned
  • conn : A Connection to a database which will be used for this
Returns:
A Result with a list of entries as parameter or an Error if something went wrong.

getColumn :: [SetOp] -> [SingleColumnSelect a] -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [a])   

Gets a single Column from the database.

Example call:
(getColumn setops sels)
Parameters:
  • setops : list of Setoperators to combine queries if more than one is given, can be empty otherwise
  • sels : list of SingleColumnSelects to specify query, if there are more requests than can be combined with setoperators they will be ignored (where a is the type of the column) or an Error if something went wrong.

getColumnTuple :: [SetOp] -> [TupleColumnSelect a b] -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [(a,b)])   

Gets two Columns from the database.

Example call:
(getColumnTuple setops sels)
Parameters:
  • setops : list of Setoperators to combine queries if more than one is given, can be empty otherwise
  • sels : list of TupleColumnSelects to specify queries, if there are more requests than can be combined with setoperators they will be ignored (where a is the type of the column) or an Error if something went wrong.

getColumnTriple :: [SetOp] -> [TripleColumnSelect a b c] -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [(a,b,c)])   

Gets three Columns from the database.

Example call:
(getColumnTriple setops sels)
Parameters:
  • setops : list of Setoperators to combine queries if more than one is given, can be empty otherwise
  • sels : list of TripleColumnSelects to specify queries, if there are more requests than can be combined with setoperators they will be ignored (where a is the type of the column) or an Error if something went wrong.

getColumnFourTuple :: [SetOp] -> [FourColumnSelect a b c d] -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [(a,b,c,d)])   

Gets four Columns from the database.

Example call:
(getColumnFourTuple setops sels)
Parameters:
  • setops : list of Setoperators to combine queries if more than one is given, can be empty otherwise
  • sels : list of FourColumnSelects to specify queries, if there are more requests than can be combined with setoperators they will be ignored (where a is the type of the column) or an Error if something went wrong.

getColumnFiveTuple :: [SetOp] -> [FiveColumnSelect a b c d e] -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [(a,b,c,d,e)])   

Gets five Columns from the database.

Example call:
(getColumnFiveTuple setops sels)
Parameters:
  • setops : list of Setoperators to combine queries if more than one is given, can be empty otherwise
  • sels : list of FiveColumnSelects to specify queries, if there are more requests than can be combined with setoperators they will be ignored (where a is the type of the column) or an Error if something went wrong.

getEntriesCombined :: Specifier -> CombinedDescription a -> [Join] -> Criteria -> [Option] -> Maybe Int -> Connection -> IO (Either DBError [a])   

Gets combined entries from the database.

Example call:
(getEntriesCombined spec cd joins crit op limit conn)
Parameters:
  • spec : Specifier Distinct or All
  • cd : The CombinedDescription that describes the entity
  • joins : joins to combine the entity, they will be applied in a left-associative manner
  • crit : Criteria for the query
  • op : order-by-clause
  • limit : int value to determine number of values returned
  • conn : A Connection to a database which will be used for this
Returns:
A Result with a list of entries as parameter or an Error if something went wrong.

insertEntryCombined :: a -> CombinedDescription a -> Connection -> IO (Either DBError ())   

Inserts combined entries.

Example call:
(insertEntryCombined a cd conn)
Parameters:
  • a : The combined Entity to be saved
  • cd : The CombinedDescription that describes the entity
  • conn : A Connection to a database which will be used for this
Returns:
A Result without parameter if saving worked or an Error if there was a problem

saveEntryCombined :: a -> CombinedDescription a -> Connection -> IO (Either DBError ())   

Saves combined entries (for backward compatibility).

updateEntries :: EntityDescription a -> [ColVal] -> Constraint -> Connection -> IO (Either DBError ())   

Updates entries depending on wether they fulfill the criteria or not

Example call:
(updateEntries en xs const conn)
Parameters:
  • en : The EntityDescription descriping the Entities that are to be updated
  • xs : A list of ColVal that descripe the columns that should be updated and which values are to be inserted into them
  • const : A Constraint can be be given as input which describes which entities should be updated. Only entities fulfilling the constraint will be updated. Nothing updates every entry.
  • conn : A Connection to a database which will be used for this
Returns:
A Result without parameter if everything went right, an Error if something went wrong
Further infos:
  • partially defined

updateEntry :: a -> EntityDescription a -> Connection -> IO (Either DBError ())   

Updates an entry by ID. Works for Entities that have a primary key as first value. Function will update the entry in the database with the ID of the entry that is given as parameter with the values of the entry given as parameter

Example call:
(updateEntry entry ed conn)
Parameters:
  • entry : The entry that will be updated
  • ed : -> The EntityDescription describung the entity-type
  • conn : -> A Connection to a database which will be used for this
Returns:
A Result without parameter if everything went right, an Error if something went wrong

updateEntryCombined :: a -> CombinedDescription a -> Connection -> IO (Either DBError ())   

Same as updateEntry but for combined Data

deleteEntries :: EntityDescription a -> Maybe Constraint -> Connection -> IO (Either DBError ())   

Deletes entries depending on wether they fulfill the criteria or not

Example call:
(deleteEntries en const conn)
Parameters:
  • en : The EntityDescription descriping the Entities that are to be updated
  • const : A Constraint can be be given as input which describes which entities should be deleted. Only entities fulfilling the constraint will be deleted. Nothing deletes every entry.
  • conn : A Connection to a database which will be used for this
Returns:
A Result without parameter if everything went right, an Error if something went wrong