[Haskell-cafe] pure Haskell database
Marc Weber
marco-oweber at gmx.de
Wed Sep 24 18:03:10 EDT 2008
On Wed, Sep 24, 2008 at 11:17:01PM +0200, Manlio Perillo wrote:
> Hi.
>
> I need a simple, concurrent safe, database, written in Haskell.
> A database with the interface of Data.Map would be great, since what I need
> to to is atomically increment some integer values, and I would like to avoid
> to use SQLite.
I've tried writing at least part of that. But it's still higly
experimental and uses template haskell.
It looks like this:
from that some datastructures are defined which look like
tables used in traditional RDBMS such as SQLite..
However if you don't want to use many "tables" you may be a lot faster
writing down what you need yourself. My lib automacially generates code
for inserting / deleting tuples into multi indexes such as (Map Int (Map
Int PrimIdx)).
$(let cds = defaultTable {
tblName = "cds"
, columns = [ ("cdId", conT ''Int) , ("title", conT ''Int) ]
, primary = PrimaryUniq [ "cdId" ] [| 0 |]
, indexes = [ Index "title" [] ]
, tblStates = [ ( "nextCdId", [t| Int |], [| 0 |] ) ]
}
tracks = let
a="a"
-- updateNumRows n = [| \n -> cdUpdateByPK (\r -> r { num_tracks = (num_tracks r) + $(n) } ) |]
in defaultTable {
tblName = "tracks"
, columns = [ ("trackId", conT ''Int )
, ("name", conT ''String)
, ("cd", conT ''Int) -- foreign key
]
, primary = PrimaryUniq [ "cd", "trackId" ] [| 0 |]
, indexes = [ Index "cd" [ IndexUnique "trackId" ] ] --the id is uniq foreach cd
-- checks = [ foreignConstraint "cd" "cds" "id" ]
-- triggers = [ InsertUpdate (Just ["cd"]) [| cdUpdateByPK ( updateNum_tracks (+1) ) . pk |]
-- DeleteUpdate (Just ["cd"]) [| cdUpdateByPK ( updateNum_tracks (-1) ) . pk |]
-- ]
}
db = defaultDB {
dbName = "my"
, tables = [ cds, tracks]
, statistics = True
}
in createDB db)
If you're interested drop me a mail.
Marc
More information about the Haskell-Cafe
mailing list