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