prowdsponsor / esqueleto

Bare bones, type-safe EDSL for SQL queries on persistent backends.
http://hackage.haskell.org/package/esqueleto
BSD 3-Clause "New" or "Revised" License
177 stars 51 forks source link

`toBaseId` for Maybes #132

Open jkarni opened 8 years ago

jkarni commented 8 years ago

toBaseId is great, but doesn't really work on e.g. a left inner join, since there's no way of pushing the Maybe in. It's easy enough to define:

toBaseIdM :: ToBaseId ent => expr (Value (Maybe (Key ent))) -> expr (Value (Maybe (Key (BaseEnt ent))))

For expr ~ SqlExpr (it's the same implementation as toBaseId),. Should I submit a PR for it? It seems a little ugly to have two altogether separate class methods for this...

meteficha commented 8 years ago

I'm not sure what's best as well. What's your opinion, @pseudonom?

pseudonom commented 8 years ago

I haven't actually investigated if this is possible/non-enormous, but would it make sense to make a version of when_/case_ that knew about NULL and Maybe? So that an expr (Value (Maybe typ)) becomes an expr (Value typ) in the appropriate branch?