Function diesel:: expression:: dsl:: count_star
[−]
[src]
pub fn count_star() -> CountStar
Creates a SQL COUNT(*)
expression
For selecting the count of a query, and nothing else, you can just call
count
on the query instead.
As with most bare functions, this is not exported by default. You can import
it specifically as diesel::expression::count_star
, or glob import
diesel::expression::dsl::*
Example
#[macro_use] extern crate diesel;
include!("src/doctest_setup.rs");
use diesel::expression::dsl::*;
table! {
users {
id -> Serial,
name -> VarChar,
}
}
fn main() {
use self::users::dsl::*;
let connection = establish_connection();
assert_eq!(Ok(Some(2)), users.select(count_star()).first(&connection));