Skip to main content

diesel/upsert/
mod.rs

1//! Types and functions related to PG's and Sqlite's `ON CONFLICT` clause
2//!
3//! Upsert is currently supported by diesel for the following database systems:
4//!
5//! * PostgreSQL version 9.5 or newer
6//! * Sqlite3 version 3.24.0 or newer
7//! * MySQL version 5.7 or newer
8//!
9//! See [the methods on `InsertStatement`](crate::query_builder::InsertStatement#impl-2)
10//! for usage examples.
11//!
12//! Constructing an upsert statement from an existing select statement
13//! requires a where clause on sqlite due to a ambiguity in their
14//! parser. See [the corresponding documentation](https://www.sqlite.org/lang_UPSERT.html)
15//! for details.
16pub(crate) use self::on_conflict_extension::OnConflictHelper;
17use crate::query_builder::upsert::on_conflict_actions::Excluded;
18
19mod on_conflict_extension;
20
21#[doc(inline)]
22pub use self::on_conflict_extension::{
23    DecoratableTarget, IncompleteDoUpdate, IncompleteOnConflict,
24};
25#[cfg(feature = "postgres_backend")]
26pub use crate::pg::query_builder::on_constraint::*;
27
28/// Represents `excluded.column` in an `ON CONFLICT DO UPDATE` clause,
29/// and `VALUES(column)` for MySQL and MariaDB.
30pub fn excluded<T>(excluded: T) -> Excluded<T> {
31    Excluded::new(excluded)
32}
33
34/// Reexports `excluded` as `values` for MySQL and MariaDB using
35/// `VALUES(column)`, which MySQL deprecates but whose replacement requires MySQL 8.0.19.
36#[cfg(any(feature = "mysql_backend", feature = "mariadb_backend"))]
37pub use excluded as values;