on YuMingLiao-feature/add_with_relvar_macro
help
sign in
1{-# LANGUAGE DeriveAnyClass,DeriveGeneric #-}
4import ProjectM36.Client
7import ProjectM36.Relation
13import ProjectM36.Tuple
15data AgeType = PreciseAge Int |
19 ApproximateAge Int Int
20 deriving (Eq,Show,Read,Hashable,Binary,Typeable,NFData,Generic)
22instance Atomable AgeType
24failFastMaybe :: (Show a) => Maybe a -> IO ()
25failFastMaybe (Just err) = error (show err)
26failFastMaybe Nothing = return ()
28failFastEither :: Show a => Either a b -> IO b
29failFastEither (Left err) = error (show err)
30failFastEither (Right val) = return val
32ageAtomType :: AtomType
33ageAtomType = atomTypeForProxy (Proxy :: Proxy AgeType)
37 let bob_relation_attrs = attributesFromList [Attribute "name" stringAtomType,
38 Attribute "age" ageAtomType]
39 relvar_name = "hospital_patient"
40 age_value_in = ApproximateAge 30 40
41 bob_relation_err = mkRelationFromList
43 [[Atom ("Bob"::Text), Atom age_value_in]]
45 connerr <- connectProjectM36 (InProcessConnectionInfo NoPersistence)
46 conn <- failFastEither connerr
47 bob_relation <- failFastEither bob_relation_err
48 merr <- executeDatabaseContextExpr conn (Assign relvar_name (ExistingRelation bob_relation))
50 result_err <- executeRelationalExpr conn (RelationVariable relvar_name)
51 result <- failFastEither result_err
52 case singletonTuple result of
53 Nothing -> error "not a singleton relation!"
55 (Atom age_value_out) <- failFastEither $ atomForAttributeName "age" tuple
58 case cast age_value_out of
59 Nothing -> error "wrong datatype"
60 Just age_value_out' ->
61 print (age_value_in == age_value_out')
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list