
I'm not familiar with persistent, but I might have some ideas.
You are using template haskell. So while you are not directly using json,
you are using it indirectly, via the code generated by mkPersist [1].
Presumably mkPersist must create an PersistEntity Account instance. Looking
at the superclass constraints of PersistEntity [2] we see ToJSON (Key
record) and FromJSON (Key record) where the record type variable is you
Account type.
You can easily create instances of FromJSON and ToJSON by using Generics
[3]. But this only works if you type is an instance of the Generic type
class. I think that the code generated by mkPersist depends on the Key
Account type having an instance for Generic. Notice that Key is a data
family (type level function) and thus Key Account equals some other type.
I can really recommend the -ddump-splices GHC option [4] when debugging
code involving template haskell. It is a lot easier to understand a problem
when you can just read the generated Haskell code.
1 -
https://hackage.haskell.org/package/persistent-template-2.8.0.1/docs/Databas...
2 -
https://hackage.haskell.org/package/persistent-2.10.4/docs/Database-Persist-...
3 -
https://hackage.haskell.org/package/aeson-1.4.6.0/docs/Data-Aeson.html#v:par...
4 -
https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/debugging.ht...
Op vr 17 jan. 2020 om 18:29 schreef Debasish Ghosh : Hi - I have an entity declaration in persistent as follows: share [mkPersist sqlSettings { mpsGenerateLenses = True, mpsPrefixFields =
False }, mkMigrate "migrateAll"] [persistLowerCase|
Account
accountNo Text
accountType AccountType
accountHolderName Text
accountOpenDate UTCTime default=CURRENT_TIME
accountCloseDate UTCTime Maybe default=NULL
currentBalance MoneyUSD
rateOfInterest Double
Primary accountNo
deriving Show
|] I am getting this compilation error .. • No instance for (Generic (Key Account))
arising from the 'deriving' clause of a data type declaration
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
• When deriving the instance for
(aeson-1.4.6.0:Data.Aeson.Types.ToJSON.ToJSON
(Key Account))
|
40 | share [mkPersist sqlSettings { mpsGenerateLenses = True,
mpsPrefixFields = False }, mkMigrate "migrateAll"] [persistLowerCase|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^... and another exactly similar for FromJSON What exactly is going wrong here ? I am not using json in the above
definition. regards.
--
Debasish Ghosh