Skip to content

Commit cfe347f

Browse files
Add support for postgresql-binary-0.14
postgresql-binary-0.14, which is now in stackage nightlies, swaps out the type `NetAddr IP` from the `network-ip` package for its inet type with `IPRange` from the `iproute` package. This change adds CPP so that both build.
1 parent 6b790f2 commit cfe347f

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

squeal-postgresql/squeal-postgresql.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ library
9999
, free-categories >= 0.2.0.0
100100
, generics-sop >= 0.5.1.0
101101
, hashable >= 1.3.0.0
102+
, iproute >= 1.7.0
102103
, mmorph >= 1.1.3
103104
, monad-control >= 1.0.2.3
104105
, mtl >= 2.2.2

squeal-postgresql/src/Squeal/PostgreSQL/Session/Decode.hs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ import Data.Bits
6868
import Data.Coerce (coerce)
6969
import Data.Functor.Constant (Constant(Constant))
7070
import Data.Int (Int16, Int32, Int64)
71+
#if MIN_VERSION_postgresql_binary(0, 14, 0)
72+
import Data.IP (IPRange)
73+
#else
74+
import Network.IP.Addr (NetAddr, IP)
75+
#endif
7176
import Data.Kind
7277
import Data.Scientific (Scientific)
7378
import Data.String (fromString)
@@ -78,7 +83,6 @@ import Data.Vector (Vector)
7883
import Database.PostgreSQL.LibPQ (Oid(Oid))
7984
import GHC.OverloadedLabels
8085
import GHC.TypeLits
81-
import Network.IP.Addr (NetAddr, IP)
8286
import PostgreSQL.Binary.Decoding hiding (Composite)
8387
import Unsafe.Coerce
8488

@@ -200,8 +204,11 @@ instance FromPG Money where
200204
fromPG = devalue $ Money <$> int
201205
instance FromPG UUID where
202206
fromPG = devalue uuid
203-
instance FromPG (NetAddr IP) where
204-
fromPG = devalue inet
207+
#if MIN_VERSION_postgresql_binary(0, 14, 0)
208+
instance FromPG IPRange where fromPG = devalue inet
209+
#else
210+
instance FromPG (NetAddr IP) where fromPG = devalue inet
211+
#endif
205212
instance FromPG Char where
206213
fromPG = devalue char
207214
instance FromPG Strict.Text where

squeal-postgresql/src/Squeal/PostgreSQL/Session/Encode.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ encoding of statement parameters
1111
{-# LANGUAGE
1212
AllowAmbiguousTypes
1313
, ConstraintKinds
14+
, CPP
1415
, DataKinds
1516
, DefaultSignatures
1617
, FlexibleContexts
@@ -59,6 +60,11 @@ import Data.Functor.Const (Const(Const))
5960
import Data.Functor.Constant (Constant(Constant))
6061
import Data.Functor.Contravariant
6162
import Data.Int (Int16, Int32, Int64)
63+
#if MIN_VERSION_postgresql_binary(0, 14, 0)
64+
import Data.IP (IPRange)
65+
#else
66+
import Network.IP.Addr (NetAddr, IP)
67+
#endif
6268
import Data.Kind
6369
import Data.Scientific (Scientific)
6470
import Data.Text as Strict (Text)
@@ -69,7 +75,6 @@ import Data.Vector (Vector)
6975
import Data.Word (Word32)
7076
import Foreign.C.Types (CUInt(CUInt))
7177
import GHC.TypeLits
72-
import Network.IP.Addr (NetAddr, IP)
7378
import PostgreSQL.Binary.Encoding hiding (Composite, field)
7479

7580
import qualified Data.Aeson as Aeson
@@ -121,7 +126,11 @@ instance ToPG db Double where toPG = pure . float8
121126
instance ToPG db Scientific where toPG = pure . numeric
122127
instance ToPG db Money where toPG = pure . int8_int64 . cents
123128
instance ToPG db UUID where toPG = pure . uuid
129+
#if MIN_VERSION_postgresql_binary(0, 14, 0)
130+
instance ToPG db IPRange where toPG = pure . inet
131+
#else
124132
instance ToPG db (NetAddr IP) where toPG = pure . inet
133+
#endif
125134
instance ToPG db Char where toPG = pure . char_utf8
126135
instance ToPG db Strict.Text where toPG = pure . text_strict
127136
instance ToPG db Lazy.Text where toPG = pure . text_lazy

squeal-postgresql/src/Squeal/PostgreSQL/Type/PG.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ into corresponding Postgres types.
1010
-}
1111
{-# LANGUAGE
1212
AllowAmbiguousTypes
13+
, CPP
1314
, DeriveAnyClass
1415
, DeriveFoldable
1516
, DeriveFunctor
@@ -57,12 +58,16 @@ import Data.Functor.Const (Const)
5758
import Data.Functor.Constant (Constant)
5859
import Data.Kind (Type)
5960
import Data.Int (Int16, Int32, Int64)
61+
#if MIN_VERSION_postgresql_binary(0, 14, 0)
62+
import Data.IP (IPRange)
63+
#else
64+
import Network.IP.Addr (NetAddr, IP)
65+
#endif
6066
import Data.Scientific (Scientific)
6167
import Data.Time (Day, DiffTime, LocalTime, TimeOfDay, TimeZone, UTCTime)
6268
import Data.Vector (Vector)
6369
import Data.UUID.Types (UUID)
6470
import GHC.TypeLits
65-
import Network.IP.Addr (NetAddr, IP)
6671

6772
import qualified Data.ByteString.Lazy as Lazy (ByteString)
6873
import qualified Data.ByteString as Strict (ByteString)
@@ -166,7 +171,11 @@ instance IsPG DiffTime where type PG DiffTime = 'PGinterval
166171
-- | `PGuuid`
167172
instance IsPG UUID where type PG UUID = 'PGuuid
168173
-- | `PGinet`
174+
#if MIN_VERSION_postgresql_binary(0, 14, 0)
175+
instance IsPG IPRange where type PG IPRange = 'PGinet
176+
#else
169177
instance IsPG (NetAddr IP) where type PG (NetAddr IP) = 'PGinet
178+
#endif
170179
-- | `PGjson`
171180
instance IsPG Value where type PG Value = 'PGjson
172181
-- | `PGvarchar`

0 commit comments

Comments
 (0)