haskellyesodhspechaskell-persistent

How does "import Database.Persist as X hiding (get)" from the yesod-sqlite template works


I am using the yesod-sqlite template and trying to use the get function from Database.Persist in a test.

Here is my code:

[Entity _ task] <- runDB $ selectList [TaskName ==. name] []
...
user <- runDB $ X.get (taskUserId task)

And the error I am getting:

my_project/test/Handler/TaskSpec.hs:47:29: error:
Not in scope: ‘X.get’
No module named ‘X’ is imported.

In the TestImport.hs file, I saw this line:

import Database.Persist      as X hiding (get)

To my understanding it should be hidding the get function from the HSpec module, so I could use X.get for database retrieving. I also tried with Database.Persist.get and just get with the same result.

So my doubt is: what that line in TestImport.hs is doing?


Solution

  • The import line is importing everything in the Database.Persist module except get, optionally qualified.

    If I'm understanding correctly and you want to import only get qualified, and everything else unqualified, you could use:

    import Database.Persist hiding (get)
    import qualified Database.Persist as X (get)