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

valkey not working: No instance for (ToBackendKey SqlBackend Product) #161

Open
MuhammedZakir opened this issue May 13, 2022 · 2 comments
Open

Comments

@MuhammedZakir
Copy link

Schema:

share [ mkPersist sqlSettings
      , mkMigrate "migrateAll" ] [persistUpperCase|
Product
  Id    Int
  name  Text
  deriving Eq Show
]

Helper functions:

dbName = "/tmp/esqueleto.db"

connectionPool = do
  conInfo <- walEnabled (const $ pure False) $ mkSqliteConnectionInfo dbName
  runStdoutLoggingT $ createSqlitePoolFromInfo conInfo 1

pool = connectionPool

q q = pool >>= \p -> runSqlPool q p

For above schema, running this in ghci

q $ select $ (from $ table @Product) >>= \ps -> where_ (ps ^. ProductId ==. valkey 1) >> pure ps

throws

• No instance for (ToBackendKey SqlBackend Product)
        arising from a use of ‘valkey’

<context info>

This works:

q $ select $ (from $ table @Product) >>= \ps -> where_ (ps ^. ProductId ==. (val $ ProductKey 1)) >> pure ps
@MuhammedZakir
Copy link
Author

Is ProductId treated differently? This works:

import Database.Persist as DP ( (==.) )

q $ deleteWhere [ProductName DP.==. "some name"]

This doesn't:

q $ deleteWhere [ProductId DP.==. 1]

throws

• No instance for (Num ProductId) arising from the literal ‘15’
• In the second argument of ‘(DP.>=.)’, namely ‘15’

Note: I ran these in ghci.

@MuhammedZakir
Copy link
Author

Out of topic: [ProductName ==. "text"] is better than [ps ^. ProductName ==. val "name"]`. For the query, I can understand it as maybe optimization, better generated query and better type-level safety. But for this, I don't understand. What was the reason for choosing the latter?


Late, but, thank you very much for this library!

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

No branches or pull requests

1 participant