Struct scooby::postgres::statements::Select
source · pub struct Select { /* private fields */ }
Expand description
SELECT
statement, possibly with additional clauses.
Finalize and turn into String
by calling to_string
.
See select
docs for more details and examples.
Implementations§
source§impl Select
impl Select
sourcepub fn and_select(
self,
expressions: impl IntoIteratorOfSameType<Expression>
) -> Self
pub fn and_select( self, expressions: impl IntoIteratorOfSameType<Expression> ) -> Self
Add more expressions to be selected
use scooby::postgres::select;
let sql = select(("id", "name"))
.from("Person")
.and_select("age")
.and_select(("occupation_id", "city_id"))
.to_string();
assert_eq!(sql, "SELECT id, name, age, occupation_id, city_id FROM Person");
sourcepub fn all(self) -> Self
pub fn all(self) -> Self
Explicitly specify SELECT ALL
, i.e. non-distinct query
use scooby::postgres::select;
let sql = select("*").all().from("City").to_string();
assert_eq!(sql, "SELECT ALL * FROM City");
sourcepub fn distinct(self) -> Self
pub fn distinct(self) -> Self
Set a simple DISTINCT
clause
use scooby::postgres::select;
let sql = select("*").distinct().from("City").to_string();
assert_eq!(sql, "SELECT DISTINCT * FROM City");
sourcepub fn distinct_on(
self,
expressions: impl IntoIteratorOfSameType<Expression>
) -> Self
pub fn distinct_on( self, expressions: impl IntoIteratorOfSameType<Expression> ) -> Self
Set a DISTINCT ON (...)
clause
use scooby::postgres::select;
let sql = select("*").distinct_on("id").from("City").to_string();
assert_eq!(sql, "SELECT DISTINCT ON (id) * FROM City");
sourcepub fn from(self, from: impl IntoIteratorOfSameType<FromItem>) -> Self
pub fn from(self, from: impl IntoIteratorOfSameType<FromItem>) -> Self
Set or add more items in a FROM
clause
Import Joinable
for convenient joins.
You can pass subselects as well, so long as you make sure they’re aliased.
use scooby::postgres::select;
let sql = select("*").from("City").from(("Other", "Third")).to_string();
assert_eq!(sql, "SELECT * FROM City, Other, Third");
use scooby::postgres::{select, Joinable};
let sql = select("col1")
.from(
"Person p"
.inner_join("City c")
.on("c.id = p.city_id")
.left_join("Belonging b")
.on("p.id = b.person_id"),
)
.to_string();
assert_eq!(sql, "SELECT col1 FROM Person p INNER JOIN City c ON c.id = p.city_id LEFT JOIN Belonging b ON p.id = b.person_id");
use scooby::postgres::{select, Aliasable};
let sql = select("*")
.from(select("id").from("City").as_("x"))
.to_string();
assert_eq!(sql, "SELECT * FROM (SELECT id FROM City) AS x");
sourcepub fn where_(self, conditions: impl IntoIteratorOfSameType<Condition>) -> Self
pub fn where_(self, conditions: impl IntoIteratorOfSameType<Condition>) -> Self
Add one or more WHERE
conditions, AND
’ed together with themselves and existing conditions.
use scooby::postgres::select;
let sql = select("col1")
.from("Dummy")
.where_(("x > 1", "y > 1"))
.where_("z > 1")
.to_string();
assert_eq!(sql, "SELECT col1 FROM Dummy WHERE x > 1 AND y > 1 AND z > 1");
sourcepub fn group_by(
self,
groupings: impl IntoIteratorOfSameType<Expression>
) -> Self
pub fn group_by( self, groupings: impl IntoIteratorOfSameType<Expression> ) -> Self
Add one or more expressions in a GROUP BY
clause
use scooby::postgres::select;
let sql = select(("country_id", "COUNT(*)"))
.from("City")
.group_by("country_id")
.to_string();
assert_eq!(sql, "SELECT country_id, COUNT(*) FROM City GROUP BY country_id");
sourcepub fn having(self, conditions: impl IntoIteratorOfSameType<Condition>) -> Self
pub fn having(self, conditions: impl IntoIteratorOfSameType<Condition>) -> Self
Add one or more expressions in a HAVING
clause
use scooby::postgres::select;
let sql = select(("country_id", "COUNT(*)"))
.from("City")
.group_by("country_id")
.having("COUNT(*) > 10000")
.to_string();
assert_eq!(sql, "SELECT country_id, COUNT(*) FROM City GROUP BY country_id HAVING COUNT(*) > 10000");
sourcepub fn order_by(self, order_bys: impl IntoIteratorOfSameType<OrderBy>) -> Self
pub fn order_by(self, order_bys: impl IntoIteratorOfSameType<OrderBy>) -> Self
Set or add more sort expressions in an ORDER BY
clause.
Import Orderable
for convenient order specifications.
use scooby::postgres::select;
let sql = select("*").from("City").order_by("id").to_string();
assert_eq!(sql, "SELECT * FROM City ORDER BY id");
use scooby::postgres::{select, Orderable};
let sql = select("*")
.from("City")
.order_by(("last_modified".desc(), "id".desc()))
.to_string();
assert_eq!(sql, "SELECT * FROM City ORDER BY last_modified DESC, id DESC");
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Select
impl Send for Select
impl Sync for Select
impl Unpin for Select
impl UnwindSafe for Select
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