1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Database.Persist.TH.ImplicitIdColSpec where
import TemplateTestImports
import Data.Text (Text)
import Database.Persist.ImplicitIdDef
import Database.Persist.ImplicitIdDef.Internal (fieldTypeFromTypeable)
do
let
uuidDef =
mkImplicitIdDef @Text "uuid_generate_v1mc()"
settings =
setImplicitIdDef uuidDef sqlSettings
mkPersist settings [persistLowerCase|
User
name String
age Int
|]
pass :: IO ()
pass = pure ()
asIO :: IO a -> IO a
asIO = id
spec :: Spec
spec = describe "ImplicitIdColSpec" $ do
describe "UserKey" $ do
it "has type Text -> Key User" $ do
let
userKey = UserKey "Hello"
_ = UserKey :: Text -> UserId
pass
describe "getEntityId" $ do
let
EntityIdField idField =
getEntityId (entityDef (Nothing @User))
it "has SqlString SqlType" $ asIO $ do
fieldSqlType idField `shouldBe` SqlString
it "has Text FieldType" $ asIO $ do
pendingWith "currently returns UserId, may not be an issue"
fieldType idField
`shouldBe`
fieldTypeFromTypeable @Text
|