cargo fmt
This commit is contained in:
parent
cd439fe4df
commit
92f1c012d2
@ -43,9 +43,7 @@ where
|
||||
|
||||
#[cfg(feature = "with-json")]
|
||||
pub fn as_json(self) -> SelectJson {
|
||||
SelectJson {
|
||||
query: self.query,
|
||||
}
|
||||
SelectJson { query: self.query }
|
||||
}
|
||||
|
||||
pub async fn one(self, db: &Database) -> Result<E::Model, QueryErr> {
|
||||
@ -75,9 +73,7 @@ where
|
||||
|
||||
#[cfg(feature = "with-json")]
|
||||
pub fn as_json(self) -> SelectTwoJson {
|
||||
SelectTwoJson {
|
||||
query: self.query,
|
||||
}
|
||||
SelectTwoJson { query: self.query }
|
||||
}
|
||||
|
||||
pub async fn one(self, db: &Database) -> Result<(E::Model, F::Model), QueryErr> {
|
||||
|
@ -20,7 +20,11 @@ impl SelectJson {
|
||||
let builder = db.get_query_builder_backend();
|
||||
self.query.limit(1);
|
||||
// TODO: Error handling
|
||||
db.get_connection().query_one(self.build(builder)).await?.as_json("").map_err(|_e| QueryErr)
|
||||
db.get_connection()
|
||||
.query_one(self.build(builder))
|
||||
.await?
|
||||
.as_json("")
|
||||
.map_err(|_e| QueryErr)
|
||||
}
|
||||
|
||||
pub async fn all(self, db: &Database) -> Result<JsonValue, QueryErr> {
|
||||
|
@ -78,14 +78,14 @@ impl QueryResult {
|
||||
|
||||
#[cfg(feature = "with-json")]
|
||||
pub fn as_json(&self, pre: &str) -> Result<serde_json::Value, TypeErr> {
|
||||
use serde_json::{Value, Map, json};
|
||||
use serde_json::{json, Map, Value};
|
||||
match &self.row {
|
||||
QueryResultRow::SqlxMySql(row) => {
|
||||
use sqlx::{Row, Column, Type, MySql};
|
||||
use sqlx::{Column, MySql, Row, Type};
|
||||
let mut map = Map::new();
|
||||
for column in row.columns() {
|
||||
let col = if !column.name().starts_with(pre) {
|
||||
continue
|
||||
continue;
|
||||
} else {
|
||||
column.name().replacen(pre, "", 1)
|
||||
};
|
||||
@ -93,8 +93,11 @@ impl QueryResult {
|
||||
macro_rules! match_mysql_type {
|
||||
( $type: ty ) => {
|
||||
if <$type as Type<MySql>>::type_info().eq(col_type) {
|
||||
map.insert(col.to_owned(), json!(self.try_get::<$type>(pre, &col)?));
|
||||
continue
|
||||
map.insert(
|
||||
col.to_owned(),
|
||||
json!(self.try_get::<$type>(pre, &col)?),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -112,7 +115,7 @@ impl QueryResult {
|
||||
match_mysql_type!(String);
|
||||
}
|
||||
Ok(Value::Object(map))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user