Comments (7)
How TO HIDE PERSISTENT?
from esqueleto.
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.
@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.
@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.
BTW, since you guys revived this issue, what should be done about it, if anything? :)
from esqueleto.
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.
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)
- info: helper functions and common queries HOT 2
- Ripping the name-clashes bandaid off HOT 4
- `in_` and `notIn` on multiple columns HOT 1
- `toBaseId` for Maybes HOT 2
- Trouble with inner select with limit
- Support for persistent 2.5 HOT 11
- Add "row_number" function
- mixing up order of orderBy clause passes typechecking, produces bad sql
- Convert joins into nested tuples HOT 10
- Right place to ask questions?
- use deleteCascade/deleteCascadeWhere with esqueleto?
- sum_ and friends can cause runtime type errors
- inner join with derived table
- Is it possible to treat a primary key as an Int64? HOT 1
- Adding `OVER()` to a `SELECT` clause
- countRows does not work with distinct HOT 1
- Not working with newer versions (>2.8) of persistent HOT 1
- Put a message pointing to this lib's new home in the README
- Expose SqlSelect so it can be used in type signatures HOT 1
- `valkey` not working: `No instance for (ToBackendKey SqlBackend Product)` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esqueleto.