yesod

How to perform database queries in GHCi in Yesod Application

十年热恋 提交于 2019-12-18 16:48:15
问题 How to, for example, insert a new User into a database using Yesod application's models? Or is there a better way? I am dealing with scaffolded application. Now I created App instance and dont know how to perform requests using it. :i Extra data Extra = Extra {extraCopyright :: Data.Text.Internal.Text, extraAnalytics :: Maybe Data.Text.Internal.Text} -- Defined in `Settings let e = Extra "asdf" Nothing let c = AppConfig {appEnv = Development, appPort = 3000, appRoot = "/", appHost =

How to perform database queries in GHCi in Yesod Application

守給你的承諾、 提交于 2019-12-18 16:48:14
问题 How to, for example, insert a new User into a database using Yesod application's models? Or is there a better way? I am dealing with scaffolded application. Now I created App instance and dont know how to perform requests using it. :i Extra data Extra = Extra {extraCopyright :: Data.Text.Internal.Text, extraAnalytics :: Maybe Data.Text.Internal.Text} -- Defined in `Settings let e = Extra "asdf" Nothing let c = AppConfig {appEnv = Development, appPort = 3000, appRoot = "/", appHost =

Deploying Yesod to Heroku, can't build statically

冷暖自知 提交于 2019-12-16 20:28:58
问题 I'm very new to Yesod and I'm having trouble building Yesod statically so I can deploy to Heroku. I have changed the default .cabal file to reflect static compilation if flag(production) cpp-options: -DPRODUCTION ghc-options: -Wall -threaded -O2 -static -optl-static else ghc-options: -Wall -threaded -O0 And it no longer builds. I get a whole bunch of warnings and then a slew of undefined references like this: Linking dist/build/personal-website/personal-website ... /usr/lib/ghc-7.0.3/libHSrts

“Yesod devel” fails with fromJust in devel.hs

人盡茶涼 提交于 2019-12-13 17:04:33
问题 When I run "yesod devel" it says "devel.hs: Maybe.fromJust: Nothing yesod init # created a project bbbb ... cabal install && yesod devel ... Registering bbbb-0.0.0... Starting development server... Starting devel application devel.hs: Maybe.fromJust: Nothing And the web server is not listening the port (I cannot open the site in my browser) Does anyone know how to fix this? My environment: yesod-0.9.4.1 The Glorious Glasgow Haskell Compilation System, version 7.0.3 Mac OS X 10.6.8 Here is

Migrating from Network.HTTP.Enumerator to Network.HTTP.Conduit

▼魔方 西西 提交于 2019-12-13 15:08:34
问题 I don't know why my code breaks. At first I thought it was because parseURL gives [] for the requestHeaders . Okay, so maybe I just need to tell it what the resquestHeaders should be. Well, I examined the requestHeaders generated from my old, working code. It too, returns a [] . So now I am out of ideas. Below is the old working code, followed my things I have been trying in GHCi with with new conduits based library. captureRawJson :: IO Response captureRawJson = do nManager <- newManager

Can Yesod's DB be configured with environment variables?

久未见 提交于 2019-12-13 02:58:37
问题 When I scaffold a new Yesod project and select e.g. PostgreSQL as the database, I get config/postgresql.yml that has the connection parameters. But I want to run my DB in one Docker container and the app in another, and link these via environment variables that contain the DB IP, port and whatnot. How can I tell Yesod to connect to a database by using a bunch of environment variables for configuration? 回答1: Yes, you can do this via the following environment variables: "PGHOST" "PGPORT"

Haskell Yesod - extracting a object inside a json before converting it to a model

[亡魂溺海] 提交于 2019-12-13 02:36:35
问题 Suppose I have a JSON like this: { data: {...} } and {...} represents a model of mine. How could get my model in this case in the Handler? For instance, the following will not work obviously: putMyEntityR :: Handler () putMyEntityR = do (Entity id _) <- (...) -- getting the Key e <- requireJsonBody :: Handler MyEntity runDB $ replace id e sendResponseStatus status204 ("UPDATED" :: Text) How can I read the JSON , take the data object, and only then decode it? 回答1: There was some more

How to generalize a list with different EntityField values

萝らか妹 提交于 2019-12-13 02:25:35
问题 I try to generalize the URL handling when going to for example /api/v1.0/events?order=-id,title for a RESTful output - so the results will order by id desc, and than by title asc Models file: -- models Event title Text content Text userId UserId deriving Eq deriving Show Haskell file: -- Events.hs text2Order :: Text -> [SelectOpt Event] text2Order text = case lookup textWithNoPrefix keyVal of Just val -> [direction val] Nothing -> error "wrong order" where keyVal = [ ("title", EventTitle) , (

Haskell Persistent out of sync

佐手、 提交于 2019-12-13 01:14:56
问题 I'm using Yesod and Persistent to make a blog (really original, eh?). At some point, I changed my model, and Persistent said that what I was trying to do is unsafe, and that I would have to do it manually. It said: Database migration: manual intervention required. The following actions are considered unsafe: ALTER TABLE "article" DROP COLUMN "date"; So I went ahead and ran that in Postgres. In fact, I have gone ahead and dropped the table "article", and I get the error: Migrating: CREATe

Point authRoute directly to google auth

天大地大妈咪最大 提交于 2019-12-12 16:24:48
问题 Since I'm only using google auth anyways, I would like to get rid of the login screen seeing as it's quite superfluous to have a page with just a google button on. What would be the way (if possible) to set the authRoute to point directly to google auth instead of pointing to the Just $ AuthR LoginR ? It didn't seem super simple since it involved some POST request, but I'm hoping I'm missing something obvious here. 回答1: You want to redirect to the forwardUrl for Google Email: Just $ AuthR