Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
jsonbbytes to jsonb
Browse files Browse the repository at this point in the history
  • Loading branch information
willbasky committed Sep 2, 2019
1 parent b676629 commit 4f0c0a9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions back/src/Guide/Types/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,15 @@ instance Aeson.FromJSON Category where
pure Category{..}

instance ToPostgres Category where
toPostgres = toByteString . Aeson.encode >$< HE.jsonbBytes
toPostgres = Aeson.toJSON >$< HE.jsonb

instance FromPostgres Category where
fromPostgres = HD.jsonbBytes $
either (Left . toText) (Right . id) . Aeson.eitherDecodeStrict
fromPostgres = resultToEither . Aeson.fromJSON <$> HD.jsonb

-- | Unwrap result to category or fail.
resultToEither :: Aeson.Result Category -> Category
resultToEither (Aeson.Success category) = category
resultToEither (Aeson.Error s) = error $ "fromJSON failed with error: " ++ s

-- | Category identifier (used in URLs). E.g. for a category with title
-- “Performance optimization” and UID “t3c9hwzo” the slug would be
Expand Down

0 comments on commit 4f0c0a9

Please sign in to comment.