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