sql_tools::update

Trait UpdateBuilder

Source
pub trait UpdateBuilder {
    // Required methods
    fn set<T: ToSQLData>(self, column: &str, new_value: T) -> Self;
    fn where_in<T: ToSQLData>(self, column: &str, values: Vec<T>) -> WhereUpdate;
    fn where_not<T: ToSQLData>(
        self,
        column: &str,
        values: Vec<T>,
    ) -> WhereUpdate;
    fn build(self) -> Result<(), Error>;
    fn build_return_count(self) -> Result<usize, Error>;
}

Required Methods§

Source

fn set<T: ToSQLData>(self, column: &str, new_value: T) -> Self

Sets a column to a new value. Implements the ToSQLData trait for new values. For UPDATEs, it’s highly recommended to add a where_in or where_not (unless you want to update all entries).

conn.update("quarterly_earnings")
    .set("predicted_earnings", 1000000)
    .build()?; 
Source

fn where_in<T: ToSQLData>(self, column: &str, values: Vec<T>) -> WhereUpdate

Adds a WHERE clause to your query.

conn.update("test_grades")
    .set("passed", "false")
    .where_in("name", vec!["John Doe", "Jane Smith"])
    .build()?;

Is the same as:

UPDATE test_grades
SET passed = 'false'
WHERE name NOT IN ('John Doe');
Source

fn where_not<T: ToSQLData>(self, column: &str, values: Vec<T>) -> WhereUpdate

Adds a WHERE NOT clause to your query.

conn.update("test_grades")
    .set("passed", "true")
    .where_not("name", vec!["John Doe", "Jane Smith"])
    .build()?;

Is the same as:

UPDATE test_grades
SET passed = 'true'
WHERE name NOT IN ('John Doe');
Source

fn build(self) -> Result<(), Error>

Builds the query.

Source

fn build_return_count(self) -> Result<usize, Error>

Builds the query and returns the number of row updated.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§