keelson-psql 0.1.1

The PostgreSQL dialect for keelson.
Documentation
//! Mods for [`psql::insert`](crate::insert()).
//!
//! ```
//! use keelson_psql as psql;
//! use keelson_psql::{arg, insert};
//!
//! let q = psql::insert((
//!     insert::into("users").columns(["id", "name"]),
//!     insert::values((arg(1i32), arg("ada"))),
//!     insert::on_conflict("id").do_update(insert::set_excluded(["name"])),
//!     insert::returning("*"),
//! ));
//! ```
//!
//! # The mods that are not for the `INSERT` itself
//!
//! [`set`], [`set_col`], [`set_excluded`] and [`where_`] apply to a
//! [`ConflictClause`](keelson_core::clause::ConflictClause), not to an
//! `InsertQuery` — an `INSERT` has no `SET` and no `WHERE`. They are here because
//! this is where they are used: inside
//! [`on_conflict(..).do_update(..)`](crate::shared::ConflictChain::do_update). An
//! `InsertQuery` does not implement the traits they need, so misplacing one is a
//! compile error rather than a surprise.
//!
//! The two `WHERE`s of an `ON CONFLICT` are easy to conflate and behave nothing
//! alike: `on_conflict(..).where_(..)` is the *index* predicate, matched against a
//! partial unique index's own definition, while [`where_`] inside `do_update`
//! filters which conflicting rows are updated.

use keelson_core::{Mod, mod_fn};

use crate::extras::Overriding;
use crate::statement::InsertQuery;

pub use crate::shared::{
    from_item as into, on_conflict, on_conflict_on_constraint, recursive, returning, rows, set,
    set_col, set_excluded, values, values_from_query as query, where_, with,
};

/// `OVERRIDING SYSTEM VALUE` — write the supplied value into a
/// `GENERATED ALWAYS AS IDENTITY` column, which otherwise refuses one.
pub fn overriding_system() -> impl Mod<InsertQuery> {
    mod_fn(|q: &mut InsertQuery| q.overriding = Some(Overriding::System))
}

/// `OVERRIDING USER VALUE` — ignore the supplied value and take the sequence's,
/// for a `GENERATED BY DEFAULT AS IDENTITY` column.
pub fn overriding_user() -> impl Mod<InsertQuery> {
    mod_fn(|q: &mut InsertQuery| q.overriding = Some(Overriding::User))
}