on master help sign in
Squeeze in mapTypeInformation
a683d3cOllie Charles
docs/concepts.rst+8−2
@@ -26,16 +26,22 @@ If our database has users and orders, these tables might both have ids, but they
26are clearly not meant to be treated as a common type. Instead, we can make these
26are clearly not meant to be treated as a common type. Instead, we can make these
27types clearly different by writing::
27types clearly different by writing::
28
28
29− newtype UserId = UserId Int64
29+ newtype UserId = UserId { getUserId :: Int64 }
30 deriving newtype DBType
30 deriving newtype DBType
31
31
32− newtype OrderId = OrderId Int64
32+ newtype OrderId = OrderId { getOrderId :: Int64 }
33 deriving newtype DBType
33 deriving newtype DBType
34
34
35Now we can use ``UserId`` and ``OrderId`` in our Rel8 queries and definitions,
35Now we can use ``UserId`` and ``OrderId`` in our Rel8 queries and definitions,
36and Haskell will make sure we don't accidentally use an ``OrderId`` when we're
36and Haskell will make sure we don't accidentally use an ``OrderId`` when we're
37looking up a user.
37looking up a user.
38
38
39+If you would like to use this approach but can't use generalized newtype
40+deriving, the same can be achived by using ``mapTypeInformation``::
41+
42+ instance DBType UserId where
43+ typeInformation = mapTypeInformation UserId getUserId typeInformation
44+
39Parsing with ``DBType``
45Parsing with ``DBType``
40-----------------------
46-----------------------
41
47