pub struct Insert {
pub table: String,
pub rows: Vec<RowValues>,
pub conflict: Option<OnConflict>,
pub scope: Option<Scope>,
pub returning: Vec<SelectItem>,
pub from_select: Option<(Vec<String>, Box<Select>)>,
}Expand description
An INSERT (single- or multi-row), optionally an upsert, optionally RETURNING.
Fields§
§table: String§rows: Vec<RowValues>§conflict: Option<OnConflict>§scope: Option<Scope>Forces column = value into every inserted row (adds or overrides).
returning: Vec<SelectItem>RETURNING <items> (empty ⇒ none). Not supported by every engine (e.g. MySQL).
from_select: Option<(Vec<String>, Box<Select>)>INSERT INTO t (<columns>) <select> — when set, rows come from a SELECT (rows ignored).
Under a scoped write, Insert::force_scope read-scopes the source and host-forces the
target tenant column (dropping any guest projection of it), so the written tenant can’t be
forged; without a scope (or all) the columns/projection are taken verbatim.
Implementations§
Source§impl Insert
impl Insert
Sourcepub fn uniform_scope_value(&self, col: &str) -> Option<SqlValue>
pub fn uniform_scope_value(&self, col: &str) -> Option<SqlValue>
For a posture-vetted cross-tenant (all) INSERT with no host-injected stamp: the single,
uniform LITERAL value of scope column col across every inserted row — the tenant the row(s)
declare — or None when it isn’t one well-defined literal (an INSERT … SELECT source, a
row missing col or giving it a non-literal, or rows that disagree). Used ONLY to set the
RLS tenant GUC to what the write targets (an all guest may write any one tenant, GUC-
consistent); a None simply doesn’t re-set the GUC, leaving it at whatever the per-transaction
own/session set established (or unset if none) — under all that only over-restricts the write
(the DB’s WITH CHECK still confines it), never widens it. The DB is the final arbiter — a
wrong value is rejected there.
Source§impl Insert
impl Insert
Sourcepub fn force_scope(
&mut self,
write: Option<&Scope>,
read: Option<&Scope>,
) -> Result<(), OrmError>
pub fn force_scope( &mut self, write: Option<&Scope>, read: Option<&Scope>, ) -> Result<(), OrmError>
Force the host-resolved tenant scope. write stamps the tenant column on a
VALUES-based insert (per ScopeMode); for an INSERT … SELECT, the read scope is
forced onto the source query (and its nested unions) so the selected rows stay
tenant-isolated, and the target tenant column is host-forced too — any guest-supplied
tenant column + its projection is dropped and re-appended bound to the resolved value, so a
guest can’t project another tenant’s id into the write (a cross-tenant write forgery).
None for an axis (cross-tenant all) clears that scope — the operation runs unscoped on
that axis, by design (an all write’s stamp_value() is None, so nothing is forced).