Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate ToMaybe in deriveEsqueletoRecord #370

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

9999years
Copy link
Contributor

Before submitting your PR, check that you've:

After submitting your PR:

  • Update the Changelog.md file with a link to your PR.
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts).

@halogenandtoast
Copy link
Contributor

halogenandtoast commented Aug 24, 2023

I have a version that compiles and I believe generates the desired instance here:

master...halogenandtoast:esqueleto:goose/dux-1281-tomaybe-instance-for-deriveesqueletorecord

I wasn't sure if the scope was larger than this (are there other instances that are needed?)

I assume what else is left is:

-- * @x@ is transformed into @'SqlExpr' ('Value' ('Maybe' x))@.
-- * If there exists an instance @'SqlSelect' sql x@, then @x@ is transformed into @sql@.

@parsonsmatt
Copy link
Collaborator

Proper acceptance critieria is going to include a test where we can define a subquery that returns a SqlMyRecord and you can left join on it, and the result is a SqlMaybeMyRecord, and parsing/query execution works out fine

@halogenandtoast
Copy link
Contributor

halogenandtoast commented Aug 26, 2023

@parsonsmatt would this suffice for acceptance:

mySubselectRecordQuery :: SqlQuery (SqlExpr (Maybe (Entity Address)))
mySubselectRecordQuery = do
  _ :& record <-
    from $ table @User
        `leftJoin` myRecordQuery
        `on` (do \(user :& record) -> just (user ^. #id) ==. record.myUser ?. #id)
  pure $ record.myAddress
    itDb "can left join on records" $ do
        setup
        [record] <- fmap entityVal . catMaybes <$> select mySubselectRecordQuery
        liftIO $ record
          `shouldSatisfy`
          (\case Address { addressAddress = "30-50 Feral Hogs Rd" } -> True
                 _ -> False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants