Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for postgresql-binary-0.14 #362

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions squeal-postgresql/squeal-postgresql.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ library
, free-categories >= 0.2.0.0
, generics-sop >= 0.5.1.0
, hashable >= 1.3.0.0
, iproute >= 1.7.0
, mmorph >= 1.1.3
, monad-control >= 1.0.2.3
, mtl >= 2.2.2
Expand Down
13 changes: 10 additions & 3 deletions squeal-postgresql/src/Squeal/PostgreSQL/Session/Decode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ import Data.Bits
import Data.Coerce (coerce)
import Data.Functor.Constant (Constant(Constant))
import Data.Int (Int16, Int32, Int64)
#if MIN_VERSION_postgresql_binary(0, 14, 0)
import Data.IP (IPRange)
#else
import Network.IP.Addr (NetAddr, IP)
#endif
import Data.Kind
import Data.Scientific (Scientific)
import Data.String (fromString)
Expand All @@ -78,7 +83,6 @@ import Data.Vector (Vector)
import Database.PostgreSQL.LibPQ (Oid(Oid))
import GHC.OverloadedLabels
import GHC.TypeLits
import Network.IP.Addr (NetAddr, IP)
import PostgreSQL.Binary.Decoding hiding (Composite)
import Unsafe.Coerce

Expand Down Expand Up @@ -200,8 +204,11 @@ instance FromPG Money where
fromPG = devalue $ Money <$> int
instance FromPG UUID where
fromPG = devalue uuid
instance FromPG (NetAddr IP) where
fromPG = devalue inet
#if MIN_VERSION_postgresql_binary(0, 14, 0)
instance FromPG IPRange where fromPG = devalue inet
#else
instance FromPG (NetAddr IP) where fromPG = devalue inet
#endif
instance FromPG Char where
fromPG = devalue char
instance FromPG Strict.Text where
Expand Down
11 changes: 10 additions & 1 deletion squeal-postgresql/src/Squeal/PostgreSQL/Session/Encode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ encoding of statement parameters
{-# LANGUAGE
AllowAmbiguousTypes
, ConstraintKinds
, CPP
, DataKinds
, DefaultSignatures
, FlexibleContexts
Expand Down Expand Up @@ -59,6 +60,11 @@ import Data.Functor.Const (Const(Const))
import Data.Functor.Constant (Constant(Constant))
import Data.Functor.Contravariant
import Data.Int (Int16, Int32, Int64)
#if MIN_VERSION_postgresql_binary(0, 14, 0)
import Data.IP (IPRange)
#else
import Network.IP.Addr (NetAddr, IP)
#endif
import Data.Kind
import Data.Scientific (Scientific)
import Data.Text as Strict (Text)
Expand All @@ -69,7 +75,6 @@ import Data.Vector (Vector)
import Data.Word (Word32)
import Foreign.C.Types (CUInt(CUInt))
import GHC.TypeLits
import Network.IP.Addr (NetAddr, IP)
import PostgreSQL.Binary.Encoding hiding (Composite, field)

import qualified Data.Aeson as Aeson
Expand Down Expand Up @@ -121,7 +126,11 @@ instance ToPG db Double where toPG = pure . float8
instance ToPG db Scientific where toPG = pure . numeric
instance ToPG db Money where toPG = pure . int8_int64 . cents
instance ToPG db UUID where toPG = pure . uuid
#if MIN_VERSION_postgresql_binary(0, 14, 0)
instance ToPG db IPRange where toPG = pure . inet
#else
instance ToPG db (NetAddr IP) where toPG = pure . inet
#endif
instance ToPG db Char where toPG = pure . char_utf8
instance ToPG db Strict.Text where toPG = pure . text_strict
instance ToPG db Lazy.Text where toPG = pure . text_lazy
Expand Down
11 changes: 10 additions & 1 deletion squeal-postgresql/src/Squeal/PostgreSQL/Type/PG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ into corresponding Postgres types.
-}
{-# LANGUAGE
AllowAmbiguousTypes
, CPP
, DeriveAnyClass
, DeriveFoldable
, DeriveFunctor
Expand Down Expand Up @@ -57,12 +58,16 @@ import Data.Functor.Const (Const)
import Data.Functor.Constant (Constant)
import Data.Kind (Type)
import Data.Int (Int16, Int32, Int64)
#if MIN_VERSION_postgresql_binary(0, 14, 0)
import Data.IP (IPRange)
#else
import Network.IP.Addr (NetAddr, IP)
#endif
import Data.Scientific (Scientific)
import Data.Time (Day, DiffTime, LocalTime, TimeOfDay, TimeZone, UTCTime)
import Data.Vector (Vector)
import Data.UUID.Types (UUID)
import GHC.TypeLits
import Network.IP.Addr (NetAddr, IP)

import qualified Data.ByteString.Lazy as Lazy (ByteString)
import qualified Data.ByteString as Strict (ByteString)
Expand Down Expand Up @@ -166,7 +171,11 @@ instance IsPG DiffTime where type PG DiffTime = 'PGinterval
-- | `PGuuid`
instance IsPG UUID where type PG UUID = 'PGuuid
-- | `PGinet`
#if MIN_VERSION_postgresql_binary(0, 14, 0)
instance IsPG IPRange where type PG IPRange = 'PGinet
#else
instance IsPG (NetAddr IP) where type PG (NetAddr IP) = 'PGinet
#endif
-- | `PGjson`
instance IsPG Value where type PG Value = 'PGjson
-- | `PGvarchar`
Expand Down
Loading