on dev help sign in
binary instances for container newtypes
commitb53969c7f0fc566e356448cce442abd9fb81ab10 authorEitan Chatav <eitan.chatav@gmail.com> dateFri 24 Aug 2018, 00:53 (8 years ago) parentf01894e
2 files changed+14−4
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+11−1 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+3−3
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+11−1
@@ -276,6 +276,7 @@ instance ToParam UTCTime 'PGtimestamptz where
276276instance ToParam DiffTime 'PGinterval where toParam = K . Encoding.interval_int
277277instance ToParam Value 'PGjson where toParam = K . Encoding.json_ast
278278instance ToParam Value 'PGjsonb where toParam = K . Encoding.jsonb_ast
279+instance ToParam Jsonb 'PGjsonb where toParam = toParam . getJsonb
279280instance ToArray x ('NotNull ('PGvararray ty))
280281 => ToParam x ('PGvararray ty) where
281282 toParam
@@ -286,6 +287,8 @@ instance ToArray x ('NotNull ('PGfixarray n ty))
286287 toParam
287288 = K . Encoding.array (baseOid @x @('NotNull ('PGfixarray n ty)))
288289 . unK . toArray @x @('NotNull ('PGfixarray n ty))
290+instance ToParam x pg => ToParam (Enumerated x) pg where
291+ toParam = toParam . getEnumerated
289292instance
290293 ( IsEnumType x
291294 , HasDatatypeInfo x
@@ -304,6 +307,8 @@ instance
304307 . Strict.pack
305308 . gshowConstructor (constructorInfo (datatypeInfo (Proxy @x)))
306309 . from
310+instance ToParam x pg => ToParam (Composite x) pg where
311+ toParam = toParam . getComposite
307312instance
308313 ( SListI fields
309314 , IsRecord x xs
@@ -448,12 +453,16 @@ instance FromValue 'PGinterval DiffTime where
448453 fromValue = Decoding.interval_int
449454instance FromValue 'PGjson Value where fromValue = Decoding.json_ast
450455instance FromValue 'PGjsonb Value where fromValue = Decoding.jsonb_ast
456+instance FromValue 'PGjsonb Jsonb where
457+ fromValue = Jsonb <$> fromValue @'PGjsonb
451458instance FromArray ('NotNull ('PGvararray ty)) y
452459 => FromValue ('PGvararray ty) y where
453460 fromValue = Decoding.array (fromArray @('NotNull ('PGvararray ty)) @y)
454461instance FromArray ('NotNull ('PGfixarray n ty)) y
455462 => FromValue ('PGfixarray n ty) y where
456463 fromValue = Decoding.array (fromArray @('NotNull ('PGfixarray n ty)) @y)
464+instance FromValue pg y => FromValue pg (Enumerated y) where
465+ fromValue = Enumerated <$> fromValue @pg
457466instance
458467 ( IsEnumType y
459468 , HasDatatypeInfo y
@@ -476,7 +485,8 @@ instance
476485 $ fmap to
477486 . greadConstructor (constructorInfo (datatypeInfo (Proxy @y)))
478487 . Strict.unpack
479−
488+instance FromValue pg y => FromValue pg (Composite y) where
489+ fromValue = Composite <$> fromValue @pg
480490instance
481491 ( FromRow fields y
482492 ) => FromValue ('PGcomposite fields) y where
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+3−3
@@ -112,9 +112,9 @@ module Squeal.PostgreSQL.Schema
112112 , PGjsonKey
113113 -- * Embedding
114114 , PG
115− , Jsonb
116− , Composite
117− , Enumerated
115+ , Jsonb (..)
116+ , Composite (..)
117+ , Enumerated (..)
118118 -- , EnumFrom
119119 , LabelsFrom
120120 -- , CompositeFrom