pub struct InsertParams {
pub values: InsertValues,
pub columns: Option<Vec<String>>,
pub on_conflict: Option<OnConflict>,
pub returning: Option<Vec<SelectItem>>,
}Expand description
Parameters for an INSERT operation.
Supports single and bulk inserts, conflict resolution, and returning specific columns.
§Examples
use postgrest_parser::{InsertParams, InsertValues, OnConflict};
use std::collections::HashMap;
use serde_json::json;
// Single insert
let mut values = HashMap::new();
values.insert("name".to_string(), json!("Alice"));
values.insert("email".to_string(), json!("alice@example.com"));
let params = InsertParams::new(InsertValues::Single(values));
assert_eq!(params.values.len(), 1);
// With conflict resolution
let mut values = HashMap::new();
values.insert("email".to_string(), json!("alice@example.com"));
let params = InsertParams::new(InsertValues::Single(values))
.with_on_conflict(OnConflict::do_update(vec!["email".to_string()]));
assert!(params.on_conflict.is_some());Fields§
§values: InsertValuesValues to insert (single or bulk)
columns: Option<Vec<String>>Optional explicit column list (if None, derived from values)
on_conflict: Option<OnConflict>Optional conflict resolution strategy
returning: Option<Vec<SelectItem>>Optional RETURNING clause columns
Implementations§
Source§impl InsertParams
impl InsertParams
Sourcepub fn new(values: InsertValues) -> Self
pub fn new(values: InsertValues) -> Self
Creates new insert parameters with the given values.
Sourcepub fn with_columns(self, columns: Vec<String>) -> Self
pub fn with_columns(self, columns: Vec<String>) -> Self
Specifies explicit column order for the insert.
Sourcepub fn with_on_conflict(self, on_conflict: OnConflict) -> Self
pub fn with_on_conflict(self, on_conflict: OnConflict) -> Self
Adds conflict resolution behavior (ON CONFLICT clause).
Sourcepub fn with_returning(self, returning: Vec<SelectItem>) -> Self
pub fn with_returning(self, returning: Vec<SelectItem>) -> Self
Specifies columns to return after insert (RETURNING clause).
Trait Implementations§
Source§impl Clone for InsertParams
impl Clone for InsertParams
Source§fn clone(&self) -> InsertParams
fn clone(&self) -> InsertParams
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for InsertParams
impl Debug for InsertParams
Source§impl<'de> Deserialize<'de> for InsertParams
impl<'de> Deserialize<'de> for InsertParams
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for InsertParams
impl PartialEq for InsertParams
Source§impl Serialize for InsertParams
impl Serialize for InsertParams
impl StructuralPartialEq for InsertParams
Auto Trait Implementations§
impl Freeze for InsertParams
impl RefUnwindSafe for InsertParams
impl Send for InsertParams
impl Sync for InsertParams
impl Unpin for InsertParams
impl UnwindSafe for InsertParams
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more