Created
March 21, 2012 14:50
-
-
Save MgaMPKAy/2147821 to your computer and use it in GitHub Desktop.
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 TemplateHaskell, QuasiQuotes #-} | |
{-# LANGUAGE TypeFamilies, GADTs, MultiParamTypeClasses #-} | |
{-# LANGUAGE OverloadedStrings, FlexibleContexts #-} | |
{-# LANGUAGE EmptyDataDecls #-} | |
import Database.Persist | |
import Database.Persist.TH | |
import Database.Persist.Sqlite | |
import Data.Text | |
import Control.Monad.IO.Class | |
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persist| | |
Student | |
sid Int | |
name Text | |
UniqueSID sid | |
Teacher | |
tid Int | |
name Text | |
UniqueTID tid | |
Lesson | |
name Text | |
teacher TeacherId | |
totalAvalible Int | |
selected Int DEC INC | |
StudentLesson | |
sid StudentId | |
lid LessonId | |
UniqueST sid lid | |
|] | |
main = withSqliteConn ":memory:" $ runSqlConn $ do | |
runMigration migrateAll | |
r <- newTeacher 1 "Mike" | |
case r of | |
Left _ -> liftIO $ print "Error~" | |
Right key -> liftIO $ print key | |
newLesson lid name tid total = | |
insertBy $ Lesson lid name tid total | |
newTeacher tid name = do | |
insertBy $ Teacher tid name | |
newStudent sid name = do | |
insertBy $ Student sid name | |
getLesson lid = selectList [LessonId ==. lid] [] | |
getTeacher tid = selectList [TeacherId ==. tid] [] | |
getStudent sid = selectList [StudentId ==. sid] [] | |
choice tid lid = do | |
selectFirst [StudentLessonLid ==. lid] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment