如何使用persistLowerCase
quasiquoter 构建具有两个或多个字段的唯一键?
使用Yesod bookDatabase.Persist
中的指导为简单网站创建模型时,会出现以下错误:
Build FAILED
$PREFIX/App/Models.hs: line 42, column 18:
Not in scope: data constructor `GroupSlug'
$PREFIX/App/Models.hs: line 43, column 19:
Not in scope: data constructor `GroupName'
应用程序/模型.hs
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module App.Models where
import Data.Text (Text)
import Database.Persist.TH
share [ mkPersist sqlSettings
, mkMigrate "migrateAll"] [persistLowerCase|
Post
group GroupId
postName Text
postSlug Text
period Text
content_en Text
content_pt Text
UniquePost postSlug
deriving Show
Group
groupId Int
groupName Text
groupSlug Text
parent GroupId
UniqueGroup groupId groupSlug
deriving Show
|]
应用程序/处理程序.hs
{-# LANGUAGE OverloadedStrings #-}
module App.Handlers where
import Database.Esqueleto
import App.Models
groupQuery x =
select $
from $ \g -> do
where_ (g ^. GroupSlug ==. val x)
return $ g ^. GroupName
版本:
我错过了一些扩展或忽略了其他东西吗?