Last active
December 18, 2015 13:09
-
-
Save xkikeg/5787948 to your computer and use it in GitHub Desktop.
Yesod Book :: Persistent :: One To One Relations
This file contains hidden or 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 QuasiQuotes, TypeFamilies, GeneralizedNewtypeDeriving, TemplateHaskell, | |
OverloadedStrings, GADTs, FlexibleContexts #-} | |
import Data.Conduit (runResourceT) | |
import Database.Persist | |
import Database.Persist.Sqlite | |
import Database.Persist.TH | |
import Control.Monad.IO.Class (liftIO) | |
import Control.Monad.Logger (runStderrLoggingT) | |
import Data.Time | |
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| | |
Person | |
name String | |
deriving Show | |
Car | |
ownerId PersonId Eq | |
name String | |
deriving Show | |
|] | |
main = runStderrLoggingT $ runResourceT $ withSqliteConn ":memory:" $ runSqlConn $ do | |
runMigration migrateAll | |
bruce <- insert $ Person "Bruce Wayne" | |
insert $ Car bruce "Bat Mobile" | |
insert $ Car bruce "Porsche" | |
-- this could go on a while | |
cars <- selectList [CarOwnerId ==. bruce] [] | |
liftIO $ print cars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment