{-# LANGUAGE DerivingStrategies #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Preql.Wire.Orphans where
import Data.Aeson (FromJSON(..), ToJSON(..), Value(..), withScientific)
import Data.Scientific (toBoundedInteger)
import qualified Database.PostgreSQL.LibPQ as PQ
instance ToJSON PQ.Oid where
toJSON (PQ.Oid oid) = Number (fromIntegral oid)
instance FromJSON PQ.Oid where
parseJSON = withScientific "Oid" $ \sci ->
case toBoundedInteger sci of
Just i -> return (PQ.Oid i)
Nothing -> fail "expected integer Oid"