From 00b2abc11061f90701213a0df3e8c26ce06d5c02 Mon Sep 17 00:00:00 2001 From: Ben Orchard Date: Wed, 11 Mar 2026 16:09:22 +0000 Subject: [PATCH 1/2] add DBType instance for Aeson.Object --- src/Rel8/Type.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Rel8/Type.hs b/src/Rel8/Type.hs index f49835ba..0e934322 100644 --- a/src/Rel8/Type.hs +++ b/src/Rel8/Type.hs @@ -16,7 +16,7 @@ module Rel8.Type where -- aeson -import Data.Aeson ( Value ) +import Data.Aeson ( Value, Object ) import qualified Data.Aeson as Aeson import qualified Data.Aeson.Text as Aeson @@ -63,7 +63,7 @@ import Rel8.Type.Array ( listTypeInformation, nonEmptyTypeInformation ) import Rel8.Type.Decimal (PowerOf10, resolution) import Rel8.Type.Decoder (Decoder (..)) import Rel8.Type.Encoder (Encoder (..)) -import Rel8.Type.Information ( TypeInformation(..), mapTypeInformation ) +import Rel8.Type.Information ( TypeInformation(..), mapTypeInformation, parseTypeInformation ) import Rel8.Type.Name (TypeName (..)) import Rel8.Type.Parser (parse) import qualified Rel8.Type.Builder.ByteString as Builder @@ -521,6 +521,16 @@ instance DBType Value where , typeName = "jsonb" } +-- | Corresponds to @jsonb@ +instance DBType Object where + typeInformation = parseTypeInformation + (aesonResultToEither . Aeson.fromJSON) + Aeson.Object + typeInformation + where + aesonResultToEither = \case + Aeson.Success o -> Right o + Aeson.Error e -> Left e -- | Corresponds to @inet@ instance DBType IPRange where From 176d16caf5b6c5e1b79e0c1f62dbcf2afb5147cb Mon Sep 17 00:00:00 2001 From: Ben Orchard Date: Wed, 11 Mar 2026 16:20:47 +0000 Subject: [PATCH 2/2] add test for DBType Aeson.Object --- tests/Main.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Main.hs b/tests/Main.hs index 8ba5cd58..f26a580a 100644 --- a/tests/Main.hs +++ b/tests/Main.hs @@ -585,6 +585,7 @@ testDBType getTestDatabase = testGroup "DBType instances" , dbTypeTest "Value" genValue , dbTypeTest "JSONEncoded" genJSONEncoded , dbTypeTest "JSONBEncoded" genJSONBEncoded + , dbTypeTest "Object" genObject ] where @@ -733,13 +734,16 @@ testDBType getTestDatabase = testGroup "DBType instances" , Aeson.Number <$> genScientific , Aeson.String <$> genText ] - [ Aeson.Object . Aeson.KeyMap.fromMap <$> Gen.map (Range.linear 0 10) ((,) <$> genKey <*> genValue) + [ Aeson.Object <$> genObject , Aeson.Array . Vector.fromList <$> Gen.list (Range.linear 0 10) genValue ] genJSONEncoded = Rel8.JSONEncoded <$> genValue genJSONBEncoded = Rel8.JSONBEncoded <$> genValue + genObject :: Gen Aeson.Object + genObject = Aeson.KeyMap.fromMap <$> Gen.map (Range.linear 0 10) ((,) <$> genKey <*> genValue) + testDBEq :: IO TmpPostgres.DB -> TestTree testDBEq getTestDatabase = testGroup "DBEq instances"