Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve doc about using esqueleto with Yesod #1

Open
meteficha opened this issue Sep 7, 2012 · 7 comments
Open

Improve doc about using esqueleto with Yesod #1

meteficha opened this issue Sep 7, 2012 · 7 comments
Labels

Comments

@meteficha
Copy link
Member

On Fri, Sep 7, 2012 at 7:42 AM, Arthur Clemens arthurclemens@gmail.com wrote:

This looks promising.

Trying out, I notice that I need to hide ==. from Yesod and
Database.Persist.Sqlite, so my imports become:

import Yesod hiding ((==.))
import Database.Persist.Sqlite (withSqliteConn, withSqlitePool)
import Database.Persist.TH

Yesod exports Yesod.Persist, which in turn exports Database.Persist, which in turns exports Database.Persist.Query, which conflicts with a lot of symbols from esqueleto.

Hmm... I guess I'll have to say on the docs that either you manually import Yesod modules, or you import esqueleto qualified.

@ghost
Copy link

ghost commented Jul 15, 2013

How TO HIDE PERSISTENT?

@rehno-lindeque
Copy link

Just FYI - what I've done for my project is to split off queries from handlers so that handler can just import Import (which includes import Yesod in the standard scaffold) without worrying about name clashes.

Then module Query.Foo will import only Database.Esqueleto and contain functions like e.g.

findAFromBWithCount :: TableBId -> SqlPersistT Handler [(Value TableAId, Value (Maybe Int))]
findAFromBWithCount = select $ from $ \(ta `InnerJoin` tb) -> -- etc...

The type signatures are unfortunately slightly awkward to maintain (and non-optional) but it helps prevent any overlap with persistent operators. (Perhaps helpers for unboxing Value would help?) I could also imagine there's a chance you might want to compose queries so that it's useful to have them separated out into modules.

meteficha pushed a commit that referenced this issue Sep 17, 2014
Bump upper bounds for base and text
@joefiorini
Copy link

@rehno-lindeque I tried that for myself but got an error finding "Handler". The only "Handler" I could find is Control.Exception. Is that what you use in your Query module?

@rehno-lindeque
Copy link

@joefiorini oh the Handler type is generated by Yesod, which I guess you're probably not using then.

These days I often just add all the type constraints the compiler tells me I need. E.g.

getFoo :: (PersistMonadBackend m ~ SqlBackend, MonadResource m, MonadSqlPersist m) 
       => m (Entity Foo)

The type signatures for esqueleto may have changed now with persistent 2 though and I haven't had a chance to upgrade yet.

You may find the ConstraintKind extension helpful: Have a look at the Persistent 2.1 upgrade guide in this blog post

@meteficha
Copy link
Member Author

BTW, since you guys revived this issue, what should be done about it, if anything? :)

@rehno-lindeque
Copy link

Some beginner-friendly documentation on how to write type signatures for standalone queries perhaps? I think the persistent upgrade doc did a reasonable job of it for persistent.

@bburdette
Copy link

I'm using this:

import Import hiding ((==.), (!=.), (||.))
import Database.Esqueleto;
import qualified Database.Persist as P

For some reason (^.) doesn't need to be hidden. I'm not sure about the other operators. If there's no more elegant way of hiding persistent, then maybe something like this should be in the docs, as some noob friendly boilerplate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants