m |
|
| (6 intermediate revisions not shown.) |
| Line 2: |
Line 2: |
| | == Introduction == | | == Introduction == |
| | | | |
| - | A [[combinator]] library for declarative, type safe database management. A domain specific embedded language, containing the concept of [[extensible record]] and a special Query [[monad]] (among other powerful ideas, see [[#Related concepts]]). | + | A [[combinator]] library for declarative, type safe database management. All queries and operations can be expressed in Haskell. No SQL need be written! |
| | | | |
| - | All the queries and operations are completely expressed within Haskell, no embedded (SQL) commands are needed.
| + | While [https://github.com/m4dc4p/haskelldb HaskellDB is on GitHub], [http://hackage.haskell.org/package/haskelldb Hackage] hosts the [http://hackage.haskell.org/package/haskelldb latest release of HaskellDB]. |
| | | | |
| - | == Status == | + | ==== Archived Information ==== |
| | | | |
| - | HaskellDB, pulled from its repository, builds on GHC 6.10.1.
| + | Archive information from this page can be found on [[Applications and libraries/Database interfaces/HaskellDB/Archive]]. |
| - | | + | |
| - | Some of HaskellDB HDBC backends (ODBC and SQLite3 to be exact) have been updated to work with recent HDBC (2.1 as of this writing).
| + | |
| - | | + | |
| - | This library is in need of some tender love and care. Drop a mail at HaskellDB mailing list if you're interested in improving code or documentation.
| + | |
| - | | + | |
| - | == Homes ==
| + | |
| - | | + | |
| - | === Current Version ===
| + | |
| - | The current repository is stored at code.haskell.org.
| + | |
| - | There was a [http://www.haskell.org/pipermail/haskell-cafe/2008-December/051557.html complaint on Haskell-cafe] that HaskellDB does not compile with GHC 6.10.1. This is only partially true: one can darcs get HaskellDB repository and build it themselves.
| + | |
| - | | + | |
| - | The following procedure worked as of October, 2008:
| + | |
| - | * GHC 6.8.3
| + | |
| - | * Cabal 1.6(?)
| + | |
| - | * HDBC 1.1.5
| + | |
| - | http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HDBC
| + | |
| - | runghc Setup.lhs configure
| + | |
| - | runghc Setup.lhs build
| + | |
| - | sudo runghc Setup.lhs install
| + | |
| - | * HDBC.ODBC 1.1.4.4
| + | |
| - | http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HDBC-odbc
| + | |
| - | runghc Setup.hs configure
| + | |
| - | runghc Setup.hs build
| + | |
| - | sudo runghc Setup.hs install
| + | |
| - | * HaskellDB - patch 743
| + | |
| - | darcs get http://code.haskell.org/haskelldb
| + | |
| - | runghc Setup.hs configure
| + | |
| - | runghc Setup.hs build
| + | |
| - | sudo runghc Setup.hs install
| + | |
| - | cd driver-hdbc
| + | |
| - | runghc Setup.hs configure
| + | |
| - | runghc Setup.hs build
| + | |
| - | sudo runghc Setup.hs install
| + | |
| - | cd ../driver-hdbc-odbc
| + | |
| - | runghc Setup.hs configure
| + | |
| - | runghc Setup.hs build
| + | |
| - | sudo runghc Setup.hs install
| + | |
| - | | + | |
| - | === [http://www.haskell.org/haskellDB/index.html Daan Leijen's original version] ===
| + | |
| - | It makes possible to use Haskell's typecheck system for a type-safe, declarative database management -- a combinator library. It can prevent the user even from using multiple labels in the same record, but the price for this: it needs a special extension of Haskell called Trex (providing [[extensible record]]s).
| + | |
| - | | + | |
| - | HaskellDB was originally developed by Daan Leijen, and is described in the paper Domain Specific Embedded Compilers, Daan Leijen and Erik Meijer. 2nd USENIX Conference on Domain-Specific Languages (DSL), Austin, USA, October 1999.
| + | |
| - | | + | |
| - | === [http://haskelldb.sourceforge.net Chalmers version] ===
| + | |
| - | A student project by Björn Bringert, Anders Höckersten, Conny Andersson, Martin Andersson, Mary Bergman, Victor Blomqvist, Torbjörn Martin.
| + | |
| - | | + | |
| - | It works well with the most common Haskell implementations, because [[extensible record]]s (without check for multiple labels) are implemented in a way which does not need the Trex extension of Haskell.
| + | |
| - | | + | |
| - | See also Björn Bringert's slides [http://www.cs.chalmers.se/~bringert/publ/haskelldb/haskelldb-db-2005.pdf HaskellDB -- Type safe declarative database combinators].
| + | |
| - | | + | |
| - | == Other materials ==
| + | |
| - | | + | |
| - | === How to use ===
| + | |
| - | | + | |
| - | HaskellDB needs database schema expressed in Haskell to operate (not only a schema, but also some boilerplate, too: fortunately, it can be derived automagically). Furthermore, HaskellDB description and real database schema should be kept in sync.
| + | |
| - | | + | |
| - | Here's an example of creating both database tables and appropriate Haskell boilerplate out of database specification.
| + | |
| - | | + | |
| - | <haskell>
| + | |
| - | -- Compile with:
| + | |
| - | -- ghc --make <filename>
| + | |
| - | ---------------------------------
| + | |
| - | -- Compile a Haskell description of a database (from a DBInfo)
| + | |
| - | --
| + | |
| - | import Database.HaskellDB
| + | |
| - | import Database.HaskellDB.DBSpec.DBSpecToDBDirect
| + | |
| - | import Database.HaskellDB.DBSpec
| + | |
| - | import Database.HaskellDB.HDBC.ODBC
| + | |
| - | import Database.HaskellDB.DBSpec.PPHelpers
| + | |
| - | | + | |
| - | ---------------------------------
| + | |
| - | -- Connect to a DSN through ODBC
| + | |
| - | withDB dsn = (connect driver) [ ("dsn",dsn) ]
| + | |
| - | | + | |
| - | ---------------------------------
| + | |
| - | -- An example Database
| + | |
| - | testdb = DBInfo {dbname = "test", opts = testopts, tbls = [testtbl1]}
| + | |
| - | testopts = DBOptions {useBString = False, makeIdent = mkIdentPreserving}
| + | |
| - | testtbl1 = TInfo {tname = "test_tbl", cols = [testcol11,testcol12]}
| + | |
| - | testcol11 = CInfo {cname = "c11", descr = (IntT,False)}
| + | |
| - | testcol12 = CInfo {cname = "c12", descr = (IntT,True)}
| + | |
| - | | + | |
| - | ---------------------------------
| + | |
| - | main = do
| + | |
| - | -- Generate the database type import files from the DBInfo structure
| + | |
| - | dbInfoToModuleFiles "" "Test" testdb
| + | |
| - | | + | |
| - | -- Create the database tables
| + | |
| - | withDB "testdsn" $ \db -> dbSpecToDatabase db testdb
| + | |
| - | </haskell>
| + | |
| - | | + | |
| - | Now we can express queries in a nice declarative and type-safe manner:
| + | |
| - | | + | |
| - | <haskell>
| + | |
| - | -- Compile with:
| + | |
| - | -- ghc --make <filename>
| + | |
| - | ----------------------------------------------
| + | |
| - | -- Query the database and print results
| + | |
| - | --
| + | |
| - | import Database.HaskellDB
| + | |
| - | import Database.HaskellDB.DBSpec.DBSpecToDBDirect
| + | |
| - | import Database.HaskellDB.DBSpec
| + | |
| - | import Database.HaskellDB.HDBC.ODBC
| + | |
| - | | + | |
| - | -- This file generated from "dbInfoToModuleFiles" function in Part 1.
| + | |
| - | import Test.Test_tbl
| + | |
| - | | + | |
| - | ---------------------------------
| + | |
| - | -- Connect to a DSN through ODBC
| + | |
| - | withDB dsn = (connect driver) [ ("dsn",dsn) ]
| + | |
| - | | + | |
| - | ---------------------------------
| + | |
| - | -- Get all the rows from the test table
| + | |
| - | getSomeData :: Database -> IO [(Int,Maybe Int)]
| + | |
| - | getSomeData db = do
| + | |
| - | let q = do
| + | |
| - | t <- table test_tbl
| + | |
| - | order [desc t c11]
| + | |
| - | return t
| + | |
| - | rs <- query db q
| + | |
| - | return $ map (\row -> (row!c11, row!c12)) rs
| + | |
| - | | + | |
| - | ---------------------------------
| + | |
| - | main = do
| + | |
| - | -- Query the database
| + | |
| - | rs <- withDB "testdsn" $ \db -> getSomeData db
| + | |
| - | mapM_ (putStrLn.(\(a,b) -> "(" ++ (show a) ++ "," ++ (show b) ++ ")")) rs
| + | |
| - | </haskell>
| + | |
| - | | + | |
| - | For more examples, see [http://haskelldb.sourceforge.net/getting-started.html Getting Started] and [http://haskelldb.sourceforge.net/guide/ Guide to Hacking].
| + | |
| - | | + | |
| - | === ICS Wiki (FIXME: links seem broken) ===
| + | |
| - | [http://abaris.zoo.cs.uu.nl:8080/wiki/ ICS Wiki] is a huge resource of Haskell materials (among others).
| + | |
| - | * [http://abaris.zoo.cs.uu.nl:8080/wiki/pub/Afp/DomainSpecificLanguages/haskelldb.pdf Database programming with HaskellDB] -- a PDF file (slides). A webpage containing a link to it (among others): the bottom (attachment part) of [http://abaris.zoo.cs.uu.nl:8080/wiki/Afp/DomainSpecificLanguages the ''Domain Specific Languages'' page of ICS Wiki].
| + | |
| - | * There are other links to HaskellDB materials in the [http://abaris.zoo.cs.uu.nl:8080/wiki/Afp/DomainSpecificLanguages#4_Haskell_DB HaskellDB section of the same page].
| + | |
| - | | + | |
| - | === Other ===
| + | |
| - | * [http://www.vimeo.com/1983774 HaskellDB Talk Trailer]
| + | |
| - | * [http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=8F1C49953E49974D927950052C15CA41?doi=10.1.1.26.6906&rep=rep1&type=pdf Original HaskellDB paper]
| + | |
| - | | + | |
| - | == Future ==
| + | |
| - | | + | |
| - | [http://homepages.cwi.nl/~ralf/HList/ HList --- a Haskell library for strongly typed heterogeneous collections] includes also extensible records. Its relatedness to database programming is described in the articles, see also its [http://hackage.haskell.org/trac/summer-of-code/ticket/33 possible] relatedness to HaskellDB project.
| + | |
| - | | + | |
| - | To explore other declarative, type safe database managament approaches, see [[../CoddFish|CoddFish]]. Also it uses [http://homepages.cwi.nl/~ralf/HList/ HList].
| + | |
| - | | + | |
| - | == Related concepts ==
| + | |
| - | | + | |
| - | Concepts which are concerned by the papers of the two official HaskellDB homes
| + | |
| - | * [[Extensible record]]
| + | |
| - | * [[Phantom type]]
| + | |
| - | * [[Generalised algebraic datatype]]
| + | |
| - | * [[Relational algebra]]
| + | |