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>>
pub fn with_columns<T, C>( stmt: Statement, ) -> SelectorRaw<SelectGetableValue<T, C>>
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<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""#, []
)
)
.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 fn into_statement(self) -> Statement
pub fn into_statement(self) -> Statement
Get the SQL statement
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"#,
[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) -> 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""#,
[],
))
.all(&db)
.await?;
assert_eq!(
db.into_transaction_log(),
[Transaction::from_sql_and_values(
DbBackend::Postgres,
r#"SELECT "cake"."id", "cake"."name" FROM "cake""#,
[]
),]
);
Trait Implementationsยง
Sourceยงimpl<S> Clone for SelectorRaw<S>where
S: SelectorTrait + Clone,
impl<S> Clone for SelectorRaw<S>where
S: SelectorTrait + Clone,
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: SelectorTrait + Debug,
impl<S> Debug for SelectorRaw<S>where
S: SelectorTrait + Debug,
Sourceยงimpl<'db, C, S> PaginatorTrait<'db, C> for SelectorRaw<S>
impl<'db, C, S> PaginatorTrait<'db, C> for SelectorRaw<S>
Auto Trait Implementationsยง
impl<S> Freeze for SelectorRaw<S>where
S: Freeze,
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
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงunsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
๐ฌThis is a nightly-only experimental API. (
clone_to_uninit
)Sourceยงimpl<T> Instrument for T
impl<T> Instrument for T
Sourceยงfn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Sourceยงfn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more