haskelldb-2.2.2: A library of combinators for generating and executing SQL statements.

Portability | non-portable
Stability | experimental
Maintainer | haskelldb-users@lists.sourceforge.net
Safe Haskell | None

Database.HaskellDB.DBSpec

Description

DBSpec is the new and improved way of specifying databases. It is designed to be able to describe a database in such a way that it can easily be converted to a DBDirect-spec OR directly into a database

Synopsis

- data DBInfo = DBInfo {
  - dbname :: String
  - opts :: DBOptions
  - tbls :: [TInfo]
  }
- data TInfo = TInfo {
  - tname :: String
  - cols :: [CInfo]
  }
- data CInfo = CInfo {
  - cname :: String
  - descr :: FieldDesc
  }
- data DBOptions = DBOptions {
  - useBString :: Bool
  - makeIdent :: MakeIdentifiers
  }
- type FieldDesc = (FieldType, Bool)
- data FieldType
  - = StringT
  - | IntT
  - | IntegerT
  - | DoubleT
  - | BoolT
  - | CalendarTimeT
  - | LocalTimeT
  - | BStrT Int
- makeDBSpec :: String -> DBOptions -> [TInfo] -> DBInfo
- makeTInfo :: String -> [CInfo] -> TInfo
- makeCInfo :: String -> FieldDesc -> CInfo
- constructNonClashingDBInfo :: DBInfo -> DBInfo
- ppDBInfo :: DBInfo -> Doc
- ppTInfo :: TInfo -> Doc
- ppCInfo :: CInfo -> Doc
- ppDBOptions :: DBOptions -> Doc
- dbInfoToDoc :: DBInfo -> Doc
- finalizeSpec :: DBInfo -> DBInfo
- dbToDBSpec :: Bool -> MakeIdentifiers -> String -> Database -> IO DBInfo
- dbSpecToDatabase :: Database -> DBInfo -> IO ()

# Documentation

data DBInfo Source

Defines a database layout, top level

Constructors

DBInfo |

Fields

dbname :: String

  The name of the database

opts :: DBOptions

  Any options (i.e whether to use Bounded Strings)

tbls :: [TInfo]

  Tables this database contains

Instances

Show DBInfo |

data TInfo Source

Constructors

TInfo |

Fields

tname :: String

  The name of the table

cols :: [CInfo]

  The columns in this table

Instances

Eq TInfo |
Show TInfo |

data CInfo Source

Constructors

CInfo |

Fields

cname :: String

  The name of this column

descr :: FieldDesc

  The description of this column

Instances

Eq CInfo |
Show CInfo |

data DBOptions Source

Constructors

DBOptions |

Fields

useBString :: Bool

  Use Bounded Strings?

makeIdent :: MakeIdentifiers

  Conversion routines from Database identifiers to Haskell identifiers

Instances

Show DBOptions |

type FieldDesc = (FieldType, Bool)Source

The type and `nullable` flag of a database column

data FieldType Source

A database column type

Constructors

StringT |
IntT |
IntegerT |
DoubleT |
BoolT |
CalendarTimeT |
LocalTimeT |
BStrT Int |

Instances

Eq FieldType |
Ord FieldType |
Read FieldType |
Show FieldType |

makeDBSpec Source

Arguments

:: String | The name of the Database
-> DBOptions | Options
-> [TInfo] | Tables
-> DBInfo | The generated DBInfo

Creates a DBInfo

makeTInfo Source

Arguments

:: String | The table name
-> [CInfo] | Columns
-> TInfo | The generated TInfo

Creates a TInfo

makeCInfo Source

Arguments

:: String | The column name
-> FieldDesc | What the column contains
-> CInfo | The generated CInfo

Creates a CInfo

constructNonClashingDBInfo :: DBInfo -> DBInfo Source

Constructs a DBInfo that doesn't cause nameclashes

ppDBInfo :: DBInfo -> Doc Source

Pretty prints a DBInfo

ppTInfo :: TInfo -> Doc Source

ppCInfo :: CInfo -> Doc Source

ppDBOptions :: DBOptions -> Doc Source

dbInfoToDoc :: DBInfo -> Doc Source

Creates a valid declaration of a DBInfo. The variable name will be the same as the database name

finalizeSpec :: DBInfo -> DBInfo Source

Does a final touching up of a DBInfo before it is used by i.e DBDirect. This converts any Bounded Strings to ordinary strings if that flag is set.

dbToDBSpec Source

Arguments

:: Bool | Use bounded strings?
-> MakeIdentifiers | style of generated Haskell identifiers, cOLUMN_NAME vs. columnName
-> String | the name our database should have
-> Database | the database connection
-> IO DBInfo | return a DBInfo

Connects to a database and generates a specification from it

dbSpecToDatabase Source

Arguments

:: Database | A Database
-> DBInfo | The DBInfo to generate from
-> IO () |

Converts a DBInfo to a real life Database, note that the database must exist for this to work