composite
composite copied to clipboard
how to do left joins properly?
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.
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
maybe try rmap toNullable
?