Minor fixes
This commit is contained in:
parent
2caa00c06a
commit
19a1aa26e4
@ -83,3 +83,4 @@ getScoreByAge conn = do
|
||||
- [ ] `FromRow`
|
||||
- [ ] Custom `FromField` impls
|
||||
- [ ] Improve type errors when trying to `instance` a type that isn't a record (e.g. sum type)
|
||||
- [ ] Improve documentation for `fromRow` module
|
||||
|
@ -89,7 +89,7 @@ type family NumberOfMembers f where
|
||||
NumberOfMembers (M1 D _ f) = NumberOfMembers f
|
||||
-- The constructor has as many members as the type that it contains.
|
||||
NumberOfMembers (M1 C _ f) = NumberOfMembers f
|
||||
-- A product type has as many types as its subtypes have together.
|
||||
-- A product type has as many members as its subtypes have together.
|
||||
NumberOfMembers (f :*: g) = NumberOfMembers f + NumberOfMembers g
|
||||
-- A selector has/is exactly one member.
|
||||
NumberOfMembers (M1 S _ f) = 1
|
||||
@ -99,19 +99,23 @@ data FromRowCtx = FromRowCtx
|
||||
Result -- ^ Obtained from 'LibPQ.execParams'.
|
||||
ColumnTable -- ^ 'Vector' of expected columns indices and OIDs.
|
||||
|
||||
-- Specialized proxy type to be used instead of `Proxy (n, f)`
|
||||
data FRProxy (n :: Nat) (f :: Type -> Type) = FRProxy
|
||||
|
||||
class FromRow' (n :: Nat) (f :: Type -> Type) where
|
||||
fromRow' :: FRProxy n f -> FromRowCtx -> Row -> ExceptT Error IO (f p)
|
||||
|
||||
instance FromRow' n f => FromRow' n (M1 D c f) where
|
||||
fromRow' FRProxy ctx row = M1 <$> fromRow' @n FRProxy ctx row
|
||||
fromRow' FRProxy ctx row =
|
||||
M1 <$> fromRow' @n FRProxy ctx row
|
||||
|
||||
instance FromRow' n f => FromRow' n (M1 C c f) where
|
||||
fromRow' FRProxy ctx row = M1 <$> fromRow' @n FRProxy ctx row
|
||||
fromRow' FRProxy ctx row =
|
||||
M1 <$> fromRow' @n FRProxy ctx row
|
||||
|
||||
instance (FromRow' n f, FromRow' (n + NumberOfMembers f) g) => FromRow' n (f :*: g) where
|
||||
fromRow' FRProxy ctx row = (:*:) <$> fromRow' @n FRProxy ctx row <*> fromRow' @(n + NumberOfMembers f) FRProxy ctx row
|
||||
fromRow' FRProxy ctx row =
|
||||
(:*:) <$> fromRow' @n FRProxy ctx row <*> fromRow' @(n + NumberOfMembers f) FRProxy ctx row
|
||||
|
||||
instance {-# OVERLAPPABLE #-} (KnownNat n, KnownSymbol nameSym, FromField t) => FromRow' n (M1 S ('MetaSel ('Just nameSym) nu ns dl) (Rec0 t)) where
|
||||
fromRow' FRProxy = decodeField memberIndex nameText $ \row ->
|
||||
@ -158,4 +162,3 @@ decodeField memberIndex nameText g (FromRowCtx result columnTable) row = do
|
||||
first
|
||||
(ErrorInvalidField (ErrorPosition row nameText) oid field)
|
||||
(Just <$> fromField field)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user