1module Rel8.Type.JSONBEncoded ( JSONBEncoded(..) ) where
4import Data.Aeson ( FromJSON, ToJSON, parseJSON, toJSON )
5import Data.Aeson.Types ( parseEither )
8import Data.Bifunctor ( first )
12import qualified Hasql.Decoders as Hasql
15import Rel8.Type ( DBType(..) )
16import Rel8.Type.Information ( TypeInformation(..) )
19import Data.Text ( pack )
22-- | Like 'Rel8.JSONEncoded', but works for @jsonb@ columns.
23newtype JSONBEncoded a = JSONBEncoded { fromJSONBEncoded :: a }
26instance (FromJSON a, ToJSON a) => DBType (JSONBEncoded a) where
27 typeInformation = TypeInformation
28 { encode = encode typeInformation . toJSON . fromJSONBEncoded
29 , decode = Hasql.refine (first pack . fmap JSONBEncoded . parseEither parseJSON) Hasql.jsonb
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list