I've got the following:
asSqlBackendReader :: ReaderT SqlBackend m a -> ReaderT SqlBackend m a
asSqlBackendReader = id
insertEnt :: (Entity a) -> IO (Key (Entity a))
insertEnt x = runWithDb $ do
insert $ x
where runWithDb = runSqlite "test.db" . asSqlBackendReader
The purpose of the asSqlBAckendReader is due to Persistent selectList causing error of "Couldn't match type ‘BaseBackend backend0’ with ‘SqlBackend’".
I'm running into an error of:
• Couldn't match type ‘PersistEntityBackend (Entity a)’
with ‘SqlBackend’
arising from a use of ‘insert’
• In a stmt of a 'do' block: insert $ x
In the second argument of ‘($)’, namely ‘do { insert $ x }’
In the expression: runWithDb $ do { insert $ x }
Add the constraint to the signature of
insertEnt. You'll also need aPersistEntityconstraint.To deduce that (other than just giving the compiler what it's indirectly asking), you may look at the type of
insertWe also have
Furthermore, in your application you have some concrete types:
These concrete types discharge
PersistStoreWrite backendandMonadIO m, and sinceEntity ais still mostly abstract, you are left with the two constraints that definePersistRecordBackend. You could in fact use that synonym as a shorthand: