diff --git a/diesel/src/type_impls/primitives.rs b/diesel/src/type_impls/primitives.rs index 7969f963a0e4..470ffdd06b14 100644 --- a/diesel/src/type_impls/primitives.rs +++ b/diesel/src/type_impls/primitives.rs @@ -114,6 +114,11 @@ mod foreign_impls { #[diesel(foreign_derive, not_sized)] #[diesel(sql_type = Binary)] struct BinarySliceProxy([u8]); + + #[derive(AsExpression)] + #[diesel(foreign_derive)] + #[diesel(sql_type = Binary)] + struct BinaryArrayProxy([u8; N]); } impl FromSql for String @@ -175,6 +180,16 @@ where } } +impl ToSql for [u8; N] +where + DB: Backend, + [u8]: ToSql, +{ + fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, DB>) -> serialize::Result { + self.as_slice().to_sql(out) + } +} + impl ToSql for [u8] where for<'a> DB: Backend = RawBytesBindCollector>, diff --git a/diesel_tests/tests/types.rs b/diesel_tests/tests/types.rs index a661b0d36d1b..1e6c42108513 100644 --- a/diesel_tests/tests/types.rs +++ b/diesel_tests/tests/types.rs @@ -610,6 +610,7 @@ fn binary_from_sql() { #[cfg(feature = "postgres")] fn bytes_to_sql_binary() { let invalid_utf8_bytes = vec![0x1Fu8, 0x8Bu8]; + let invalid_utf8_array = [0x1Fu8, 0x8Bu8]; assert!(query_to_sql_equality::>( "E'\\\\x1F8B'::bytea", invalid_utf8_bytes.clone() @@ -618,6 +619,10 @@ fn bytes_to_sql_binary() { "E'\\\\x1F8B'::bytea", &invalid_utf8_bytes )); + assert!(query_to_sql_equality::( + "E'\\\\x1F8B'::bytea", + &invalid_utf8_array + )); assert!(!query_to_sql_equality::( "''::bytea", &invalid_utf8_bytes