You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(λ _ λ) edited this page Nov 17, 2016
·
3 revisions
[WARNING] Yesod Cookbook has moved to a new place. Please contribute there.
Example MySQL connection code:
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
importControl.Monad.IO.Class (liftIO)
importControl.Monad.Logger (runStderrLoggingT)
importDatabase.PersistimportDatabase.Persist.MySQLimportDatabase.Persist.TH
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Person
name String
age Int Maybe
address Int
deriving Show
BlogPost
title String
authorId PersonId
deriving Show
|]
connectionInfo = defaultConnectInfo { connectPort =5000,
connectPassword ="password",
connectDatabase ="database"}
main::IO()
main = runStderrLoggingT $ withMySQLPool connectionInfo 10$\pool -> liftIO $doflip runSqlPersistMPool pool $do
printMigration migrateAll
runMigration migrateAll