Fix merge conflict (#1386)

* Fix merge conflict

* remove unnecessary clone
This commit is contained in:
Billy Chan 2023-01-11 15:27:34 +08:00 committed by GitHub
parent f6e6e3d4e6
commit c49a8ac843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 42 deletions

View File

@ -538,38 +538,35 @@ macro_rules! try_getable_uuid {
( $type: ty, $conversion_fn: expr ) => { ( $type: ty, $conversion_fn: expr ) => {
#[allow(unused_variables, unreachable_code)] #[allow(unused_variables, unreachable_code)]
impl TryGetable for $type { impl TryGetable for $type {
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> { fn try_get_by<I: ColIdx>(res: &QueryResult, idx: I) -> Result<Self, TryGetError> {
let column = format!("{}{}", pre, col);
let res: Result<uuid::Uuid, TryGetError> = match &res.row { let res: Result<uuid::Uuid, TryGetError> = match &res.row {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
QueryResultRow::SqlxMySql(row) => { QueryResultRow::SqlxMySql(row) => {
use sqlx::Row; use sqlx::Row;
row.try_get::<Option<uuid::Uuid>, _>(column.as_str()) row.try_get::<Option<uuid::Uuid>, _>(idx.as_sqlx_mysql_index())
.map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e)))
.and_then(|opt| opt.ok_or(TryGetError::Null(column))) .and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx)))
} }
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
QueryResultRow::SqlxPostgres(row) => { QueryResultRow::SqlxPostgres(row) => {
use sqlx::Row; use sqlx::Row;
row.try_get::<Option<uuid::Uuid>, _>(column.as_str()) row.try_get::<Option<uuid::Uuid>, _>(idx.as_sqlx_postgres_index())
.map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e)))
.and_then(|opt| opt.ok_or(TryGetError::Null(column))) .and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx)))
} }
#[cfg(feature = "sqlx-sqlite")] #[cfg(feature = "sqlx-sqlite")]
QueryResultRow::SqlxSqlite(row) => { QueryResultRow::SqlxSqlite(row) => {
use sqlx::Row; use sqlx::Row;
row.try_get::<Option<uuid::Uuid>, _>(column.as_str()) row.try_get::<Option<uuid::Uuid>, _>(idx.as_sqlx_sqlite_index())
.map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e)))
.and_then(|opt| opt.ok_or(TryGetError::Null(column))) .and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx)))
} }
#[cfg(feature = "mock")] #[cfg(feature = "mock")]
#[allow(unused_variables)] #[allow(unused_variables)]
QueryResultRow::Mock(row) => { QueryResultRow::Mock(row) => row.try_get::<uuid::Uuid, _>(idx).map_err(|e| {
row.try_get::<uuid::Uuid>(column.as_str()).map_err(|e| { debug_print!("{:#?}", e.to_string());
debug_print!("{:#?}", e.to_string()); err_null_idx_col(idx)
TryGetError::Null(column) }),
})
}
#[allow(unreachable_patterns)] #[allow(unreachable_patterns)]
_ => unreachable!(), _ => unreachable!(),
}; };
@ -733,8 +730,7 @@ mod postgres_array {
( $type: ty, $conversion_fn: expr ) => { ( $type: ty, $conversion_fn: expr ) => {
#[allow(unused_variables, unreachable_code)] #[allow(unused_variables, unreachable_code)]
impl TryGetable for Vec<$type> { impl TryGetable for Vec<$type> {
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> { fn try_get_by<I: ColIdx>(res: &QueryResult, idx: I) -> Result<Self, TryGetError> {
let column = format!("{}{}", pre, col);
let res: Result<Vec<uuid::Uuid>, TryGetError> = match &res.row { let res: Result<Vec<uuid::Uuid>, TryGetError> = match &res.row {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
QueryResultRow::SqlxMySql(row) => { QueryResultRow::SqlxMySql(row) => {
@ -743,21 +739,21 @@ mod postgres_array {
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
QueryResultRow::SqlxPostgres(row) => { QueryResultRow::SqlxPostgres(row) => {
use sqlx::Row; use sqlx::Row;
row.try_get::<Option<Vec<uuid::Uuid>>, _>(column.as_str()) row.try_get::<Option<Vec<uuid::Uuid>>, _>(idx.as_sqlx_postgres_index())
.map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e)))
.and_then(|opt| opt.ok_or(TryGetError::Null(column))) .and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx)))
} }
#[cfg(feature = "sqlx-sqlite")] #[cfg(feature = "sqlx-sqlite")]
QueryResultRow::SqlxSqlite(_) => { QueryResultRow::SqlxSqlite(_) => {
panic!("{} unsupported by sqlx-sqlite", stringify!($type)) panic!("{} unsupported by sqlx-sqlite", stringify!($type))
} }
#[cfg(feature = "mock")] #[cfg(feature = "mock")]
QueryResultRow::Mock(row) => row QueryResultRow::Mock(row) => {
.try_get::<Vec<uuid::Uuid>>(column.as_str()) row.try_get::<Vec<uuid::Uuid>, _>(idx).map_err(|e| {
.map_err(|e| {
debug_print!("{:#?}", e.to_string()); debug_print!("{:#?}", e.to_string());
TryGetError::Null(column) err_null_idx_col(idx)
}), })
}
#[allow(unreachable_patterns)] #[allow(unreachable_patterns)]
_ => unreachable!(), _ => unreachable!(),
}; };

View File

@ -30,8 +30,8 @@ pub async fn insert_collection(db: &DatabaseConnection) -> Result<(), DbErr> {
teas_opt: Some(vec![Tea::BreakfastTea]), teas_opt: Some(vec![Tea::BreakfastTea]),
colors: vec![Color::Black], colors: vec![Color::Black],
colors_opt: Some(vec![Color::Black]), colors_opt: Some(vec![Color::Black]),
uuid: vec![uuid.clone()], uuid: vec![uuid],
uuid_hyphenated: vec![uuid.clone().hyphenated()], uuid_hyphenated: vec![uuid.hyphenated()],
} }
.into_active_model() .into_active_model()
.insert(db) .insert(db)
@ -44,8 +44,8 @@ pub async fn insert_collection(db: &DatabaseConnection) -> Result<(), DbErr> {
teas_opt: Some(vec![Tea::BreakfastTea]), teas_opt: Some(vec![Tea::BreakfastTea]),
colors: vec![Color::Black], colors: vec![Color::Black],
colors_opt: Some(vec![Color::Black]), colors_opt: Some(vec![Color::Black]),
uuid: vec![uuid.clone()], uuid: vec![uuid],
uuid_hyphenated: vec![uuid.clone().hyphenated()], uuid_hyphenated: vec![uuid.hyphenated()],
} }
); );
@ -58,8 +58,8 @@ pub async fn insert_collection(db: &DatabaseConnection) -> Result<(), DbErr> {
teas_opt: None, teas_opt: None,
colors: vec![Color::Black], colors: vec![Color::Black],
colors_opt: None, colors_opt: None,
uuid: vec![uuid.clone()], uuid: vec![uuid],
uuid_hyphenated: vec![uuid.clone().hyphenated()], uuid_hyphenated: vec![uuid.hyphenated()],
} }
.into_active_model() .into_active_model()
.insert(db) .insert(db)
@ -72,8 +72,8 @@ pub async fn insert_collection(db: &DatabaseConnection) -> Result<(), DbErr> {
teas_opt: None, teas_opt: None,
colors: vec![Color::Black], colors: vec![Color::Black],
colors_opt: None, colors_opt: None,
uuid: vec![uuid.clone()], uuid: vec![uuid],
uuid_hyphenated: vec![uuid.clone().hyphenated()], uuid_hyphenated: vec![uuid.hyphenated()],
} }
); );
@ -86,8 +86,8 @@ pub async fn insert_collection(db: &DatabaseConnection) -> Result<(), DbErr> {
teas_opt: Some(vec![]), teas_opt: Some(vec![]),
colors: vec![], colors: vec![],
colors_opt: Some(vec![]), colors_opt: Some(vec![]),
uuid: vec![uuid.clone()], uuid: vec![uuid],
uuid_hyphenated: vec![uuid.clone().hyphenated()], uuid_hyphenated: vec![uuid.hyphenated()],
} }
.into_active_model() .into_active_model()
.insert(db) .insert(db)
@ -100,8 +100,8 @@ pub async fn insert_collection(db: &DatabaseConnection) -> Result<(), DbErr> {
teas_opt: Some(vec![]), teas_opt: Some(vec![]),
colors: vec![], colors: vec![],
colors_opt: Some(vec![]), colors_opt: Some(vec![]),
uuid: vec![uuid.clone()], uuid: vec![uuid],
uuid_hyphenated: vec![uuid.clone().hyphenated()], uuid_hyphenated: vec![uuid.hyphenated()],
} }
); );
@ -134,8 +134,8 @@ pub async fn update_collection(db: &DatabaseConnection) -> Result<(), DbErr> {
teas_opt: Set(None), teas_opt: Set(None),
colors: Set(vec![Color::White]), colors: Set(vec![Color::White]),
colors_opt: Set(None), colors_opt: Set(None),
uuid: Set(vec![uuid.clone()]), uuid: Set(vec![uuid]),
uuid_hyphenated: Set(vec![uuid.clone().hyphenated()]), uuid_hyphenated: Set(vec![uuid.hyphenated()]),
} }
.update(db) .update(db)
.await?; .await?;

View File

@ -24,11 +24,11 @@ pub async fn insert_uuid_fmt(db: &DatabaseConnection) -> Result<(), DbErr> {
let uuid_fmt = uuid_fmt::Model { let uuid_fmt = uuid_fmt::Model {
id: 1, id: 1,
uuid: uuid.clone(), uuid: uuid,
uuid_braced: uuid.clone().braced(), uuid_braced: uuid.braced(),
uuid_hyphenated: uuid.clone().hyphenated(), uuid_hyphenated: uuid.hyphenated(),
uuid_simple: uuid.clone().simple(), uuid_simple: uuid.simple(),
uuid_urn: uuid.clone().urn(), uuid_urn: uuid.urn(),
}; };
let result = uuid_fmt.clone().into_active_model().insert(db).await?; let result = uuid_fmt.clone().into_active_model().insert(db).await?;