pub struct Update<'a> { /* private fields */ }
Expand description
A builder for an UPDATE
statement.
Implementations§
Source§impl<'a> Update<'a>
impl<'a> Update<'a>
Sourcepub fn table<T>(table: T) -> Self
pub fn table<T>(table: T) -> Self
Creates the basis for an UPDATE
statement to the given table.
Sourcepub fn set<K, V>(&mut self, column: K, value: V)
pub fn set<K, V>(&mut self, column: K, value: V)
Add another column value assignment to the query
let mut query = Update::table("users");
query.set("foo", 10);
query.set("bar", false);
let (sql, params) = renderer::Postgres::build(query);
assert_eq!(r#"UPDATE "users" SET "foo" = $1, "bar" = $2"#, sql);
assert_eq!(
vec![
Value::from(10),
Value::from(false),
],
params,
);
Sourcepub fn so_that<T>(&mut self, conditions: T)where
T: Into<ConditionTree<'a>>,
pub fn so_that<T>(&mut self, conditions: T)where
T: Into<ConditionTree<'a>>,
Adds WHERE
conditions to the query. See
Comparable for more examples.
let mut query = Update::table("users");
query.set("foo", 1);
query.so_that("bar".equals(false));
let (sql, params) = renderer::Postgres::build(query);
assert_eq!(r#"UPDATE "users" SET "foo" = $1 WHERE "bar" = $2"#, sql);
assert_eq!(
vec![
Value::from(1),
Value::from(false),
],
params,
);
We can also use a nested SELECT
in the conditions.
let mut select = Select::from_table("bars");
select.column("id");
select.so_that("uniq_val".equals(3));
let mut query = Update::table("users");
query.set("foo", 1);
query.so_that("bar".equals(select));
let (sql, params) = renderer::Postgres::build(query);
assert_eq!(
r#"UPDATE "users" SET "foo" = $1 WHERE "bar" = (SELECT "id" FROM "bars" WHERE "uniq_val" = $2)"#,
sql
);
assert_eq!(
vec![
Value::from(1),
Value::from(3),
],
params,
);
Trait Implementations§
impl<'a> StructuralPartialEq for Update<'a>
Auto Trait Implementations§
impl<'a> Freeze for Update<'a>
impl<'a> RefUnwindSafe for Update<'a>
impl<'a> Send for Update<'a>
impl<'a> Sync for Update<'a>
impl<'a> Unpin for Update<'a>
impl<'a> UnwindSafe for Update<'a>
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