@@ -1,8 +1,9 @@
11{-# LANGUAGE DefaultSignatures, TypeFamilies, TypeOperators, PolyKinds, FlexibleInstances, ScopedTypeVariables, FlexibleContexts, DeriveGeneric, DeriveAnyClass #-}
2−module ProjectM36.ConstructedAtom where
2+module ProjectM36.Atomable where
33--http://stackoverflow.com/questions/13448361/type-families-with-ghc-generics-or-data-data
44--instances to marshal Haskell ADTs to ConstructedAtoms and back
55import ProjectM36.Base
6+import ProjectM36.Relation
67import ProjectM36.DataTypes.Primitive
78import GHC.Generics
89import qualified Data.Map as M
@@ -10,6 +11,9 @@ import qualified Data.Text as T
1011import Control.DeepSeq (NFData)
1112import Data.Binary
1213import Control.Applicative
14+import Data.Time.Calendar
15+import Data.ByteString (ByteString)
16+import Data.Time.Clock
1317
1418--also add haskell scripting atomable support
1519--rename this module to Atomable along with test
@@ -54,13 +58,56 @@ instance Atomable Int where
5458 toAtomType _ = IntAtomType
5559 toDatabaseContextExpr _ = NoOperation
5660
61+instance Atomable Double where
62+ toAtom d = DoubleAtom d
63+ fromAtom (DoubleAtom d) = d
64+ fromAtom _ = error "improper fromAtom"
65+ toAtomType _ = DoubleAtomType
66+ toDatabaseContextExpr _ = NoOperation
67+
5768instance Atomable T.Text where
5869 toAtom t = TextAtom t
5970 fromAtom (TextAtom t) = t
6071 fromAtom _ = error "improper fromAtom"
6172 toAtomType _ = TextAtomType
6273 toDatabaseContextExpr _ = NoOperation
63−
74+
75+instance Atomable Day where
76+ toAtom d = DayAtom d
77+ fromAtom (DayAtom d) = d
78+ fromAtom _ = error "improper fromAtom"
79+ toAtomType _ = DayAtomType
80+ toDatabaseContextExpr _ = NoOperation
81+
82+instance Atomable UTCTime where
83+ toAtom t = DateTimeAtom t
84+ fromAtom (DateTimeAtom t) = t
85+ fromAtom _ = error "improper fromAtom"
86+ toAtomType _ = DateTimeAtomType
87+ toDatabaseContextExpr _ = NoOperation
88+
89+instance Atomable ByteString where
90+ toAtom = ByteStringAtom
91+ fromAtom (ByteStringAtom b) = b
92+ fromAtom _ = error "improper fromAtom"
93+ toAtomType _ = ByteStringAtomType
94+ toDatabaseContextExpr _ = NoOperation
95+
96+instance Atomable Bool where
97+ toAtom = BoolAtom
98+ fromAtom (BoolAtom b) = b
99+ fromAtom _ = error "improper fromAtom"
100+ toAtomType _ = BoolAtomType
101+ toDatabaseContextExpr _ = NoOperation
102+
103+instance Atomable Relation where
104+ toAtom = RelationAtom
105+ fromAtom (RelationAtom r) = r
106+ fromAtom _ = error "improper fromAtom"
107+ --warning: cannot be used with undefined "Relation"
108+ toAtomType rel = RelationAtomType (attributes rel)
109+ toDatabaseContextExpr _ = NoOperation
110+
64111-- Generics
65112class AtomableG g where
66113 --type AtomTG g