Skip to content

Commit

Permalink
support macaddr::MacAddr6 with Pg
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fenoll <[email protected]>
  • Loading branch information
fenollp committed May 23, 2023
1 parent 201e4b8 commit 48e524d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion diesel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ bitflags = { version = "2.0.0", optional = true }
r2d2 = { version = ">= 0.8.2, < 0.9.0", optional = true }
itoa = { version = "1.0.0", optional = true }
time = { version = "0.3.9", optional = true, features = ["macros"] }
macaddr = { version = "1.0.1", optional = true }

[dependencies.diesel_derives]
version = "~2.0.0"
Expand All @@ -47,7 +48,7 @@ quickcheck = "1.0.3"

[features]
default = ["with-deprecated", "32-column-tables"]
extras = ["chrono", "time", "serde_json", "uuid", "network-address", "numeric", "r2d2"]
extras = ["chrono", "time", "serde_json", "uuid", "network-address", "numeric", "r2d2", "macaddr"]
unstable = ["diesel_derives/nightly"]
large-tables = ["32-column-tables"]
huge-tables = ["64-column-tables"]
Expand Down
8 changes: 8 additions & 0 deletions diesel/src/pg/types/mac_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ fn macaddr_roundtrip() {
ToSql::<MacAddr, Pg>::to_sql(&input_address, &mut bytes).unwrap();
let output_address: [u8; 6] = FromSql::from_sql(PgValue::for_test(&buffer)).unwrap();
assert_eq!(input_address, output_address);

#[cfg(feature = "macaddr")]
{
use macaddr::MacAddr6;

let output_address: MacAddr6 = FromSql::from_sql(PgValue::for_test(&buffer)).unwrap();
assert_eq!(input_address, output_address);
}
}
12 changes: 12 additions & 0 deletions diesel_tests/tests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,12 @@ fn pg_macaddress_from_sql() {
expected_value,
query_single_value::<MacAddr, [u8; 6]>(query)
);

#[cfg(feature = "macaddr")]
assert_eq!(
expected_value,
query_single_value::<MacAddr, macaddr::MacAddr6>(query)
);
}

#[test]
Expand All @@ -1059,6 +1065,12 @@ fn pg_macaddress_to_sql_macaddress() {
expected_value,
value
));

#[cfg(feature = "macaddr")]
assert!(query_to_sql_equality::<MacAddr, macaddr::MacAddr6>(
expected_value,
value
));
}

#[test]
Expand Down

0 comments on commit 48e524d

Please sign in to comment.