composite icon indicating copy to clipboard operation
composite copied to clipboard

how to do left joins properly?

Open martyall opened this issue 6 years ago • 2 comments

I feel like it should be possible to do something like the following:


type DBUserCols = '[CUserId, CUsername]

userTable :: Table (Record DBUserCols) (Record DBUserCols)
userTable = Table "user" defaultRecTable

type DBAddressCols = '[CUserId, CCity, CStreet]
type DBMaybeAddressCols = '[Nullable CUserId, Nullable CCity, Nullable CStreet]

addressTable :: Table (Record DBUserCols) (Record DBUserCols)
addressTable = Table "user" defaultRecTable
 
usersWithAddressQ :: Query (Record DBUserCols, DBMaybeUserAddress)
usersWithAddressQ =
  let joiner l r = (l , allToNullable r)
       joinerL = (l, null)
       matcher l r  = l ^. cUserId .== r ^. cUserId
  in leftJoinF joiner joinerL matcher (queryTable userTable) (queryTable addressTable)

Is this already possible and I just haven't done it correctly? I don't see anything like the allToNullable above.

martyall avatar Aug 14 '18 22:08 martyall

hey, sorry for the long delay in responding. allToNullable doesn't exist, but it's probably not too hard to add. feel free to PR it. we've only used leftJoinF for pulling specific columns and just used toNullable from opaleye to construct individual values into a one-off record

Dridus avatar Oct 13 '18 02:10 Dridus

maybe try rmap toNullable?

Dridus avatar Oct 13 '18 02:10 Dridus