Skip to content

Commit

Permalink
remove option on key
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragonliu2018 committed Dec 2, 2024
1 parent c0981d3 commit d47e600
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use crate::sql::IndexType;

macro_rules! sqlx_fetch_optional {
($pool:expr, $sql:expr, $key_type:ty, $val_type:ty, $format_val_fn:expr) => {{
let res: Option<(Option<$key_type>, Option<$val_type>)> =
let res: Option<($key_type, Option<$val_type>)> =
sqlx::query_as(&$sql).fetch_optional($pool).await?;
Ok(res.and_then(|(_, v)| v.map($format_val_fn)))
}};
Expand Down Expand Up @@ -95,53 +95,53 @@ macro_rules! fetch_all_rows_by_sqlx {
($pool:expr, $sql:expr, $key_scalar:expr, $val_type:ty, $format_key_fn:expr) => {
match $key_scalar {
DataType::Boolean => {
let res: Vec<(Option<bool>, Option<$val_type>)> =
let res: Vec<(bool, Option<$val_type>)> =
sqlx::query_as($sql).fetch_all($pool).await?;
res.into_iter()
.filter_map(|(key, val)| match (key, val) {
(Some(k), Some(v)) => Some(($format_key_fn(ScalarRef::Boolean(k)), v)),
(k, Some(v)) => Some(($format_key_fn(ScalarRef::Boolean(k)), v)),
_ => None,
})
.collect()
}
DataType::String => {
let res: Vec<(Option<String>, Option<$val_type>)> =
let res: Vec<(String, Option<$val_type>)> =
sqlx::query_as($sql).fetch_all($pool).await?;
res.into_iter()
.filter_map(|(key, val)| match (key, val) {
(Some(k), Some(v)) => Some(($format_key_fn(ScalarRef::String(&k)), v)),
(k, Some(v)) => Some(($format_key_fn(ScalarRef::String(&k)), v)),
_ => None,
})
.collect()
}
DataType::Number(num_ty) => {
with_integer_mapped_type!(|NUM_TYPE| match num_ty {
NumberDataType::NUM_TYPE => {
let res: Vec<(Option<NUM_TYPE>, Option<$val_type>)> =
let res: Vec<(NUM_TYPE, Option<$val_type>)> =
sqlx::query_as($sql).fetch_all($pool).await?;
res.into_iter()
.filter_map(|(key, val)| match (key, val) {
(Some(k), Some(v)) => Some((format!("{}", k), v)),
(k, Some(v)) => Some((format!("{}", k), v)),
_ => None,
})
.collect()
}
NumberDataType::Float32 => {
let res: Vec<(Option<f32>, Option<$val_type>)> =
let res: Vec<(f32, Option<$val_type>)> =
sqlx::query_as($sql).fetch_all($pool).await?;
res.into_iter()
.filter_map(|(key, val)| match (key, val) {
(Some(k), Some(v)) => Some((format!("{}", k), v)),
(k, Some(v)) => Some((format!("{}", k), v)),
_ => None,
})
.collect()
}
NumberDataType::Float64 => {
let res: Vec<(Option<f64>, Option<$val_type>)> =
let res: Vec<(f64, Option<$val_type>)> =
sqlx::query_as($sql).fetch_all($pool).await?;
res.into_iter()
.filter_map(|(key, val)| match (key, val) {
(Some(k), Some(v)) => Some((format!("{}", k), v)),
(k, Some(v)) => Some((format!("{}", k), v)),
_ => None,
})
.collect()
Expand Down

0 comments on commit d47e600

Please sign in to comment.