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

Implement Maybe related things for Esqueleto.Record #348

Closed
wants to merge 3 commits into from

Conversation

parsonsmatt
Copy link
Collaborator

This PR addresses #347 #344 and also #271 potentially

This is a bit of a tricky problem. We previously have two "places" to put a Maybe:

SqlExpr (Value (Maybe  a))
SqlExpr (Maybe (Entity a))

However, the esqueleto records pulls the SqlExpr inside of the record. Given a type:

data X = X { x :: Int }

-- we generate:
data SqlX = SqlX { x :: SqlExpr (Value Int) }

One approach is to create a new type.

data MaybeSqlX = MaybeSqlX { x :: SqlExpr (Value (Maybe Int)) }

The approach I take here is to use Maybe directly:

type MaybeSqlX = Maybe SqlX

The "approved" way of accessing into that is to use the HasField instance, which I define via TemplateHaskell for each field on SqlX:

instance HasField "x" (Maybe SqlX) (SqlExpr (Value (Maybe Int))) where
    ...

Except- wait, this doesn't make sense D:

The ToMaybe instance for records is Just, but that's no good. It means that a LEFT JOIN should give us something which we can case on. But this will be the Wrong Thing - we can't case on the SQL value itself.

So maybe need to rework this. But it's in a good enough state for now.


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).

@parsonsmatt parsonsmatt closed this Aug 7, 2023
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.

1 participant