是否有可能构建一个“持久”架构?

时间:2016-09-30 21:36:12

标签: haskell persistent

假设我有4个模块:Common,A,B和Main,我想要以下架构:

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Common
  commonField Int
A
  commonId CommonId
  aField Int
B
  commonId CommonId
  bField Int
|]

但我希望将它分割为Common,A和B模块。然后我希望Main依赖所有这些并包含数据库逻辑。

我尝试了以下(忽略B)

-- module Common
share [mkPersist sqlSettings, mkMigrate "migrateCommon"] [persistLowerCase|
Common
  commonField Int
|]

-- module A
share [mkPersist sqlSettings, mkMigrate "migrateA"] [persistLowerCase|
A
  commonId CommonId
  aField Int
|]

但是生成的迁移会将外部约束从A移除到Common。

我在调用share之前尝试存储并连接persistLowerCase quasiquoter的结果,但这导致了一个关于CommonId不在范围内的类型错误。

我能想到的唯一其他解决方案是存储字符串,连接它们,并在其上调用quasiquoter,这看起来不太好。

有什么建议吗?

0 个答案:

没有答案
相关问题