Struct sea_orm::SelectorRaw
source · pub struct SelectorRaw<S>where
S: SelectorTrait,{ /* private fields */ }
Expand description
Performs a raw SELECT
operation on a model
Implementations
sourceimpl<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""#,
vec![],
))
.into_model::<SelectResult>()
.all(&db)
.await?;
assert_eq!(
res,
vec![
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(),
vec![Transaction::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."name", count("cake"."id") AS "num_of_cakes" FROM "cake""#,
vec![]
),]
);
sourcepub fn into_json(self) -> SelectorRaw<SelectModel<JsonValue>>
pub fn into_json(self) -> SelectorRaw<SelectModel<JsonValue>>
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""#, vec![]
)
)
.into_json()
.all(&db)
.await?;
assert_eq!(
res,
vec![
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(),
vec![
Transaction::from_sql_and_values(
DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake""#, vec![]
),
]);
sourcepub async fn one<'a, C>(self, db: &C) -> Result<Option<S::Item>, DbErr>where
C: ConnectionTrait,
pub async fn one<'a, C>(self, db: &C) -> Result<Option<S::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"#,
vec![1.into()],
))
.one(&db)
.await?;
assert_eq!(
db.into_transaction_log(),
vec![Transaction::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "id" = $1"#,
vec![1.into()]
),]
);
sourcepub async fn all<'a, C>(self, db: &C) -> Result<Vec<S::Item>, DbErr>where
C: ConnectionTrait,
pub async fn all<'a, C>(self, db: &C) -> Result<Vec<S::Item>, 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""#,
vec![],
))
.all(&db)
.await?;
assert_eq!(
db.into_transaction_log(),
vec![Transaction::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."id", "cake"."name" FROM "cake""#,
vec![]
),]
);
Trait Implementations
sourceimpl<S: Clone> Clone for SelectorRaw<S>where
S: SelectorTrait,
impl<S: Clone> Clone for SelectorRaw<S>where
S: SelectorTrait,
sourcefn clone(&self) -> SelectorRaw<S>
fn clone(&self) -> SelectorRaw<S>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl<S: Debug> Debug for SelectorRaw<S>where
S: SelectorTrait,
impl<S: Debug> Debug for SelectorRaw<S>where
S: SelectorTrait,
sourceimpl<'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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more