@@ -25,23 +25,32 @@ import Data.UUID (UUID)
25import qualified Data.UUID as UUID
25import qualified Data.UUID as UUID
26import qualified Data.UUID.V4 as UUID.V4
26import qualified Data.UUID.V4 as UUID.V4
27#ifndef ghcjs_HOST_OS
27#ifndef ghcjs_HOST_OS
28+import Data.Csv as Csv hiding(Name)
28import Database.PostgreSQL.Simple.FromField as PG (FromField)
30import Database.PostgreSQL.Simple.FromField as PG (FromField)
29import Database.PostgreSQL.Simple.ToField as PG (ToField)
31import Database.PostgreSQL.Simple.ToField as PG (ToField)
30−import Data.Csv as Csv hiding(Name)
32−import Flat as F
33+#endif
33import GHC.TypeLits
34import GHC.TypeLits
34import Test.QuickCheck
35import Test.QuickCheck
35import Text.ParserCombinators.ReadP
36import Text.ParserCombinators.ReadP
36import Web.HttpApiData
37import Web.HttpApiData
37import Web.PathPieces (PathPiece(..))
38import Web.PathPieces (PathPiece(..))
43+import qualified Data.Store
39newtype Id t = Id { unId :: UUID }
46newtype Id t = Id { unId :: UUID }
40 deriving stock Data
47 deriving stock Data
41 deriving newtype
48 deriving newtype
42 ( Eq, Ord, Binary
49 ( Eq, Ord, Binary
43#ifndef ghcjs_HOST_OS
50#ifndef ghcjs_HOST_OS
44 , PG.ToField, PG.FromField
52 , PG.ToField, PG.FromField
46 , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
55 , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
47 , ToParamSchema, FromHttpApiData, ToHttpApiData )
56 , ToParamSchema, FromHttpApiData, ToHttpApiData )
@@ -66,10 +75,19 @@ instance KnownSymbol s => Read (Id s) where
66 _ <- string ("Id-" <> symbolVal (Proxy @s) <> "-")
75 _ <- string ("Id-" <> symbolVal (Proxy @s) <> "-")
67 mkId <$> readS_to_P reads
76 mkId <$> readS_to_P reads
69instance Flat (Id s) where
79instance Flat (Id s) where
70 encode = F.encode . UUID.toWords . coerce
80 encode = F.encode . UUID.toWords . coerce
71 decode = coerce . (\(a,b,c,d) -> UUID.fromWords a b c d) <$> F.decode
81 decode = coerce . (\(a,b,c,d) -> UUID.fromWords a b c d) <$> F.decode
72 size = F.size . UUID.toWords . coerce
82 size = F.size . UUID.toWords . coerce
86+instance Data.Store.Store (Id s) where
87+ poke = Data.Store.poke . UUID.toWords . coerce
88+ peek = coerce . (\(a,b,c,d) -> UUID.fromWords a b c d) <$> Data.Store.peek
89+ size = Data.Store.ConstSize 16
74instance Arbitrary (Id t) where
92instance Arbitrary (Id t) where
75 arbitrary = fmap Id $ UUID.fromWords
93 arbitrary = fmap Id $ UUID.fromWords
@@ -116,7 +134,9 @@ newtype IntId t = IntId { unIntId :: Integer }
116 deriving newtype
134 deriving newtype
117 ( Eq, Ord, Binary
135 ( Eq, Ord, Binary
118#ifndef ghcjs_HOST_OS
136#ifndef ghcjs_HOST_OS
119 , PG.ToField, PG.FromField, Csv.ToField, Csv.FromField
138 , PG.ToField, PG.FromField, Csv.ToField, Csv.FromField
121 , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
141 , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
122 , ToParamSchema, FromHttpApiData, ToHttpApiData, PathPiece, Flat, Arbitrary
142 , ToParamSchema, FromHttpApiData, ToHttpApiData, PathPiece, Flat, Arbitrary
@@ -154,7 +174,9 @@ newtype Name t = Name { unName :: Text }
154 deriving newtype
174 deriving newtype
155 ( Eq, Ord, Binary
175 ( Eq, Ord, Binary
156#ifndef ghcjs_HOST_OS
176#ifndef ghcjs_HOST_OS
157 , PG.ToField, PG.FromField, Csv.ToField, Csv.FromField
178 , PG.ToField, PG.FromField, Csv.ToField, Csv.FromField
159 , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
181 , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
160 , ToParamSchema, FromHttpApiData, ToHttpApiData, PathPiece, Flat
182 , ToParamSchema, FromHttpApiData, ToHttpApiData, PathPiece, Flat