我目前正在研究的项目广泛使用persistent
。persistent
我想使用json来代替准引用的语法来指定模型。现在,我使用脚本来生成persistent
期望使用的准引用simple-templates
。这在工作流程中增加了一个相当尴尬的步骤。可以避免使用template-haskell
吗?
当前由脚本生成:
-- File : ProjSpecific.Models
share [mkPersist sqlSettings, mkMigrate "migrateAll"]
[persistLowerCase|
Person
name String
age Int Maybe
deriving Show
BlogPost
title String
authorId PersonId
deriving Show
|]
这是我理想的方式:
-- File : ProjSpecific.Config
import Data.Aeson.QQ
import Data.Aeson (Value)
models :: Value
models = [aesonQQ| {some json encoding of above models} |]
和
-- File : ProjSpecific.Models
complie time logic to generate the persistent models
关于如何完成此操作的任何想法,或者是否有更好的方法来实现我要执行的操作?
是的,应该相对没有痛苦。本质上,您希望使用from的quoteExp字段persistLowerCase
,它将为您提供type函数String -> Q Exp
。使用预处理器将JSON转换为所需的语法,然后将其传递给函数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句