使用
Haskell中的Groundhog库,我希望实现一个在后端是Postgresql时使用“uuid”的列类型,否则只需使用“varchar”用于任何其他后端.虽然根据Groundhog.Core中的注释,这应该是可能的,我不完全确定如何从代理db中解包dbType,并且在groundhog-examples中没有这个例子,因为列类型已在那些中硬编码例子.
我想在Postgresql的案例匹配方面得到一些帮助,我会在排序之后解决剩下的问题.这是我在的地方:
instance PrimitivePersistField UUID where toPrimitivePersistValue _ uuid = PersistString $show uuid fromPrimitivePersistValue _ (PersistString a) = fromJust $UUIDmethods.fromString a instance PersistField UUID where persistName _ = "UUID" toPersistValues = primToPersistValue fromPersistValues = primFromPersistValue dbType db _ = case db of Postgresql _ -> DbTypePrimitive (DbOther $OtherTypeDef [Left "uuid"]) False nothing nothing _ -> DbTypePrimitive (DbOther $OtherTypeDef [Left "varchar"]) False nothing nothing
在编译时出现了这个问题:
Couldn't match expected type ‘proxy db’ with actual type ‘Postgresql’ Relevant bindings include db :: proxy db (bound at basicGroundhog.hs:34:10) dbType :: proxy db -> UUID -> DbType (bound at basicGroundhag.hs:34:3) In the pattern: Postgresql _ In a case alternative: Postgresql _ -> DbTypePrimitive (DbOther $OtherTypeDef [Left "uuid"]) False nothing nothing In the expression: case db of { Postgresql _ -> DbTypePrimitive (DbOther $OtherTypeDef [Left "uuid"]) False nothing nothing _ -> DbTypePrimitive (DbOther $OtherTypeDef [Left "varchar"]) False nothing nothing }
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。