esqueleto

Running join on Maybe Relation

浪尽此生 提交于 2019-12-24 12:27:00
问题 I have a model Assignment blah Text .... and a model File assignmentId AssignmentId Maybe ... and I want to get all the files associated with an assignment in a join query. I have tried Esqueleto and runJoin with selectOneMany but haven't had any luck, so I am considering not using a join, or using rawSql. That really doesn't seem like a good idea, but I can't figure this out. Is there any support for that feature? 回答1: Update, working example: {-# LANGUAGE PackageImports, OverloadedStrings,

Haskell Esqueleto project to list of records instead of tuples

家住魔仙堡 提交于 2019-12-24 07:05:20
问题 In all the examples I have seen the results from esqueleto are projected into a list of tuples. This makes coding and maintenance harder because of lack of labels. For example: previousLogItems <- select $ from $ \li -> do orderBy [desc (li ^. LogItemId)] limit 10 return (li ^. LogItemId, li ^. LogItemTitle) Is there any way to get esqueleto to project the results to a list of records instead? 回答1: In fact you construct the tuple yourself. Indeed: previousLogItems <- select $ from $ \li -> do

Outer Joins with Esqueleto

╄→尐↘猪︶ㄣ 提交于 2019-12-10 22:00:35
问题 I am a bit confused about how outer joins work with esqueleto. I have created the following query (simplified): select $ from $ \(rep `LeftOuterJoin` event) -> do on (rep ^. RepAtomId ==. event ^. EventAtomId ) where_ (rep ^. RepAtomId ==. val aid) return $ (rep, event ^. EventSeconds) As far as I know, on the SQL-side, this query will search for reps that may have an associated event. If they do not have an associated event, the event fields (like EventSeconds) will be "null". On the Haskell

Haskell Esqueleto project subset of columns to list of custom records

和自甴很熟 提交于 2019-12-06 08:59:32
问题 In all the examples I have seen the results from esqueleto are projected into a list of tuples or to entities records. For example: previousLogItems <- select $ from $ \li -> do orderBy [desc (li ^. LogItemId)] limit 10 return (li ^. LogItemId, li ^. LogItemTitle) Is there any way in esqueleto to project a subset of the columns to custom records (different than the entity) instead of tuples? This being done without an extra projection from tuples to custom records. As an example, let's say

How can I get esqueleto to generate an SQL string for me?

亡梦爱人 提交于 2019-12-03 06:26:02
问题 How can I get esqueleto to generate an SQL string from a from statement? The documentation of toRawSql says that "you may just turn on query logging of persistent". I tried all possible forms of MonadLogger that I could understand, but it never printed any SQL. The same documentation also says "manually using this function ... is possible but tedious". However, no constructors of the type, nor any functions returning values of the type, QueryType are exported. I managed to get around this by

How can I get esqueleto to generate an SQL string for me?

懵懂的女人 提交于 2019-12-02 19:52:54
How can I get esqueleto to generate an SQL string from a from statement? The documentation of toRawSql says that "you may just turn on query logging of persistent". I tried all possible forms of MonadLogger that I could understand, but it never printed any SQL. The same documentation also says "manually using this function ... is possible but tedious". However, no constructors of the type, nor any functions returning values of the type, QueryType are exported. I managed to get around this by noticing that QueryType is a newtype and using unsafeCoerce ! I was also forced to provide a Connection