@@ -243,6 +243,28 @@ instance (HasOid pg, ToParam x pg)
243243 => ToParam (Vector x) ('PGvararray ('NotNull pg)) where
244244 toParam = K . Encoding.array_vector
245245 (oid @pg) (unK . toParam @x @pg)
246+toVector :: (All ((~) x) xs) => NP I xs -> Vector x
247+toVector = \case
248+ Nil -> Vector.empty
249+ I x :* xs -> Vector.singleton x <> toVector xs
250+instance
251+ ( HasOid pg
252+ , ToParam x pg
253+ , IsProductType hask xs
254+ , All ((~) x) xs
255+ , len ~ Length xs
256+ ) => ToParam hask ('PGfixarray len ('NotNull pg)) where
257+ toParam = K . Encoding.array_vector
258+ (oid @pg) (unK . toParam @x @pg) . toVector . unZ . unSOP . from
259+instance
260+ ( HasOid pg
261+ , ToParam x pg
262+ , IsProductType hask xs
263+ , All ((~) (Maybe x)) xs
264+ , len ~ Length xs
265+ ) => ToParam hask ('PGfixarray len ('Null pg)) where
266+ toParam = K . Encoding.nullableArray_vector
267+ (oid @pg) (unK . toParam @x @pg) . toVector . unZ . unSOP . from
246268instance
247269 ( IsEnumType x
248270 , HasDatatypeInfo x
@@ -388,16 +410,39 @@ instance FromValue pg y
388410 fromValue = Decoding.array
389411 (Decoding.dimensionArray Vector.replicateM
390412 (Decoding.valueArray (fromValue @pg)))
391−instance FromValue pg y
392− => FromValue ('PGfixarray n ('Null pg)) (Vector (Maybe y)) where
393− fromValue = Decoding.array
394− (Decoding.dimensionArray Vector.replicateM
395− (Decoding.nullableValueArray (fromValue @pg)))
396−instance FromValue pg y
397− => FromValue ('PGfixarray n ('NotNull pg)) (Vector y) where
398− fromValue = Decoding.array
399− (Decoding.dimensionArray Vector.replicateM
400− (Decoding.valueArray (fromValue @pg)))
413+fromVector
414+ :: forall x xs. (All ((~) x) xs, SListI xs)
415+ => Vector x
416+ -> Decoding.Value (NP I xs)
417+fromVector vec = case fromList (Vector.toList vec) of
418+ Nothing -> failure "fromVector: unexpected length"
419+ Just xs -> return $ hcmap (Proxy :: Proxy ((~) x)) (I . unK) xs
420+instance
421+ ( IsProductType hask ys
422+ , All ((~) y) ys
423+ , len ~ Length ys
424+ , FromValue pg y
425+ ) => FromValue ('PGfixarray len ('NotNull pg)) hask where
426+ fromValue =
427+ let
428+ vectorValue = Decoding.array
429+ (Decoding.dimensionArray Vector.replicateM
430+ (Decoding.valueArray (fromValue @pg)))
431+ in
432+ fmap (to . SOP . Z) (fromVector @y =<< vectorValue)
433+instance
434+ ( IsProductType hask ys
435+ , All ((~) (Maybe y)) ys
436+ , len ~ Length ys
437+ , FromValue pg y
438+ ) => FromValue ('PGfixarray len ('Null pg)) hask where
439+ fromValue =
440+ let
441+ vectorValue = Decoding.array
442+ (Decoding.dimensionArray Vector.replicateM
443+ (Decoding.nullableValueArray (fromValue @pg)))
444+ in
445+ fmap (to . SOP . Z) (fromVector @(Maybe y) =<< vectorValue)
401446instance
402447 ( IsEnumType y
403448 , HasDatatypeInfo y