@@ -4,21 +4,29 @@
44{-# OPTIONS_GHC -Wno-orphans #-}
55
66module Data.Id
7− ( Id, mkId, unId, randomId, unsafeIdTagConvert, coerceId, _Id, nilId
8− , IntId, mkIntId, unIntId, unsafeIntIdTagConvert, coerceIntId, _IntId
9− , Name, mkName, unName, unsafeNameTagConvert, coerceName, _Name
7+ ( Id, mkId, unId, randomId, unsafeIdTagConvert, coerceId, nilId
8+ , IntId, mkIntId, unIntId, unsafeIntIdTagConvert, coerceIntId
9+ , Name, mkName, unName, unsafeNameTagConvert, coerceName
10+#ifdef USE_LENS
11+ , _Id, _IntId, _Name
12+#endif
1013 )
1114 where
1215
1316import Control.DeepSeq (NFData)
17+#ifdef USE_LENS
1418import Control.Lens
19+#endif
1520import Control.Monad
1621import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey)
1722import Data.Binary (Binary)
1823import Data.Coerce (coerce)
1924import Data.Data
2025import Data.Hashable (Hashable)
26+import Data.Int (Int64)
27+#ifdef USE_OPENAPI
2128import Data.OpenApi
29+#endif
2230import Data.String
2331import Data.Text as T
2432import Data.UUID (UUID)
@@ -44,6 +52,9 @@ import Flat as F
4452#ifdef USE_STORE
4553import qualified Data.Store
4654#endif
55+#ifdef USE_REL8
56+import Rel8 (DBType(..))
57+#endif
4758
4859newtype Id t = Id { unId :: UUID }
4960 deriving stock Data
@@ -53,14 +64,18 @@ newtype Id t = Id { unId :: UUID }
5364#ifdef USE_POSTGRES
5465 , PG.ToField, PG.FromField
5566#endif
67+#ifdef USE_REL8
68+ , DBType
69+#endif
70+#endif
71+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
72+#ifdef USE_OPENAPI
73+ , ToSchema, ToParamSchema
5674#endif
57− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
58− , ToParamSchema, FromHttpApiData, ToHttpApiData )
75+ , FromHttpApiData, ToHttpApiData )
5976
6077type role Id nominal
6178
62−makePrisms ''Id
63−
6479mkId :: forall s. UUID -> Id s
6580mkId = coerce
6681{-# INLINE mkId #-}
@@ -133,7 +148,7 @@ type family Ambiguous (a :: k) :: j where
133148 Ambiguous x = x
134149
135150----------------- IntId
136−newtype IntId t = IntId { unIntId :: Integer }
151+newtype IntId t = IntId { unIntId :: Int64 }
137152 deriving stock Data
138153 deriving newtype
139154 ( Eq, Ord, Binary
@@ -150,17 +165,21 @@ newtype IntId t = IntId { unIntId :: Integer }
150165#ifdef USE_STORE
151166 , Data.Store.Store
152167#endif
168+#ifdef USE_REL8
169+ , DBType
170+#endif
153171#endif
154− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
155− , ToParamSchema, FromHttpApiData, ToHttpApiData, PathPiece, Arbitrary
172+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
173+#ifdef USE_OPENAPI
174+ , ToSchema, ToParamSchema
175+#endif
176+ , FromHttpApiData, ToHttpApiData, PathPiece, Arbitrary
156177 , Num, Integral, Real, Enum )
157178
158179type role IntId nominal
159180
160−makePrisms ''IntId
161−
162181mkIntId :: forall s. Integer -> IntId s
163−mkIntId = coerce
182+mkIntId = fromInteger
164183{-# INLINE mkIntId #-}
165184
166185instance KnownSymbol s => Show (IntId s) where
@@ -199,15 +218,19 @@ newtype Name t = Name { unName :: Text }
199218#ifdef USE_STORE
200219 , Data.Store.Store
201220#endif
221+#ifdef USE_REL8
222+ , DBType
223+#endif
224+#endif
225+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
226+#ifdef USE_OPENAPI
227+ , ToSchema, ToParamSchema
202228#endif
203− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
204− , ToParamSchema, FromHttpApiData, ToHttpApiData, PathPiece
229+ , FromHttpApiData, ToHttpApiData, PathPiece
205230 , IsString, Semigroup, Monoid )
206231
207232type role Name nominal
208233
209−makePrisms ''Name
210−
211234mkName :: forall s. Text -> Name s
212235mkName = coerce
213236{-# INLINE mkName #-}
@@ -232,3 +255,9 @@ coerceName = coerce
232255{-# INLINE coerceName #-}
233256unsafeNameTagConvert = coerce
234257{-# INLINE unsafeNameTagConvert #-}
258+
259+#ifdef USE_LENS
260+makePrisms ''Id
261+makePrisms ''IntId
262+makePrisms ''Name
263+#endif