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

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  Deterministic 

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  Deterministic 

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  Deterministic 

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

getTypes :: EntityDescription a -> [SQLType]  Deterministic 

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

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

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

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

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

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

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

getColumnSimple :: Column a -> String  Deterministic 

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

getColumnFull :: Column a -> String  Deterministic 

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

getColumnName :: ColumnDescription a -> String  Deterministic 

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

getColumnTableName :: ColumnDescription a -> String  Deterministic 

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

getColumnTyp :: ColumnDescription a -> SQLType  Deterministic 

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

getColumnValueBuilder :: ColumnDescription a -> a -> SQLValue  Deterministic 

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

getColumnValueSelector :: ColumnDescription a -> SQLValue -> a  Deterministic 

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

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

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

sqlIntOrNull :: Maybe Int -> SQLValue  Deterministic 

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

sqlFloatOrNull :: Maybe Float -> SQLValue  Deterministic 

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

sqlCharOrNull :: Maybe Char -> SQLValue  Deterministic 

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

sqlStringOrNull :: Maybe String -> SQLValue  Deterministic 

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

sqlString :: String -> SQLValue  Deterministic 

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

sqlBoolOrNull :: Maybe Bool -> SQLValue  Deterministic 

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

sqlDateOrNull :: Maybe ClockTime -> SQLValue  Deterministic 

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

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

Further infos:
  • partially defined

intOrNothing :: SQLValue -> Maybe Int  Deterministic 

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

floatOrNothing :: SQLValue -> Maybe Float  Deterministic 

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

charOrNothing :: SQLValue -> Maybe Char  Deterministic 

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

stringOrNothing :: SQLValue -> Maybe String  Deterministic 

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

fromStringOrNull :: SQLValue -> String  Deterministic 

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

boolOrNothing :: SQLValue -> Maybe Bool  Deterministic 

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

dateOrNothing :: SQLValue -> Maybe ClockTime  Deterministic 

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