pub enum InsertTarget {
Scope(Box<Query>),
Model(ModelId),
Table(InsertTable),
}Expand description
The target of an Insert statement.
Specifies where new records should be inserted. At the model level this is typically a model ID or a scoped query. After lowering, it becomes a table with column mappings.
§Examples
use toasty_core::stmt::InsertTarget;
use toasty_core::schema::app::ModelId;
let target = InsertTarget::Model(ModelId(0));
assert!(target.is_model());
assert!(!target.is_table());Variants§
Scope(Box<Query>)
Insert into a scoped query. The inserted value should satisfy the query’s filter, which may set default field values or validate existing ones.
Model(ModelId)
Insert a model by its ID.
Table(InsertTable)
Insert into a database table (lowered form).
Implementations§
Source§impl InsertTarget
impl InsertTarget
Sourcepub fn model_id_unwrap(&self) -> ModelId
pub fn model_id_unwrap(&self) -> ModelId
Returns the model ID for this target.
For Scope targets, extracts the model ID from the inner query’s
select source.
§Panics
Panics if this is a Table variant.
Sourcepub fn as_table(&self) -> Option<&InsertTable>
pub fn as_table(&self) -> Option<&InsertTable>
Returns a reference to the inner InsertTable if this is a Table
variant.
Sourcepub fn as_table_unwrap(&self) -> &InsertTable
pub fn as_table_unwrap(&self) -> &InsertTable
Sourcepub fn add_constraint(&mut self, expr: impl Into<Expr>)
pub fn add_constraint(&mut self, expr: impl Into<Expr>)
Adds a constraint expression to this target.
For Scope targets, the expression is added as a filter. For Model
targets, the target is upgraded to a Scope wrapping a select query
with the constraint as a filter.
Trait Implementations§
Source§impl Clone for InsertTarget
impl Clone for InsertTarget
Source§fn clone(&self) -> InsertTarget
fn clone(&self) -> InsertTarget
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for InsertTarget
impl Debug for InsertTarget
Source§impl From<InsertTable> for InsertTarget
impl From<InsertTable> for InsertTarget
Source§fn from(value: InsertTable) -> Self
fn from(value: InsertTable) -> Self
Source§impl From<Query> for InsertTarget
impl From<Query> for InsertTarget
Source§impl<'a, T: Resolve> IntoExprTarget<'a, T> for &'a InsertTarget
impl<'a, T: Resolve> IntoExprTarget<'a, T> for &'a InsertTarget
Source§fn into_expr_target(self, schema: &'a T) -> ExprTarget<'a>
fn into_expr_target(self, schema: &'a T) -> ExprTarget<'a>
self into an ExprTarget using the provided schema.