Skip to main content

Insert

Struct Insert 

Source
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

Source

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

Source

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).

Source§

impl Insert

Source

pub fn compile(&self, dialect: Dialect) -> Result<Compiled, OrmError>

Compile to ?N SQL + bound parameters for the given dialect.

Trait Implementations§

Source§

impl Clone for Insert

Source§

fn clone(&self) -> Insert

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Insert

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Insert

Source§

fn eq(&self, other: &Insert) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Insert

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more