1module Rel8.Type.JSONEncoded ( JSONEncoded(..) ) where
4import Data.Aeson ( FromJSON, ToJSON, parseJSON, toJSON )
5import Data.Aeson.Types ( parseEither )
11import Rel8.Type ( DBType(..) )
12import Rel8.Type.Information ( parseTypeInformation )
15-- | A deriving-via helper type for column types that store a Haskell value
16-- using a JSON encoding described by @aeson@'s 'ToJSON' and 'FromJSON' type
21-- >>> import Data.Aeson
24-- data Pet = Pet { petName :: String, petAge :: Int }
25-- deriving (Generic, ToJSON, FromJSON)
26-- deriving PrimitiveType via JSONEncoded Pet
29-- will allow you to store @Pet@ values in a single SQL column (stored as
31newtype JSONEncoded a = JSONEncoded { fromJSONEncoded :: a }
34instance (FromJSON a, ToJSON a) => DBType (JSONEncoded a) where
35 typeInformation = parseTypeInformation f g typeInformation
37 f = fmap JSONEncoded . parseEither parseJSON
38 g = toJSON . fromJSONEncoded
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