Skip to main content

toasty_core/stmt/
expr_incoming.rs

1use super::Expr;
2use crate::schema::{app::ModelId, db::TableId};
3
4/// The row proposed by an upsert's create branch.
5///
6/// Projecting a field from this expression references the proposed value rather
7/// than the value already stored in the conflicting row. SQL serializers map
8/// the projected expression to the backend's proposed-row syntax, such as
9/// PostgreSQL's `EXCLUDED` relation.
10#[derive(Clone, Debug, PartialEq)]
11pub enum ExprIncoming {
12    /// The proposed application-model row before lowering.
13    Model(ModelId),
14
15    /// The proposed database-table row after lowering.
16    Table(TableId),
17}
18
19impl ExprIncoming {
20    /// Creates an incoming application-model row.
21    pub fn model(model: ModelId) -> Self {
22        Self::Model(model)
23    }
24
25    /// Creates an incoming database-table row.
26    pub fn table(table: TableId) -> Self {
27        Self::Table(table)
28    }
29}
30
31impl From<ExprIncoming> for Expr {
32    fn from(value: ExprIncoming) -> Self {
33        Self::Incoming(value)
34    }
35}