From 0756ef0e5919b73321b0b24502633f399095e4ee Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Tue, 23 Feb 2021 01:55:09 -0800 Subject: [PATCH] refactor(mysql): remove binary type IDs --- sqlx-mysql/src/type_id.rs | 24 ++++++++---------------- sqlx-mysql/src/type_info.rs | 6 +++--- sqlx-mysql/src/types/bytes.rs | 4 ++-- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/sqlx-mysql/src/type_id.rs b/sqlx-mysql/src/type_id.rs index c5344db1..93f41100 100644 --- a/sqlx-mysql/src/type_id.rs +++ b/sqlx-mysql/src/type_id.rs @@ -176,33 +176,24 @@ impl MySqlTypeId { /// pub const NULL: Self = Self(6, 0); - /// A fixed-length string that is always right-padded with spaces - /// to the specified length when stored. - /// - pub const CHAR: Self = Self(254, 0); - - /// A fixed-length binary string that is always right-padded with zeroes - /// to the specified length when stored. + /// A fixed-length string that is always right-padded with spaces or + /// zeroes (for binary collations) to the specified length when stored. /// /// The type identifier for `BINARY` is the same as `CHAR`. At the type /// level, they are identical. At the column, the presence of a binary (`_bin`) /// collation determines if the type stores binary data. /// - pub const BINARY: Self = Self(254, 0); + #[doc(alias = "BINARY")] + pub const CHAR: Self = Self(254, 0); /// A variable-length string. - pub const VARCHAR: Self = Self(253, 0); - - /// A variable-length binary string. /// /// The type identifier for `VARBINARY` is the same as `VARCHAR`. At the type /// level, they are identical. At the column, the presence of a binary (`_bin`) /// collation determines if the type stores binary data. /// - pub const VARBINARY: Self = Self(253, 0); - - /// A variable-length string that is assumed to be stored by reference. - pub const TEXT: Self = Self(252, 0); + #[doc(alias = "VARBINARY")] + pub const VARCHAR: Self = Self(253, 0); /// A variable-length string that is assumed to be stored by reference. /// @@ -210,5 +201,6 @@ impl MySqlTypeId { /// level, they are identical. At the column, the presence of a binary (`_bin`) /// collation determines if the type stores binary data. /// - pub const BLOB: Self = Self(252, 0); + #[doc(alias = "BLOB")] + pub const TEXT: Self = Self(252, 0); } diff --git a/sqlx-mysql/src/type_info.rs b/sqlx-mysql/src/type_info.rs index 898777e0..aaa96639 100644 --- a/sqlx-mysql/src/type_info.rs +++ b/sqlx-mysql/src/type_info.rs @@ -67,9 +67,9 @@ impl MySqlTypeInfo { // note: VARBINARY, BINARY, and BLOB have the same type IDs as // VARCHAR, CHAR, and TEXT; the only difference is the // presence of a binary collation - MySqlTypeId::VARBINARY if self.has_binary_collation() => "VARBINARY", - MySqlTypeId::BINARY if self.has_binary_collation() => "BINARY", - MySqlTypeId::BLOB if self.has_binary_collation() => "BLOB", + MySqlTypeId::VARCHAR if self.has_binary_collation() => "VARBINARY", + MySqlTypeId::CHAR if self.has_binary_collation() => "BINARY", + MySqlTypeId::TEXT if self.has_binary_collation() => "BLOB", MySqlTypeId::VARCHAR => "VARCHAR", MySqlTypeId::CHAR => "CHAR", diff --git a/sqlx-mysql/src/types/bytes.rs b/sqlx-mysql/src/types/bytes.rs index 873a4c1e..a0b96097 100644 --- a/sqlx-mysql/src/types/bytes.rs +++ b/sqlx-mysql/src/types/bytes.rs @@ -7,11 +7,11 @@ use crate::{MySql, MySqlOutput, MySqlRawValue, MySqlTypeId}; impl Type for &'_ [u8] { fn type_id() -> MySqlTypeId { - MySqlTypeId::BLOB + MySqlTypeId::TEXT } fn compatible(ty: &MySqlTypeInfo) -> bool { - matches!(ty.id(), MySqlTypeId::BLOB | MySqlTypeId::BINARY | MySqlTypeId::VARBINARY) + matches!(ty.id(), MySqlTypeId::TEXT | MySqlTypeId::CHAR | MySqlTypeId::VARCHAR) } }