This commit is contained in:
Chris Tsang 2021-05-27 02:31:47 +08:00
parent 99a1fe01fc
commit 007d27768d

View File

@ -91,32 +91,38 @@ where
} }
} }
macro_rules! select_query {
() => {
/// Get a mutable ref to the query builder
pub fn query(&mut self) -> &mut SelectStatement {
&mut self.query
}
/// Get an immutable ref to the query builder
pub fn as_query(&self) -> &SelectStatement {
&self.query
}
/// Take ownership of the query builder
pub fn into_query(self) -> SelectStatement {
self.query
}
/// Build the query as [`Statement`]
pub fn build<B>(&self, builder: B) -> Statement
where
B: QueryBuilder,
{
self.as_query().build(builder).into()
}
};
}
impl<E> Select<E> impl<E> Select<E>
where where
E: EntityTrait, E: EntityTrait,
{ {
/// Get a mutable ref to the query builder select_query!();
pub fn query(&mut self) -> &mut SelectStatement {
&mut self.query
}
/// Get an immutable ref to the query builder
pub fn as_query(&self) -> &SelectStatement {
&self.query
}
/// Take ownership of the query builder
pub fn into_query(self) -> SelectStatement {
self.query
}
/// Build the query as [`Statement`]
pub fn build<B>(&self, builder: B) -> Statement
where
B: QueryBuilder,
{
self.as_query().build(builder).into()
}
} }
impl<E, F> SelectTwo<E, F> impl<E, F> SelectTwo<E, F>
@ -124,26 +130,5 @@ where
E: EntityTrait, E: EntityTrait,
F: EntityTrait, F: EntityTrait,
{ {
/// Get a mutable ref to the query builder select_query!();
pub fn query(&mut self) -> &mut SelectStatement {
&mut self.query
}
/// Get an immutable ref to the query builder
pub fn as_query(&self) -> &SelectStatement {
&self.query
}
/// Take ownership of the query builder
pub fn into_query(self) -> SelectStatement {
self.query
}
/// Build the query as [`Statement`]
pub fn build<B>(&self, builder: B) -> Statement
where
B: QueryBuilder,
{
self.as_query().build(builder).into()
}
} }