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 ofInsertRecord
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
impl InsertRecords
Sourcepub fn new(columns: &[&str]) -> Self
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.
Sourcepub fn add_record(
&mut self,
record: &[&str],
) -> Result<&mut Self, InsertValueError>
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();
Sourcepub fn get_insert_text(&self) -> String
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
impl Clone for InsertRecords
Source§fn clone(&self) -> InsertRecords
fn clone(&self) -> InsertRecords
Returns a copy 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 moreAuto Trait Implementations§
impl Freeze for InsertRecords
impl RefUnwindSafe for InsertRecords
impl Send for InsertRecords
impl Sync for InsertRecords
impl Unpin for InsertRecords
impl UnwindSafe for InsertRecords
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