yesod

Baffled by selectOneMany in Yesod

烈酒焚心 提交于 2019-12-02 03:35:43
问题 Sweet but simple, how do Persistent joins work? Consider the following model: Person number Int numberOfEyes Int firstName FirstnamesId lastName LastnamesId Lastnames lastname String Firstnames firstname String Assuming I only have the number of a Person, how do I retrieve his full name and the number of his eyes? I tried looking through the haskellers.org source but couldn't find any examples of joins. I also checked out the chapter on joins in the yesod book but it only made my eyes spin.

Yesod/Persistent one-to-one query

故事扮演 提交于 2019-12-01 22:42:58
Say, in Yesod/Persistent, I have models setup like so: User ident Text password Text Maybe UniqueUser ident Question title Text asker UserId Eq And I have a list of Question s, and would like to retrieve the corresponding list of User s. How would I go about doing this? I've thought about joins, but those are one-to-many, not one-to-one (I suppose it doesn't matter, but I'd like a simpler solution). Manually doing the join is also an option, but I'm worried about performance - I have questions <- runDB $ selectList [QuestionTitle !=. ""] [LimitTo 10] let askerIds = map (\(Entity _ q) ->

Yesod/Persistent one-to-one query

一世执手 提交于 2019-12-01 21:54:31
问题 Say, in Yesod/Persistent, I have models setup like so: User ident Text password Text Maybe UniqueUser ident Question title Text asker UserId Eq And I have a list of Question s, and would like to retrieve the corresponding list of User s. How would I go about doing this? I've thought about joins, but those are one-to-many, not one-to-one (I suppose it doesn't matter, but I'd like a simpler solution). Manually doing the join is also an option, but I'm worried about performance - I have

What's wrong with this YesodAuth instance?

社会主义新天地 提交于 2019-12-01 20:49:16
问题 I've just migrated from current yesod scaffold to latest yesod-1.6.0 , yesod-auth-1.6.2 . instance YesodAuth App where type AuthId App = UserId -- .... authenticate creds = runDB $ do x <- getBy $ UniqueUser $ credsIdent creds case x of Just (Entity uid _) -> return $ Authenticated uid Nothing -> return $ UserError InvalidUsernamePass Before migration this code worked well. But after the following error occurs. .../src/Foundation.hs:212:26: error: • Could not deduce: m ~ HandlerFor site8 from

YesodAuthEmail could not deduce m ~ HandlerFor site0 [duplicate]

时光怂恿深爱的人放手 提交于 2019-12-01 12:16:20
This question already has an answer here: What's wrong with this YesodAuth instance? 1 answer I'm trying to add instance YesodAuthEmail App to the Yesod-Postgres scaffolding (yesod version 1.6) and getting stuck on a compile error. The relevant code is: instance YesodAuth App where type AuthId App = UserId .... authPlugins :: App -> [AuthPlugin App] authPlugins app = [authOpenId Claimed []] ++ extraAuthPlugins where extraAuthPlugins = [ authEmail ] instance YesodAuthEmail App where type AuthEmailId App = UserId afterPasswordRoute _ = HomeR addUnverified email verkey = runDB $ insert $ User

Using UTCTime with Hamlet

时间秒杀一切 提交于 2019-12-01 07:34:43
I am using Yesod on my first site and I have a list of news items: NewsItem date UTCTime default=CURRENT_TIME title String content String author String which are retrieved in my handler: newsitems <- runDB $ selectList [] [Desc NewsItemDate] and ultimately used in my template: $if null newsitems <p>No news. $else $forall Entity id entry <- newsitems <article> <h4>#{newsItemDate entry} <p>#{newsItemContent entry} But I get an error about datatypes: Handler/Home.hs:20:11: No instance for (Text.Blaze.ToMarkup time-1.4:Data.Time.Clock.UTC.UTCTime) arising from a use of `toHtml' Possible fix: add

Codifying presence/absence of authentication at type level

人盡茶涼 提交于 2019-12-01 03:35:41
Context: I'm approaching Haskell from a standpoint of converting runtime errors to compile-time errors. My hypothesis is that this is possible if one can codify business logic within the program's types itself. I'm writing a Telegram bot, which should be accessible by users within my company. To achieve this "restriction", whenever someone starts chatting with the bot it will look up the chat_id in a table and check if a valid oauth_token exists. If not, the user will first be sent a link to complete a Google OAuth (our company's email is hosted on Google Apps for Business). share [mkPersist

Composing Database.Esqueleto queries, conditional joins and counting

余生长醉 提交于 2019-11-30 18:21:17
How can I compose Database.Esqueleto queries in a modular way such that after defining a "base" query and the corresponding result set, I can restrict the result set by adding additional inner joins and where expressions. Also, how can I convert the base query that returns a list of entities (or field tuples) into a query that counts the result set since the base query is not executed as such, but a modified version of it with LIMIT and OFFSET. The following incorrect Haskell code snippet adopted from the Yesod Book hopefully clarifies what I'm aiming at. {-# LANGUAGE QuasiQuotes,

Deploying Yesod web app

折月煮酒 提交于 2019-11-30 17:09:47
问题 I have a simple Yesod web app. I could follow the instruction in http://www.yesodweb.com/page/quickstart, and checked stack exec -- Yesod devel is working fine. The server that I use (Amazon EC2) has only one gigabyte of memory, so I can't compile the Yesod web. I used my local machine to build. Both of them use Ubuntu 14.04. From http://www.yesodweb.com/book/deploying-your-webapp, I need three components to deploy to other machine. Your executable. The config folder. The static folder. I

Composing Database.Esqueleto queries, conditional joins and counting

为君一笑 提交于 2019-11-30 16:50:18
问题 How can I compose Database.Esqueleto queries in a modular way such that after defining a "base" query and the corresponding result set, I can restrict the result set by adding additional inner joins and where expressions. Also, how can I convert the base query that returns a list of entities (or field tuples) into a query that counts the result set since the base query is not executed as such, but a modified version of it with LIMIT and OFFSET. The following incorrect Haskell code snippet