{"action":"created","issue":{"url":"https://api.github.com/repos/gbwey/persistent-odbc/issues/13","repository_url":"https://api.github.com/repos/gbwey/persistent-odbc","labels_url":"https://api.github.com/repos/gbwey/persistent-odbc/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/gbwey/persistent-odbc/issues/13/comments","events_url":"https://api.github.com/repos/gbwey/persistent-odbc/issues/13/events","html_url":"https://github.com/gbwey/persistent-odbc/issues/13","id":134682943,"number":13,"title":"Yesod","user":{"login":"felipexpert","id":8162660,"avatar_url":"https://avatars.githubusercontent.com/u/8162660?v=3","gravatar_id":"","url":"https://api.github.com/users/felipexpert","html_url":"https://github.com/felipexpert","followers_url":"https://api.github.com/users/felipexpert/followers","following_url":"https://api.github.com/users/felipexpert/following{/other_user}","gists_url":"https://api.github.com/users/felipexpert/gists{/gist_id}","starred_url":"https://api.github.com/users/felipexpert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felipexpert/subscriptions","organizations_url":"https://api.github.com/users/felipexpert/orgs","repos_url":"https://api.github.com/users/felipexpert/repos","events_url":"https://api.github.com/users/felipexpert/events{/privacy}","received_events_url":"https://api.github.com/users/felipexpert/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-02-18T20:13:16Z","updated_at":"2016-02-19T12:15:50Z","closed_at":null,"body":"How can I easily use it with yesod through stack? (By the way, thank you so much for this repo, it was the only way I've found to use Persistent+Mysql+Windows)"},"comment":{"url":"https://api.github.com/repos/gbwey/persistent-odbc/issues/comments/186193285","html_url":"https://github.com/gbwey/persistent-odbc/issues/13#issuecomment-186193285","issue_url":"https://api.github.com/repos/gbwey/persistent-odbc/issues/13","id":186193285,"user":{"login":"felipexpert","id":8162660,"avatar_url":"https://avatars.githubusercontent.com/u/8162660?v=3","gravatar_id":"","url":"https://api.github.com/users/felipexpert","html_url":"https://github.com/felipexpert","followers_url":"https://api.github.com/users/felipexpert/followers","following_url":"https://api.github.com/users/felipexpert/following{/other_user}","gists_url":"https://api.github.com/users/felipexpert/gists{/gist_id}","starred_url":"https://api.github.com/users/felipexpert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felipexpert/subscriptions","organizations_url":"https://api.github.com/users/felipexpert/orgs","repos_url":"https://api.github.com/users/felipexpert/repos","events_url":"https://api.github.com/users/felipexpert/events{/privacy}","received_events_url":"https://api.github.com/users/felipexpert/received_events","type":"User","site_admin":false},"created_at":"2016-02-19T12:15:50Z","updated_at":"2016-02-19T12:15:50Z","body":"{-# LANGUAGE EmptyDataDecls             #-}\r\n{-# LANGUAGE FlexibleContexts           #-}\r\n{-# LANGUAGE GADTs                      #-}\r\n{-# LANGUAGE GeneralizedNewtypeDeriving #-}\r\n{-# LANGUAGE MultiParamTypeClasses      #-}\r\n{-# LANGUAGE OverloadedStrings          #-}\r\n{-# LANGUAGE QuasiQuotes                #-}\r\n{-# LANGUAGE TemplateHaskell            #-}\r\n{-# LANGUAGE TypeFamilies               #-}\r\n{-# LANGUAGE ViewPatterns               #-}\r\nimport           Control.Monad.Logger\r\nimport           Data.Text               (Text)\r\nimport qualified Database.Esqueleto      as E\r\nimport           Database.Esqueleto      ((^.))\r\nimport           Database.Persist.ODBC\r\nimport           Yesod\r\nimport qualified Data.Conduit.List as CL\r\nimport Data.Conduit (($=))\r\n\r\nshare [mkPersist sqlSettings, mkMigrate \"migrateAll\"] [persistLowerCase|\r\nAuthor\r\n    name Text\r\nBlog\r\n    author AuthorId\r\n    title Text\r\n    content Html\r\n|]\r\n\r\ndata App = App\r\n    { persistConfig :: OdbcConf\r\n    , connPool      :: ConnectionPool\r\n    }\r\ninstance Yesod App\r\ninstance YesodPersist App where\r\n    type YesodPersistBackend App = SqlBackend\r\n    runDB = defaultRunDB persistConfig connPool\r\ninstance YesodPersistRunner App where\r\n    getDBRunner = defaultGetDBRunner connPool\r\n\r\nmkYesod \"App\" [parseRoutes|\r\n/ HomeR GET\r\n/blog/#BlogId BlogR GET\r\n|]\r\n\r\ngetHomeR :: Handler TypedContent\r\ngetHomeR = do\r\n    let blogsSrc =\r\n             E.selectSource\r\n           $ E.from $ \\(blog `E.InnerJoin` author) -> do\r\n                E.on $ blog ^. BlogAuthor E.==. author ^. AuthorId\r\n                return\r\n                    ( blog   ^. BlogId\r\n                    , blog   ^. BlogTitle\r\n                    , author ^. AuthorName\r\n                    )\r\n\r\n    render <- getUrlRenderParams\r\n    respondSourceDB typeHtml $ do\r\n        sendChunkText \"<html><head><title>Blog posts</title></head><body><ul>\"\r\n        blogsSrc $= CL.map (\\(E.Value blogid, E.Value title, E.Value name) ->\r\n            toFlushBuilder $\r\n            [hamlet|\r\n                <li>\r\n                    <a href=@{BlogR blogid}>#{title} by #{name}\r\n            |] render\r\n            )\r\n        sendChunkText \"</ul></body></html>\"\r\n\r\ngetBlogR :: BlogId -> Handler Html\r\ngetBlogR _ = error \"Implementation left as exercise to reader\"\r\n\r\nmain :: IO ()\r\nmain = do\r\n    -- Is this configuration right?\r\n    let conf = OdbcConf \"DNS=mysql_test;\" 1 \"MySQL\"\r\n    pool <- createPoolConfig conf\r\n    flip runSqlPersistMPool pool $ do\r\n        runMigration migrateAll\r\n\r\n        -- Fill in some testing data\r\n        alice <- insert $ Author \"Alice\"\r\n        bob   <- insert $ Author \"Bob\"\r\n\r\n        insert_ $ Blog alice \"Alice's first post\" \"Hello World!\"\r\n        insert_ $ Blog bob \"Bob's first post\" \"Hello World!!!\"\r\n        insert_ $ Blog alice \"Alice's second post\" \"Goodbye World!\"\r\n\r\n    warp 3000 App\r\n        { persistConfig = conf\r\n        , connPool      = pool\r\n        }"}}