Skip to content

Instantly share code, notes, and snippets.

@cschneid
Last active August 29, 2015 14:19
Show Gist options
  • Save cschneid/7bd2d407e0fbe8d44417 to your computer and use it in GitHub Desktop.
Save cschneid/7bd2d407e0fbe8d44417 to your computer and use it in GitHub Desktop.
module Grocery.Database.Calendar where
import Grocery.DatabaseSchema
import Grocery.Types.Meal
import Database.Persist
import Database.Persist.Sqlite
import qualified Database.Esqueleto as E
import Database.Esqueleto ((^.))
import Data.Time
import Data.Text
import Control.Monad.Trans -- for MonadIO
import Control.Monad.Trans.Reader
getAllMeals :: (MonadIO m) => SqlPersistT m [DbMeal]
getAllMeals = do
r <- E.select $
E.from $ \(dbmeal) -> do
return dbmeal
mapM (entityVal) r
-- src/shared/Grocery/Database/Calendar.hs:26:9:
-- Couldn't match type ‘PersistEntityBackend
-- (ReaderT SqlBackend m DbMeal)’
-- with ‘SqlBackend’
-- Relevant bindings include
-- getAllMeals :: SqlPersistT m [DbMeal]
-- (bound at src/shared/Grocery/Database/Calendar.hs:24:1)
-- In the expression: E.from
-- In the second argument of ‘($)’, namely
-- ‘E.from $ \ (dbmeal) -> do { return dbmeal }’
-- In a stmt of a 'do' block:
-- r <- E.select $ E.from $ \ (dbmeal) -> do { return dbmeal }
--
share [mkPersist sqlSettings { mpsPrefixFields = False }, mkMigrate "migrateAll" ] [persistLowerCase|
DbUser sql=user
dbUserEmail T.Text
dbUserPasswordHash BS.ByteString
dbUserCreatedAt UTCTime
deriving Show
deriving Eq
deriving Generic
DbMeal sql=meal
dbMealUserId DbUserId
dbMealDay UTCTime
dbMealName T.Text
dbMealCreatedAt UTCTime Maybe default=CURRENT_TIME
deriving Show
deriving Eq
deriving Generic
DbRecipe sql=recipe
dbRecipeName T.Text
deriving Show
deriving Eq
deriving Generic
DbFood sql=food
dbFoodName T.Text
deriving Show
deriving Eq
deriving Generic
|]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment