Skip to content

Commit b99951b

Browse files
committed
feat: add ipnet support
1 parent 6c2a29f commit b99951b

File tree

21 files changed

+294
-19
lines changed

21 files changed

+294
-19
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ _unstable-all-types = [
6868
"json",
6969
"time",
7070
"chrono",
71+
"ipnet",
7172
"ipnetwork",
7273
"mac_address",
7374
"uuid",
@@ -116,6 +117,7 @@ json = ["sqlx-macros?/json", "sqlx-mysql?/json", "sqlx-postgres?/json", "sqlx-sq
116117
bigdecimal = ["sqlx-core/bigdecimal", "sqlx-macros?/bigdecimal", "sqlx-mysql?/bigdecimal", "sqlx-postgres?/bigdecimal"]
117118
bit-vec = ["sqlx-core/bit-vec", "sqlx-macros?/bit-vec", "sqlx-postgres?/bit-vec"]
118119
chrono = ["sqlx-core/chrono", "sqlx-macros?/chrono", "sqlx-mysql?/chrono", "sqlx-postgres?/chrono", "sqlx-sqlite?/chrono"]
120+
ipnet = ["sqlx-core/ipnet", "sqlx-macros?/ipnet", "sqlx-postgres?/ipnet"]
119121
ipnetwork = ["sqlx-core/ipnetwork", "sqlx-macros?/ipnetwork", "sqlx-postgres?/ipnetwork"]
120122
mac_address = ["sqlx-core/mac_address", "sqlx-macros?/mac_address", "sqlx-postgres?/mac_address"]
121123
rust_decimal = ["sqlx-core/rust_decimal", "sqlx-macros?/rust_decimal", "sqlx-mysql?/rust_decimal", "sqlx-postgres?/rust_decimal"]
@@ -142,7 +144,7 @@ sqlx = { version = "=0.8.3", path = ".", default-features = false }
142144
bigdecimal = "0.4.0"
143145
bit-vec = "0.6.3"
144146
chrono = { version = "0.4.34", default-features = false, features = ["std", "clock"] }
145-
ipnetwork = "0.20.0"
147+
ipnet = "2.3.0"
146148
mac_address = "1.1.5"
147149
rust_decimal = { version = "1.26.1", default-features = false, features = ["std"] }
148150
time = { version = "0.3.36", features = ["formatting", "parsing", "macros"] }

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ be removed in the future.
220220

221221
- `rust_decimal`: Add support for `NUMERIC` using the `rust_decimal` crate.
222222

223+
- `ipnet`: Add support for `INET` and `CIDR` (in postgres) using the `ipnet` crate.
224+
223225
- `ipnetwork`: Add support for `INET` and `CIDR` (in postgres) using the `ipnetwork` crate.
224226

225227
- `json`: Add support for `JSON` and `JSONB` (in postgres) using the `serde_json` crate.

sqlx-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ bit-vec = { workspace = true, optional = true }
4949
bigdecimal = { workspace = true, optional = true }
5050
rust_decimal = { workspace = true, optional = true }
5151
time = { workspace = true, optional = true }
52+
ipnet = { workspace = true, optional = true }
5253
ipnetwork = { workspace = true, optional = true }
5354
mac_address = { workspace = true, optional = true }
5455
uuid = { workspace = true, optional = true }

sqlx-core/src/types/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ pub use bigdecimal::BigDecimal;
6767
#[doc(no_inline)]
6868
pub use rust_decimal::Decimal;
6969

70+
#[cfg(feature = "ipnet")]
71+
#[cfg_attr(docsrs, doc(cfg(feature = "ipnet")))]
72+
pub mod ipnet {
73+
#[doc(no_inline)]
74+
pub use ipnet::{IpNet, Ipv4Net, Ipv6Net};
75+
}
76+
7077
#[cfg(feature = "ipnetwork")]
7178
#[cfg_attr(docsrs, doc(cfg(feature = "ipnetwork")))]
7279
pub mod ipnetwork {

sqlx-macros-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ json = ["sqlx-core/json", "sqlx-mysql?/json", "sqlx-postgres?/json", "sqlx-sqlit
3838
bigdecimal = ["sqlx-core/bigdecimal", "sqlx-mysql?/bigdecimal", "sqlx-postgres?/bigdecimal"]
3939
bit-vec = ["sqlx-core/bit-vec", "sqlx-postgres?/bit-vec"]
4040
chrono = ["sqlx-core/chrono", "sqlx-mysql?/chrono", "sqlx-postgres?/chrono", "sqlx-sqlite?/chrono"]
41+
ipnet = ["sqlx-core/ipnet", "sqlx-postgres?/ipnet"]
4142
ipnetwork = ["sqlx-core/ipnetwork", "sqlx-postgres?/ipnetwork"]
4243
mac_address = ["sqlx-core/mac_address", "sqlx-postgres?/mac_address"]
4344
rust_decimal = ["sqlx-core/rust_decimal", "sqlx-mysql?/rust_decimal", "sqlx-postgres?/rust_decimal"]

sqlx-macros/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ sqlite-unbundled = ["sqlx-macros-core/sqlite-unbundled"]
3737
bigdecimal = ["sqlx-macros-core/bigdecimal"]
3838
bit-vec = ["sqlx-macros-core/bit-vec"]
3939
chrono = ["sqlx-macros-core/chrono"]
40+
ipnet = ["sqlx-macros-core/ipnet"]
4041
ipnetwork = ["sqlx-macros-core/ipnetwork"]
4142
mac_address = ["sqlx-macros-core/mac_address"]
4243
rust_decimal = ["sqlx-macros-core/rust_decimal"]

sqlx-postgres/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ offline = ["sqlx-core/offline"]
1919
bigdecimal = ["dep:bigdecimal", "dep:num-bigint", "sqlx-core/bigdecimal"]
2020
bit-vec = ["dep:bit-vec", "sqlx-core/bit-vec"]
2121
chrono = ["dep:chrono", "sqlx-core/chrono"]
22+
ipnet = ["dep:ipnet", "sqlx-core/ipnet"]
2223
ipnetwork = ["dep:ipnetwork", "sqlx-core/ipnetwork"]
2324
mac_address = ["dep:mac_address", "sqlx-core/mac_address"]
2425
rust_decimal = ["dep:rust_decimal", "rust_decimal/maths", "sqlx-core/rust_decimal"]
@@ -43,6 +44,7 @@ sha2 = { version = "0.10.0", default-features = false }
4344
bigdecimal = { workspace = true, optional = true }
4445
bit-vec = { workspace = true, optional = true }
4546
chrono = { workspace = true, optional = true }
47+
ipnet = { workspace = true, optional = true }
4648
ipnetwork = { workspace = true, optional = true }
4749
mac_address = { workspace = true, optional = true }
4850
rust_decimal = { workspace = true, optional = true }

sqlx-postgres/src/type_checking.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ impl_type_checking!(
7777
#[cfg(feature = "rust_decimal")]
7878
sqlx::types::Decimal,
7979

80+
#[cfg(all(feature = "ipnet", not(feature = "ipnetwork")))]
81+
sqlx::types::ipnet::IpNet,
82+
8083
#[cfg(feature = "ipnetwork")]
8184
sqlx::types::ipnetwork::IpNetwork,
8285

@@ -138,6 +141,9 @@ impl_type_checking!(
138141
#[cfg(feature = "rust_decimal")]
139142
Vec<sqlx::types::Decimal> | &[sqlx::types::Decimal],
140143

144+
#[cfg(all(feature = "ipnet", not(feature = "ipnetwork")))]
145+
Vec<sqlx::types::ipnet::IpNet> | &[sqlx::types::ipnet::IpNet],
146+
141147
#[cfg(feature = "ipnetwork")]
142148
Vec<sqlx::types::ipnetwork::IpNetwork> | &[sqlx::types::ipnetwork::IpNetwork],
143149

sqlx-postgres/src/type_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl PgTypeInfo {
256256
]
257257
.contains(self)
258258
{
259-
Some("ipnetwork")
259+
Some("ipnet")
260260
} else if [PgTypeInfo::MACADDR].contains(self) {
261261
Some("mac_address")
262262
} else if [PgTypeInfo::NUMERIC, PgTypeInfo::NUMERIC_ARRAY].contains(self) {

0 commit comments

Comments
 (0)