Struct InsertRecords

Source
pub struct InsertRecords { /* private fields */ }
Expand description

Represents a collection of insert records.

§Fields

  • keys: A vector of strings representing the columns for the insert records.
  • insert_records: A vector of InsertRecord objects.

§Example

use safety_postgres::access::sql_base::InsertRecords;

let mut insert_records = InsertRecords::new(&["str_column1", "int_column2", "float_column3"]);

let record1 = vec!["value1", "2", "3.1"];
let record2 = vec!["value3", "10", "0.7"];
insert_records.add_record(&record1).expect("adding insert record failed");
insert_records.add_record(&record2).expect("adding insert record failed");

let insert_query = insert_records.get_insert_text();

assert_eq!(
    insert_query,
    "INSERT INTO main_table_name (str_column1, int_column2, float_column3) VALUES (value1, 2, 3.1), (value3, 10, 0.7)"
);

Implementations§

Source§

impl InsertRecords

Source

pub fn new(columns: &[&str]) -> Self

Creates a new instance of the Table struct.

§Arguments
  • columns - A slice of strings representing the column names to insert.
Source

pub fn add_record( &mut self, record: &[&str], ) -> Result<&mut Self, InsertValueError>

Adds a record to insert the database.

§Arguments
  • record - A slice of strings representing the values to be inserted.
§Returns

Returns a mutable reference to the Self type. Returns an error of type InsertValueError if there is an error during the insertion process.

§Errors

Returns an InsertValueError if some error occurred during process.

§Examples
use safety_postgres::access::sql_base::InsertRecords;

let mut insert_records = InsertRecords::new(&["first_name", "last_name", "age"]);

let record = vec!["John", "Doe", "25"];
insert_records.add_record(&record).unwrap();
Source

pub fn get_insert_text(&self) -> String

Retrieves the insert text for the SQL statement.

§Returns

The insert text for the SQL statement.

§Example
use safety_postgres::access::sql_base::InsertRecords;

let columns = vec!["column1", "column2"];
let mut insert_records = InsertRecords::new(&columns);

let record = vec!["value1", "value2"];
insert_records.add_record(&record).unwrap();

let insert_text = insert_records.get_insert_text();
println!("Insert Text: {}", insert_text);

Trait Implementations§

Source§

impl Clone for InsertRecords

Source§

fn clone(&self) -> InsertRecords

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

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, 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V