forked from yesodweb/persistent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursive.hs
More file actions
42 lines (39 loc) · 1.09 KB
/
Recursive.hs
File metadata and controls
42 lines (39 loc) · 1.09 KB
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
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# LANGUAGE CPP, ScopedTypeVariables, FlexibleInstances #-}
{-# LANGUAGE QuasiQuotes, TypeFamilies, GeneralizedNewtypeDeriving, TemplateHaskell,
OverloadedStrings, GADTs, FlexibleContexts, EmptyDataDecls, MultiParamTypeClasses #-}
module Recursive (specs,
#ifndef WITH_NOSQL
recursiveMigrate
#endif
) where
import Init
#if WITH_NOSQL
mkPersist persistSettings [persistUpperCase|
#else
share [mkPersist sqlSettings, mkMigrate "recursiveMigrate"] [persistLowerCase|
#endif
SubType
object [MenuObject]
deriving Show Eq
MenuObject
sub SubType Maybe
deriving Show Eq
|]
#if WITH_NOSQL
cleanDB :: ReaderT Context IO ()
cleanDB = do
deleteWhere ([] :: [Filter MenuObject])
deleteWhere ([] :: [Filter SubType])
db :: Action IO () -> Assertion
db = db' cleanDB
#endif
specs :: Spec
specs = describe "recursive definitions" $ do
it "mutually recursive" $ db $ do
let m1 = MenuObject $ Just $ SubType []
let m2 = MenuObject $ Just $ SubType [m1]
let m3 = MenuObject $ Just $ SubType [m2]
k3 <- insert m3
m3' <- get k3
m3' @== Just m3