Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Basic example of using HaskellDB to unmap records of a table
- CREATE TABLE books (
- id serial NOT NULL,
- title character varying NOT NULL,
- PRIMARY KEY (id)
- );
- data Book =
- { id :: Int
- , title :: String
- }
- {-# LANGUAGE TemplateHaskell #-}
- module Tables.Books (
- books
- , id
- , title
- , Books
- ) where
- import Database.HaskellDB.CodeGen
- import Prelude hiding (id)
- mkDBDirectTable "Books" [
- ("id", [t|Int|])
- , ("title", [t|String|])
- ]
- allBooks db = query db $ do
- books <- table B.books
- return books
- main :: IO ()
- main = do
- books <- postgresqlConnect [("host", "localhost"), ("user", "test"), ("password", "********")] allBooks
- mapM_ putStrLn (map (r -> r!B.title) books)
- return ()
- main :: IO ()
- main = do
- books <- postgresqlConnect [("host", "localhost"), ("user", "test"), ("password", "********")] allBooks
- mapM_ putStrLn (map (r -> r!B.title) books)
- return ()
Add Comment
Please, Sign In to add comment