cargo fmt
This commit is contained in:
parent
937af05003
commit
b818138724
@ -1,4 +1,4 @@
|
||||
pub use super::cake::Entity as Cake;
|
||||
pub use super::cake_filling::Entity as CakeFilling;
|
||||
pub use super::filling::Entity as Filling;
|
||||
pub use super::fruit::Entity as Fruit;
|
||||
pub use super::fruit::Entity as Fruit;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use sea_orm::{entity::*, query::*, Database};
|
||||
use super::*;
|
||||
use sea_orm::{entity::*, query::*, Database};
|
||||
|
||||
pub async fn all_about_operation(db: &Database) -> Result<(), ExecErr> {
|
||||
insert_and_update(db).await?;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use sea_orm::{entity::*, query::*, Database, FromQueryResult};
|
||||
use super::*;
|
||||
use sea_orm::{entity::*, query::*, Database, FromQueryResult};
|
||||
|
||||
pub async fn all_about_select(db: &Database) -> Result<(), QueryErr> {
|
||||
find_all(db).await?;
|
||||
@ -66,10 +66,7 @@ async fn find_all(db: &Database) -> Result<(), QueryErr> {
|
||||
async fn find_together(db: &Database) -> Result<(), QueryErr> {
|
||||
print!("find cakes and fruits: ");
|
||||
|
||||
let both = Cake::find()
|
||||
.left_join_and_select(Fruit)
|
||||
.all(db)
|
||||
.await?;
|
||||
let both = Cake::find().left_join_and_select(Fruit).all(db).await?;
|
||||
|
||||
println!();
|
||||
for bb in both.iter() {
|
||||
@ -141,10 +138,7 @@ async fn count_fruits_by_cake(db: &Database) -> Result<(), QueryErr> {
|
||||
async fn find_many_to_many(db: &Database) -> Result<(), QueryErr> {
|
||||
print!("find cakes and fillings: ");
|
||||
|
||||
let both = Cake::find()
|
||||
.left_join_and_select(Filling)
|
||||
.all(db)
|
||||
.await?;
|
||||
let both = Cake::find().left_join_and_select(Filling).all(db).await?;
|
||||
|
||||
println!();
|
||||
for bb in both.iter() {
|
||||
@ -246,9 +240,9 @@ async fn count_fruits_by_cake_json(db: &Database) -> Result<(), QueryErr> {
|
||||
}
|
||||
|
||||
async fn find_all_stream(db: &Database) -> Result<(), QueryErr> {
|
||||
use async_std::task::sleep;
|
||||
use futures::TryStreamExt;
|
||||
use std::time::Duration;
|
||||
use async_std::task::sleep;
|
||||
|
||||
println!("find all cakes: ");
|
||||
let mut cake_paginator = cake::Entity::find().paginate(db, 2);
|
||||
@ -279,7 +273,10 @@ async fn find_all_stream(db: &Database) -> Result<(), QueryErr> {
|
||||
|
||||
println!();
|
||||
println!("find all fruits in json with stream: ");
|
||||
let mut json_stream = fruit::Entity::find().into_json().paginate(db, 2).into_stream();
|
||||
let mut json_stream = fruit::Entity::find()
|
||||
.into_json()
|
||||
.paginate(db, 2)
|
||||
.into_stream();
|
||||
while let Some(jsons) = json_stream.try_next().await? {
|
||||
for json in jsons {
|
||||
println!("{:?}", json);
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::{Connection, Database, QueryErr, SelectorTrait};
|
||||
use futures::Stream;
|
||||
use async_stream::stream;
|
||||
use std::{marker::PhantomData, pin::Pin};
|
||||
use futures::Stream;
|
||||
use sea_query::{Alias, Expr, SelectStatement};
|
||||
use std::{marker::PhantomData, pin::Pin};
|
||||
|
||||
pub type PinBoxStream<'db, Item> = Pin<Box<dyn Stream<Item = Item> + 'db>>;
|
||||
|
||||
@ -23,7 +23,9 @@ where
|
||||
S: SelectorTrait + 'db,
|
||||
{
|
||||
pub async fn fetch_page(&mut self, page: usize) -> Result<Vec<S::Item>, QueryErr> {
|
||||
self.query.limit(self.page_size as u64).offset((self.page_size * page) as u64);
|
||||
self.query
|
||||
.limit(self.page_size as u64)
|
||||
.offset((self.page_size * page) as u64);
|
||||
let builder = self.db.get_query_builder_backend();
|
||||
let stmt = self.query.build(builder).into();
|
||||
let rows = self.db.get_connection().query_all(stmt).await?;
|
||||
@ -45,7 +47,7 @@ where
|
||||
.expr(Expr::cust("COUNT(*) AS num_rows"))
|
||||
.from_subquery(
|
||||
self.query.clone().reset_limit().reset_offset().to_owned(),
|
||||
Alias::new("sub_query")
|
||||
Alias::new("sub_query"),
|
||||
)
|
||||
.build(builder)
|
||||
.into();
|
||||
@ -53,7 +55,9 @@ where
|
||||
Some(res) => res,
|
||||
None => return Ok(0),
|
||||
};
|
||||
let num_rows = result.try_get::<i32>("", "num_rows").map_err(|_e| QueryErr)? as usize;
|
||||
let num_rows = result
|
||||
.try_get::<i32>("", "num_rows")
|
||||
.map_err(|_e| QueryErr)? as usize;
|
||||
let num_pages = (num_rows / self.page_size) + (num_rows % self.page_size > 0) as usize;
|
||||
Ok(num_pages)
|
||||
}
|
||||
@ -65,11 +69,7 @@ where
|
||||
pub async fn fetch_and_next(&mut self) -> Result<Option<Vec<S::Item>>, QueryErr> {
|
||||
let vec = self.fetch().await?;
|
||||
self.next();
|
||||
let opt = if !vec.is_empty() {
|
||||
Some(vec)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let opt = if !vec.is_empty() { Some(vec) } else { None };
|
||||
Ok(opt)
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
use crate::{Connection, Database, EntityTrait, FromQueryResult, JsonValue, Paginator, QueryErr, QueryResult, Select, SelectTwo, Statement, TypeErr, query::combine};
|
||||
use crate::{
|
||||
query::combine, Connection, Database, EntityTrait, FromQueryResult, JsonValue, Paginator,
|
||||
QueryErr, QueryResult, Select, SelectTwo, Statement, TypeErr,
|
||||
};
|
||||
use sea_query::{QueryBuilder, SelectStatement};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
@ -89,7 +92,11 @@ where
|
||||
self.into_model::<E::Model>().all(db).await
|
||||
}
|
||||
|
||||
pub fn paginate<'db>(self, db: &'db Database, page_size: usize) -> Paginator<'db, SelectModel<E::Model>> {
|
||||
pub fn paginate<'db>(
|
||||
self,
|
||||
db: &'db Database,
|
||||
page_size: usize,
|
||||
) -> Paginator<'db, SelectModel<E::Model>> {
|
||||
self.into_model::<E::Model>().paginate(db, page_size)
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,10 @@ impl FromQueryResult for JsonValue {
|
||||
macro_rules! match_mysql_type {
|
||||
( $type: ty ) => {
|
||||
if <$type as Type<MySql>>::type_info().eq(col_type) {
|
||||
map.insert(col.to_owned(), json!(res.try_get::<Option<$type>>(pre, &col)?));
|
||||
map.insert(
|
||||
col.to_owned(),
|
||||
json!(res.try_get::<Option<$type>>(pre, &col)?),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user