Skip to main content

Module select

Module select 

Source
Expand description

Mods for sqlite::select.

Everything a SQLite SELECT can carry, and nothing else. There is no returning here, no fetch, no for_update, no distinct_on, no group_by_distinct and no _combined variant of anything — SQLite’s grammar has none of them, and a mod for a construct a dialect lacks should not exist.

use keelson_sqlite as sqlite;
use keelson_sqlite::{Chain, arg, quote, select};

let q = sqlite::select((
    select::columns((quote("id"), quote("name"))),
    select::from(quote("users")),
    select::where_(quote("age").gte(arg(21i32))),
    select::order_by(quote("name")).desc().nulls_last(),
    select::limit(10),
    select::offset(20),
));

§LIMIT and OFFSET are one clause

SQLite’s production is LIMIT expr [ ( OFFSET | , ) expr ], so offset without limit is not a statement. Building one records Error::Incomplete rather than handing back SQL the database will reject.

§VALUES is a SELECT

values and rows fill the other alternative of SQLite’s select-core, so sqlite::select(select::rows([[1, 2], [3, 4]])) is the statement VALUES (1, 2), (3, 4). Compounding a VALUES core onto a SELECT one — and the reverse — is legal and is how a recursive CTE’s seed row is usually written.

Re-exports§

pub use crate::shared::columns;
pub use crate::shared::cross_join;
pub use crate::shared::except;
pub use crate::shared::extra_from_item as from_also;
pub use crate::shared::from_item as from;
pub use crate::shared::full_join;
pub use crate::shared::group_by;
pub use crate::shared::having;
pub use crate::shared::inner_join;
pub use crate::shared::intersect;
pub use crate::shared::left_join;
pub use crate::shared::limit;
pub use crate::shared::offset;
pub use crate::shared::order_by;
pub use crate::shared::preload_columns;
pub use crate::shared::recursive;
pub use crate::shared::right_join;
pub use crate::shared::rows;
pub use crate::shared::union;
pub use crate::shared::union_all;
pub use crate::shared::values;
pub use crate::shared::where_;
pub use crate::shared::window;
pub use crate::shared::with;

Functions§

distinct
SELECT DISTINCT — drop duplicate result rows.