jakubfijalkowski / codinginfinity.me

Source code of http://codinginfinity.me
1 stars 0 forks source link

Custom SQL queries in Groundhog - Coding Infinity #4

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

Custom SQL queries in Groundhog - Coding Infinity

Coding Infinity - At infinity, nothing is impossible - just like in code

https://www.codinginfinity.me/posts/custom-sql-queries-in-groundhog/

jakubfijalkowski commented 4 years ago

Originally posted by @lykahb on Disqus on 2015-09-11:

I am glad you find Groundhog useful. There is a simpler way to decode the entities. Perhaps I should have made it more obvious in the documentation.

decode = liftM fst . projectionResult (PostConstructor, CategoryConstructor, AuthorConstructor)
psa <- queryRaw True "select ..." [PersistInt64 i] $ mapAllRows decode

The projection can be even more complex! For example, you could include another field or a not mapped value in there. There are instances for tuples of limited size so if you need more, you can nest the tuples.

(PostConstructor, CategoryConstructor, AuthorConstructor, PostTitleField, undefined :: Expr db r Int, )
jakubfijalkowski commented 4 years ago

Originally posted by @jakubfijalkowski on Disqus on 2015-09-12:

Ah, I knew that I've been reinventing the wheel. Good to know that this is available OOTB.