Module Database.CDBI.Description

This module contains basic datatypes and operations to represent a relational data model in a type-safe manner. This representation is used by the library Database.CDBI.ER to provide type safety when working with relational databases. The tool erd2cdbi generates from an entity-relationship model a Curry program that represents all entities and relationships by the use of this module.

Author: Mike Tallarek, changes by Julia Krone

Summary of exported operations:

combineDescriptions :: EntityDescription a -> Int -> EntityDescription b -> Int -> (a -> b -> c) -> (c -> (a,b)) -> CombinedDescription c   
A constructor for CombinedDescription.
addDescription :: EntityDescription a -> Int -> (a -> b -> b) -> (b -> a) -> CombinedDescription b -> CombinedDescription b   
Adds another ED to an already existing CD.
getTable :: EntityDescription a -> String   
getTypes :: EntityDescription a -> [SQLType]   
getToValues :: EntityDescription a -> a -> [SQLValue]   
getToInsertValues :: EntityDescription a -> a -> [SQLValue]   
getToEntity :: EntityDescription a -> [SQLValue] -> a   
getColumnSimple :: Column a -> String   
getColumnFull :: Column a -> String   
getColumnName :: ColumnDescription a -> String   
getColumnTableName :: ColumnDescription a -> String   
getColumnTyp :: ColumnDescription a -> SQLType   
getColumnValueBuilder :: ColumnDescription a -> a -> SQLValue   
getColumnValueSelector :: ColumnDescription a -> SQLValue -> a   
toValueOrNull :: (a -> SQLValue) -> Maybe a -> SQLValue   
sqlKeyOrNull :: (a -> Int) -> Maybe a -> SQLValue   
sqlIntOrNull :: Maybe Int -> SQLValue   
sqlFloatOrNull :: Maybe Float -> SQLValue   
sqlCharOrNull :: Maybe Char -> SQLValue   
sqlStringOrNull :: Maybe String -> SQLValue   
sqlString :: String -> SQLValue   
sqlBoolOrNull :: Maybe Bool -> SQLValue   
sqlDateOrNull :: Maybe ClockTime -> SQLValue   
keyOrNothing :: (Int -> a) -> SQLValue -> Maybe a   
intOrNothing :: SQLValue -> Maybe Int   
floatOrNothing :: SQLValue -> Maybe Float   
charOrNothing :: SQLValue -> Maybe Char   
stringOrNothing :: SQLValue -> Maybe String   
fromStringOrNull :: SQLValue -> String   
boolOrNothing :: SQLValue -> Maybe Bool   
dateOrNothing :: SQLValue -> Maybe ClockTime   

Exported datatypes:


EntityDescription

The datatype EntityDescription is a description of a database entity type including the name, the types the entity consists of, a function transforming an instance of this entity to a list of SQLValues, a second function doing the same but converting the key value always to SQLNull to ensure that keys are auto incrementing and a function transforming a list of SQLValues to an instance of this entity

Constructors:


CombinedDescription

Entity-types can be combined (For Example Student and Lecture could be combined to Data StuLec = StuLec Student Lecture). If a description for this new type is written CDBI can look up that type in the database The description is a list of Tuples consisting of a String (The name of the entity type that will be combined), a "rename-number" n which will rename the table to "table as ntable" and a list of SQLTypes (The types that make up that entity type). Furthermore there has to be a function that transform a list of SQLValues into this combined type, and two functions that transform the combined type into a list of SQLValues, the first one for updates, the second one for insertion. The list of sqlvalues needs to match what is returned by the database.

Constructors:


Table

A type representing tablenames

Type synonym: Table = String


Column

A datatype representing column names. The first string is the simple name of the column (for example the column Name of the row Student). The second string is the name of the column combined with the name of the row (for example Student.Name). These names should always be in quotes (for example "Student"."Name") so no errors emerge (the name "Group" for example would result in errors if not in quotes). Has a phantom-type for the value the column represents.

Constructors:

  • Column :: String -> String -> Column a

ColumnDescription

Datatype representing columns for selection. This datatype has to be distinguished from type Column which is just for definition of conditions. The type definition consists of the complete name (including tablename), the SQLType of the column and two functions for the mapping from SQLValue into the resulttype and the other way around

Constructors:


Exported operations:

combineDescriptions :: EntityDescription a -> Int -> EntityDescription b -> Int -> (a -> b -> c) -> (c -> (a,b)) -> CombinedDescription c   

A constructor for CombinedDescription.

Example call:
(combineDescriptions ed1 rename1 ed2 rename2 f)
Parameters:
  • ed1 : Description of the first Entity-Type that is to be combined
  • rename1 : The "rename-number" for ed1. If it is zero ed1 will not be renamed in queries, otherwise is will be renamed as follows: "table as ntable"
  • ed2 : Description of the second Entity-Type that is to be combined
  • rename2 : Same as rename1 for ed2
  • f : A function that describes how the combined entity is built. Takes two entities that make up the combined entity as parameters and combines those into the combined entity.

addDescription :: EntityDescription a -> Int -> (a -> b -> b) -> (b -> a) -> CombinedDescription b -> CombinedDescription b   

Adds another ED to an already existing CD.

Example call:
(addDescription ed1 rename f1 cd)
Parameters:
  • ed1 : The ED to be added
  • rename : The "rename-number"
  • f1 : A function that describes how the combined entity is built. Takes the entity that should be added and the combined entity as parameter and combines those into a new version of the combined entity.
  • cd : The already existing CD

getTable :: EntityDescription a -> String   

Further infos:
  • solution complete, i.e., able to compute all solutions

getTypes :: EntityDescription a -> [SQLType]   

Further infos:
  • solution complete, i.e., able to compute all solutions

getToValues :: EntityDescription a -> a -> [SQLValue]   

Further infos:
  • solution complete, i.e., able to compute all solutions

getToInsertValues :: EntityDescription a -> a -> [SQLValue]   

Further infos:
  • solution complete, i.e., able to compute all solutions

getToEntity :: EntityDescription a -> [SQLValue] -> a   

Further infos:
  • solution complete, i.e., able to compute all solutions

getColumnSimple :: Column a -> String   

Further infos:
  • solution complete, i.e., able to compute all solutions

getColumnFull :: Column a -> String   

Further infos:
  • solution complete, i.e., able to compute all solutions

getColumnName :: ColumnDescription a -> String   

Further infos:
  • solution complete, i.e., able to compute all solutions

getColumnTableName :: ColumnDescription a -> String   

Further infos:
  • solution complete, i.e., able to compute all solutions

getColumnTyp :: ColumnDescription a -> SQLType   

Further infos:
  • solution complete, i.e., able to compute all solutions

getColumnValueBuilder :: ColumnDescription a -> a -> SQLValue   

Further infos:
  • solution complete, i.e., able to compute all solutions

getColumnValueSelector :: ColumnDescription a -> SQLValue -> a   

Further infos:
  • solution complete, i.e., able to compute all solutions

toValueOrNull :: (a -> SQLValue) -> Maybe a -> SQLValue   

sqlKeyOrNull :: (a -> Int) -> Maybe a -> SQLValue   

sqlIntOrNull :: Maybe Int -> SQLValue   

Further infos:
  • solution complete, i.e., able to compute all solutions

sqlFloatOrNull :: Maybe Float -> SQLValue   

Further infos:
  • solution complete, i.e., able to compute all solutions

sqlCharOrNull :: Maybe Char -> SQLValue   

Further infos:
  • solution complete, i.e., able to compute all solutions

sqlStringOrNull :: Maybe String -> SQLValue   

Further infos:
  • solution complete, i.e., able to compute all solutions

sqlString :: String -> SQLValue   

Further infos:
  • solution complete, i.e., able to compute all solutions

sqlBoolOrNull :: Maybe Bool -> SQLValue   

Further infos:
  • solution complete, i.e., able to compute all solutions

sqlDateOrNull :: Maybe ClockTime -> SQLValue   

Further infos:
  • solution complete, i.e., able to compute all solutions

keyOrNothing :: (Int -> a) -> SQLValue -> Maybe a   

Further infos:
  • partially defined

intOrNothing :: SQLValue -> Maybe Int   

Further infos:
  • partially defined
  • solution complete, i.e., able to compute all solutions

floatOrNothing :: SQLValue -> Maybe Float   

Further infos:
  • partially defined
  • solution complete, i.e., able to compute all solutions

charOrNothing :: SQLValue -> Maybe Char   

Further infos:
  • partially defined
  • solution complete, i.e., able to compute all solutions

stringOrNothing :: SQLValue -> Maybe String   

Further infos:
  • partially defined
  • solution complete, i.e., able to compute all solutions

fromStringOrNull :: SQLValue -> String   

Further infos:
  • partially defined
  • solution complete, i.e., able to compute all solutions

boolOrNothing :: SQLValue -> Maybe Bool   

Further infos:
  • partially defined
  • solution complete, i.e., able to compute all solutions

dateOrNothing :: SQLValue -> Maybe ClockTime   

Further infos:
  • partially defined
  • solution complete, i.e., able to compute all solutions