Git Product home page Git Product logo

Comments (7)

 avatar commented on September 7, 2024

How TO HIDE PERSISTENT?

from esqueleto.

rehno-lindeque avatar rehno-lindeque commented on September 7, 2024

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.

from esqueleto.

joefiorini avatar joefiorini commented on September 7, 2024

@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?

from esqueleto.

rehno-lindeque avatar rehno-lindeque commented on September 7, 2024

@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

from esqueleto.

meteficha avatar meteficha commented on September 7, 2024

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

from esqueleto.

rehno-lindeque avatar rehno-lindeque commented on September 7, 2024

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.

from esqueleto.

bburdette avatar bburdette commented on September 7, 2024

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.

from esqueleto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.