Created
January 31, 2012 11:47
-
-
Save portnov/1710072 to your computer and use it in GitHub Desktop.
Persistent issue #48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TemplateHaskell, QuasiQuotes, EmptyDataDecls, TypeFamilies, FlexibleContexts, GADTs, OverloadedStrings #-} | |
module Entities where | |
import Database.Persist | |
import Database.Persist.TH | |
import Data.Text | |
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persist| | |
Group | |
title Text | |
UniqueTitle title | |
|] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
import Control.Monad | |
import Control.Monad.Trans | |
import Database.Persist | |
import Database.Persist.Postgresql | |
import Entities | |
type DB a = SqlPersist IO a | |
check :: (Show v, PersistEntity v) => v -> DB (Key SqlPersist v) | |
check v = do | |
r <- insertBy v | |
case r of | |
Left e -> return (entityKey e) | |
Right k -> return k | |
group = Group "UNKNOWN" | |
main = do | |
withPostgresqlConn "port=5432dbname=this" $ runSqlConn $ do | |
r <- check group | |
liftIO $ print r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment