Struct leetcode_tui_rs::migrations::sea_orm::SelectorRaw
source · pub struct SelectorRaw<S>where
S: SelectorTrait,{ /* private fields */ }
Expand description
Performs a raw SELECT
operation on a model
Implementations§
source§impl<S> SelectorRaw<S>where
S: SelectorTrait,
impl<S> SelectorRaw<S>where S: SelectorTrait,
sourcepub fn from_statement<M>(stmt: Statement) -> SelectorRaw<SelectModel<M>>where
M: FromQueryResult,
pub fn from_statement<M>(stmt: Statement) -> SelectorRaw<SelectModel<M>>where M: FromQueryResult,
Select a custom Model from a raw SQL Statement.
sourcepub fn with_columns<T, C>(
stmt: Statement
) -> SelectorRaw<SelectGetableValue<T, C>>where
T: TryGetableMany,
C: IntoEnumIterator + Iden,
pub fn with_columns<T, C>( stmt: Statement ) -> SelectorRaw<SelectGetableValue<T, C>>where T: TryGetableMany, C: IntoEnumIterator + Iden,
Create SelectorRaw
from Statement and columns. Executing this SelectorRaw
will
return a type T
which implement TryGetableMany
.
sourcepub fn into_model<M>(self) -> SelectorRaw<SelectModel<M>>where
M: FromQueryResult,
pub fn into_model<M>(self) -> SelectorRaw<SelectModel<M>>where M: FromQueryResult,
use sea_orm::{entity::*, query::*, tests_cfg::cake, FromQueryResult};
#[derive(Debug, PartialEq, FromQueryResult)]
struct SelectResult {
name: String,
num_of_cakes: i32,
}
let res: Vec<SelectResult> = cake::Entity::find()
.from_raw_sql(Statement::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."name", count("cake"."id") AS "num_of_cakes" FROM "cake""#,
[],
))
.into_model::<SelectResult>()
.all(&db)
.await?;
assert_eq!(
res,
[
SelectResult {
name: "Chocolate Forest".to_owned(),
num_of_cakes: 1,
},
SelectResult {
name: "New York Cheese".to_owned(),
num_of_cakes: 1,
},
]
);
assert_eq!(
db.into_transaction_log(),
[Transaction::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."name", count("cake"."id") AS "num_of_cakes" FROM "cake""#,
[]
),]
);
sourcepub fn into_json(self) -> SelectorRaw<SelectModel<Value>>
pub fn into_json(self) -> SelectorRaw<SelectModel<Value>>
use sea_orm::{entity::*, query::*, tests_cfg::cake};
let res: Vec<serde_json::Value> = cake::Entity::find().from_raw_sql(
Statement::from_sql_and_values(
DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake""#, []
)
)
.into_json()
.all(&db)
.await?;
assert_eq!(
res,
[
serde_json::json!({
"name": "Chocolate Forest",
"num_of_cakes": 1,
}),
serde_json::json!({
"name": "New York Cheese",
"num_of_cakes": 1,
}),
]
);
assert_eq!(
db.into_transaction_log(),
[
Transaction::from_sql_and_values(
DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake""#, []
),
]);
sourcepub async fn one<'a, C>(
self,
db: &C
) -> impl Future<Output = Result<Option<<S as SelectorTrait>::Item>, DbErr>>where
C: ConnectionTrait,
pub async fn one<'a, C>( self, db: &C ) -> impl Future<Output = Result<Option<<S as SelectorTrait>::Item>, DbErr>>where C: ConnectionTrait,
Get an item from the Select query
use sea_orm::{entity::*, query::*, tests_cfg::cake};
let _: Option<cake::Model> = cake::Entity::find()
.from_raw_sql(Statement::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "id" = $1"#,
[1.into()],
))
.one(&db)
.await?;
assert_eq!(
db.into_transaction_log(),
[Transaction::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "id" = $1"#,
[1.into()]
),]
);
sourcepub async fn all<'a, C>(
self,
db: &C
) -> impl Future<Output = Result<Vec<<S as SelectorTrait>::Item, Global>, DbErr>>where
C: ConnectionTrait,
pub async fn all<'a, C>( self, db: &C ) -> impl Future<Output = Result<Vec<<S as SelectorTrait>::Item, Global>, DbErr>>where C: ConnectionTrait,
Get all items from the Select query
use sea_orm::{entity::*, query::*, tests_cfg::cake};
let _: Vec<cake::Model> = cake::Entity::find()
.from_raw_sql(Statement::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."id", "cake"."name" FROM "cake""#,
[],
))
.all(&db)
.await?;
assert_eq!(
db.into_transaction_log(),
[Transaction::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."id", "cake"."name" FROM "cake""#,
[]
),]
);
sourcepub async fn stream<'a, 'b, C>(
self,
db: &'a C
) -> impl Future<Output = Result<Pin<Box<dyn Stream<Item = Result<<S as SelectorTrait>::Item, DbErr>> + Send + 'b, Global>>, DbErr>>where
'a: 'b,
C: ConnectionTrait + StreamTrait + Send,
S: 'b,
<S as SelectorTrait>::Item: Send,
pub async fn stream<'a, 'b, C>( self, db: &'a C ) -> impl Future<Output = Result<Pin<Box<dyn Stream<Item = Result<<S as SelectorTrait>::Item, DbErr>> + Send + 'b, Global>>, DbErr>>where 'a: 'b, C: ConnectionTrait + StreamTrait + Send, S: 'b, <S as SelectorTrait>::Item: Send,
Stream the results of the Select operation
Trait Implementations§
source§impl<S> Clone for SelectorRaw<S>where
S: Clone + SelectorTrait,
impl<S> Clone for SelectorRaw<S>where S: Clone + SelectorTrait,
source§fn clone(&self) -> SelectorRaw<S>
fn clone(&self) -> SelectorRaw<S>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<S> Debug for SelectorRaw<S>where
S: Debug + SelectorTrait,
impl<S> Debug for SelectorRaw<S>where S: Debug + SelectorTrait,
source§impl<'db, C, S> PaginatorTrait<'db, C> for SelectorRaw<S>where
C: ConnectionTrait,
S: SelectorTrait + Send + Sync + 'db,
impl<'db, C, S> PaginatorTrait<'db, C> for SelectorRaw<S>where C: ConnectionTrait, S: SelectorTrait + Send + Sync + 'db,
Auto Trait Implementations§
impl<S> RefUnwindSafe for SelectorRaw<S>where S: RefUnwindSafe,
impl<S> Send for SelectorRaw<S>where S: Send,
impl<S> Sync for SelectorRaw<S>where S: Sync,
impl<S> Unpin for SelectorRaw<S>where S: Unpin,
impl<S> UnwindSafe for SelectorRaw<S>where S: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more