mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-21 09:34:02 +00:00
Add Simple format for Uuid for MySQL & SQLite. (#2469)
* Add Simple format for Uuid for MySQL & SQLite. Copy pasted the implementation for `Hyphenated` and adapt. * Add uuid Simple docs for SQLite
This commit is contained in:
@@ -62,6 +62,7 @@
|
||||
//! |---------------------------------------|------------------------------------------------------|
|
||||
//! | `uuid::Uuid` | BLOB, TEXT |
|
||||
//! | `uuid::fmt::Hyphenated` | TEXT |
|
||||
//! | `uuid::fmt::Simple` | TEXT |
|
||||
//!
|
||||
//! ### [`json`](https://crates.io/crates/serde_json)
|
||||
//!
|
||||
|
||||
@@ -5,7 +5,10 @@ use crate::type_info::DataType;
|
||||
use crate::types::Type;
|
||||
use crate::{Sqlite, SqliteArgumentValue, SqliteTypeInfo, SqliteValueRef};
|
||||
use std::borrow::Cow;
|
||||
use uuid::{fmt::Hyphenated, Uuid};
|
||||
use uuid::{
|
||||
fmt::{Hyphenated, Simple},
|
||||
Uuid,
|
||||
};
|
||||
|
||||
impl Type<Sqlite> for Uuid {
|
||||
fn type_info() -> SqliteTypeInfo {
|
||||
@@ -56,3 +59,26 @@ impl Decode<'_, Sqlite> for Hyphenated {
|
||||
Ok(uuid?.hyphenated())
|
||||
}
|
||||
}
|
||||
|
||||
impl Type<Sqlite> for Simple {
|
||||
fn type_info() -> SqliteTypeInfo {
|
||||
SqliteTypeInfo(DataType::Text)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'q> Encode<'q, Sqlite> for Simple {
|
||||
fn encode_by_ref(&self, args: &mut Vec<SqliteArgumentValue<'q>>) -> IsNull {
|
||||
args.push(SqliteArgumentValue::Text(Cow::Owned(self.to_string())));
|
||||
|
||||
IsNull::No
|
||||
}
|
||||
}
|
||||
|
||||
impl Decode<'_, Sqlite> for Simple {
|
||||
fn decode(value: SqliteValueRef<'_>) -> Result<Self, BoxDynError> {
|
||||
let uuid: Result<Uuid, BoxDynError> =
|
||||
Uuid::parse_str(&value.text().map(ToOwned::to_owned)?).map_err(Into::into);
|
||||
|
||||
Ok(uuid?.simple())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user