On 18:12 Sat 09 Jul , Tom Murphy wrote: > Hi, > I've found good explanations of the HaskellDB combinators, but I > can't find good information about how to correctly define the database > layout. Can anyone point me to a resource, or give a quick example? > > Thanks! > Tom > > _______________________________________________ > Haskell-Cafe mailing list > [email protected] > http://www.haskell.org/mailman/listinfo/haskell-cafe
I don't have any examples at hand, but I'll look through the api with
you.
There are three ways to create the dblayout interface, manually, through
dbinfo or through template haskell.
The vanilla way is to use the DBInfo(3) module to describe your database
layout. It can also be used to create the database schema, but as the
dbinfo language is very restricted, I don't recommend it.
DBInfo {
dbName "DatabaseName"
opts = DBOptions {
useBString = False
, makeIdent = mkIdentPreserving }
tbls = [TInfo {tname = "tablename"
cols = [CInfo {cname = "columnname",
descr = (IntT, False)}]
}
]
}
This would create a layout describing a database called DatabaseName
with one table "tablename" with one column "columnname" which is of type
int and can't be null. The mkIdentPreserving is an undocumented function
in (5)
The description then needs to be created into module files with
dbInfoToModuleFiles(4). This creates a root "DatabaseName.hs" file and
DatabaseName directory. The root file is uncompilable and can be safely
removed.
The fact that there is two stages for the compilation, makes it
difficult to compile. I believe this restriction is because haskelldb
was created when there was no template haskell. With template haskell
(2) you could do the following:
$(mkDbDirectTable "tablename" [("columnname", [t|Int|])]
I don't know how to specify whether the field can be null or not, but at
least this way you get your dblayout descriptions at compile time.
[1] http://hackage.haskell.org/package/haskelldb
[2] http://hackage.haskell.org/package/haskelldb-th
[3]
http://hackage.haskell.org/packages/archive/haskelldb/2.1.1/doc/html/Database-HaskellDB-DBSpec-DBInfo.html
[4]
http://hackage.haskell.org/packages/archive/haskelldb/2.1.1/doc/html/Database-HaskellDB-DBSpec-DBSpecToDBDirect.html
[5]
http://hackage.haskell.org/packages/archive/haskelldb/2.1.1/doc/html/src/Database-HaskellDB-DBSpec-PPHelpers.html
--
Mats Rauhala
MasseR
pgp4JOTyhvDIn.pgp
Description: PGP signature
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
