Skip to content

Commit

Permalink
sqlx-core: impl Type for Cow<str> on Mssql, MySql, and Sqlite (#1757)
Browse files Browse the repository at this point in the history
  • Loading branch information
ipetkov authored Mar 23, 2022
1 parent 78dc0ad commit 1af26d8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sqlx-core/src/mssql/types/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ impl Decode<'_, Mssql> for String {
}
}

impl Type<Mssql> for Cow<'_, str> {
fn type_info() -> MssqlTypeInfo {
<&str as Type<Mssql>>::type_info()
}

fn compatible(ty: &MssqlTypeInfo) -> bool {
<&str as Type<Mssql>>::compatible(ty)
}
}

impl Encode<'_, Mssql> for Cow<'_, str> {
fn produces(&self) -> Option<MssqlTypeInfo> {
match self {
Expand Down
10 changes: 10 additions & 0 deletions sqlx-core/src/mysql/types/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ impl Decode<'_, MySql> for String {
}
}

impl Type<MySql> for Cow<'_, str> {
fn type_info() -> MySqlTypeInfo {
<&str as Type<MySql>>::type_info()
}

fn compatible(ty: &MySqlTypeInfo) -> bool {
<&str as Type<MySql>>::compatible(ty)
}
}

impl Encode<'_, MySql> for Cow<'_, str> {
fn encode_by_ref(&self, buf: &mut Vec<u8>) -> IsNull {
match self {
Expand Down
10 changes: 10 additions & 0 deletions sqlx-core/src/sqlite/types/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ impl<'r> Decode<'r, Sqlite> for String {
}
}

impl Type<Sqlite> for Cow<'_, str> {
fn type_info() -> SqliteTypeInfo {
<&str as Type<Sqlite>>::type_info()
}

fn compatible(ty: &SqliteTypeInfo) -> bool {
<&str as Type<Sqlite>>::compatible(ty)
}
}

impl<'q> Encode<'q, Sqlite> for Cow<'q, str> {
fn encode(self, args: &mut Vec<SqliteArgumentValue<'q>>) -> IsNull {
args.push(SqliteArgumentValue::Text(self));
Expand Down

0 comments on commit 1af26d8

Please sign in to comment.