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

Add mysql json field support #1333

Merged
merged 3 commits into from
Jan 27, 2022

Conversation

belevy
Copy link
Contributor

@belevy belevy commented Nov 1, 2021

Now that mysql-simple and mysql have been updated to properly handle JSON values coming out of a mysql db (supported since mysql 5.7.8) this PR adds support to the MySQL backend to read these values. It does not add a PersistField instance for Value's. It is probably not great that Postgres has an orphan instance for Value. Would rather there be a Json newtype and JsonB newtype.

Before submitting your PR, check that you've:

  • Documented new APIs with Haddock markup
  • Added @since declarations to the Haddock
  • Ran stylish-haskell on any changed files.
  • Adhered to the code style (see the .editorconfig file for details)

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Bumped the version number if there isn't an (unreleased) on the Changelog
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

Copy link
Collaborator

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome thanks!

this is a bugfix patch for persistent-mysql, so I can get this out tonight.

I agree that the orphan instance PersistValue Value in persistent-postgresql isn't great. Would be better to have a newtype for precisely that reason.

it "can select json with rawsql" $ db $ do
let testJSON = toJSON $ [object [ "test" .= ("value" :: Text) ]]
[[PersistByteString value]] <- runConduit $ rawQuery "select JSON_ARRAY(JSON_OBJECT('test', 'value'))" [] .| CL.consume
liftIO $ Just testJSON `shouldBe` (decode $ BSL.fromStrict value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hell yeah

@parsonsmatt parsonsmatt merged commit 614aea3 into yesodweb:master Jan 27, 2022
@belevy belevy deleted the add-mysql-json-field-support branch January 31, 2022 03:51
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.

2 participants