Skip to content

More BackendCompatible generalizations #723

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

Merged
merged 5 commits into from
Nov 4, 2017

Conversation

parsonsmatt
Copy link
Collaborator

This PR includes some additional generalizations. Unfortunately, my work project does not use the SqlReadT or SqlWriteT features, and it was only when the code was tested on those did the issues with Esqueleto come up.

This PR generalizes SqlReadT so that Esqueleto can be updated in a way that doesn't cause any breaking changes.

If any folks are using SqlReadT, I'd appreciate testing this PR/commit out with this Esqueleto PR to verify that it doesn't break any corner cases I've missed 😄

@@ -47,20 +47,20 @@ rawQueryRes sql vals = do
stmtQuery stmt vals

-- | Execute a raw SQL statement
rawExecute :: MonadIO m
rawExecute :: (MonadIO m, BackendCompatible SqlBackend backend)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These functions needed to be generalized to satisfy Esqueleto.

@@ -27,6 +27,7 @@ import Control.Monad.Trans.Control (liftBaseOp_)
import Database.Persist.Sql.Types
import Database.Persist.Sql.Raw
import Database.Persist.Types
import Database.Persist.Sql.Orphan.PersistStore()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This import is necessary for the BackendCompatible SqlBackend SqlBackend instance.

@dariooddenino
Copy link

Compilation of persistent-mysql-2.6.2 fails with this branch. persistent-mysql-2.6.1 works fine.

Progress: 2/3
--  While building package persistent-mysql-2.6.2 using:
      /home/dario/.stack/setup-exe-cache/x86_64-linux-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-nopie/Cabal-1.24.2.0 build --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: /home/dario/dev/blue-moon/.stack-work/logs/persistent-mysql-2.6.2.log

    Configuring persistent-mysql-2.6.2...
    Building persistent-mysql-2.6.2...
    Preprocessing library persistent-mysql-2.6.2...
    [1 of 1] Compiling Database.Persist.MySQL ( Database/Persist/MySQL.hs, .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.2.0/build/Database/Persist/MySQL.o )
    
    /tmp/stack4584/persistent-mysql-2.6.2/Database/Persist/MySQL.hs:1188:17: error:
        • Could not deduce (BackendCompatible r0 backend)
            arising from a use of ‘projectBackend’
          from the context: (backend ~ PersistEntityBackend record,
                             BackendCompatible SqlBackend backend,
                             PersistEntity record,
                             MonadIO m)
            bound by the type signature for:
                       insertManyOnDuplicateKeyUpdate :: (backend
                                                          ~
                                                          PersistEntityBackend record,
                                                          BackendCompatible SqlBackend backend,
                                                          PersistEntity record, MonadIO m) =>
                                                         [record]
                                                         -> [SomeField record]
                                                         -> [Update record]
                                                         -> ReaderT backend m ()
            at Database/Persist/MySQL.hs:(1175,1)-(1185,27)
          The type variable ‘r0’ is ambiguous
          Relevant bindings include
            insertManyOnDuplicateKeyUpdate :: [record]
                                              -> [SomeField record]
                                              -> [Update record]
                                              -> ReaderT backend m ()
              (bound at Database/Persist/MySQL.hs:1186:1)
          These potential instances exist:
            instance BackendCompatible SqlBackend SqlBackend
              -- Defined in ‘persistent-2.7.1:Database.Persist.Sql.Orphan.PersistStore’
            instance BackendCompatible SqlBackend SqlReadBackend
              -- Defined in ‘persistent-2.7.1:Database.Persist.Sql.Orphan.PersistStore’
            instance BackendCompatible SqlBackend SqlWriteBackend
              -- Defined in ‘persistent-2.7.1:Database.Persist.Sql.Orphan.PersistStore’
        • In the first argument of ‘withReaderT’, namely ‘projectBackend’
          In the first argument of ‘(.)’, namely ‘withReaderT projectBackend’
          In the expression: withReaderT projectBackend . uncurry rawExecute
    
    /tmp/stack4584/persistent-mysql-2.6.2/Database/Persist/MySQL.hs:1189:15: error:
        • Could not deduce (BackendCompatible SqlBackend r0)
            arising from a use of ‘rawExecute’
          from the context: (backend ~ PersistEntityBackend record,
                             BackendCompatible SqlBackend backend,
                             PersistEntity record,
                             MonadIO m)
            bound by the type signature for:
                       insertManyOnDuplicateKeyUpdate :: (backend
                                                          ~
                                                          PersistEntityBackend record,
                                                          BackendCompatible SqlBackend backend,
                                                          PersistEntity record, MonadIO m) =>
                                                         [record]
                                                         -> [SomeField record]
                                                         -> [Update record]
                                                         -> ReaderT backend m ()
            at Database/Persist/MySQL.hs:(1175,1)-(1185,27)
          The type variable ‘r0’ is ambiguous
          These potential instances exist:
            instance BackendCompatible SqlBackend SqlBackend
              -- Defined in ‘persistent-2.7.1:Database.Persist.Sql.Orphan.PersistStore’
            instance BackendCompatible SqlBackend SqlReadBackend
              -- Defined in ‘persistent-2.7.1:Database.Persist.Sql.Orphan.PersistStore’
            instance BackendCompatible SqlBackend SqlWriteBackend
              -- Defined in ‘persistent-2.7.1:Database.Persist.Sql.Orphan.PersistStore’
        • In the first argument of ‘uncurry’, namely ‘rawExecute’
          In the second argument of ‘(.)’, namely ‘uncurry rawExecute’
          In the expression: withReaderT projectBackend . uncurry rawExecute

@parsonsmatt
Copy link
Collaborator Author

Good catch @dariooddenino The generalizations I'm making here make the preemptive persistent-mysql generalizations unnecessary :)

@paul-rouse
Copy link
Contributor

@parsonsmatt This is looking good! Could you please rebase to the latest master, and make the changelog message describe the whole PR (include a link to the PR too) instead of saying it fixes a compilation error (which was just an intermediate step!)? Then, assuming travis is still OK, I can merge it.

@parsonsmatt parsonsmatt force-pushed the matt/generalize-sqlreadt branch from 150c89b to f7afdea Compare November 3, 2017 21:18
@parsonsmatt
Copy link
Collaborator Author

Weird spurious build failure: https://travis-ci.org/yesodweb/persistent/jobs/296983378 Tests passed and all :\

@paul-rouse
Copy link
Contributor

Looked like a last-minute glitch. I restarted that test and it is fine now.

Thanks for all of this - I'll go ahead and merge it.

@paul-rouse paul-rouse merged commit 7c00533 into yesodweb:master Nov 4, 2017
MaxGabriel added a commit that referenced this pull request Dec 17, 2017
MaxGabriel added a commit that referenced this pull request Dec 17, 2017
MaxGabriel added a commit that referenced this pull request Dec 19, 2017
Revert "More BackendCompatible generalizations (#723)"
snoyberg added a commit that referenced this pull request Jan 16, 2018
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