Skip to content

Instantly share code, notes, and snippets.

@5outh
Created May 4, 2018 15:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5outh/1ef868d54e785ccf72762961c274e454 to your computer and use it in GitHub Desktop.
Save 5outh/1ef868d54e785ccf72762961c274e454 to your computer and use it in GitHub Desktop.
newtype JSONB a = JSONB { unJSONB :: a }
deriving
( Generic
, Eq
, Foldable
, Functor
, Ord
, Read
, Show
, Traversable
)
instance ToJSON a => ToJSON (JSONB a) where
toJSON (JSONB a) = toJSON a
toEncoding (JSONB a) = toEncoding a
instance FromJSON a => FromJSON (JSONB a) where
parseJSON = fmap JSONB . parseJSON
instance (ToJSON a, FromJSON a) => PersistFieldSql (JSONB a) where
sqlType _ = SqlOther "JSONB"
instance (ToJSON a, FromJSON a) => PersistField (JSONB a) where
toPersistValue = toPersistValueJSON
fromPersistValue = fromPersistValueJSON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment