Struct sql_query_builder::UpdateBuilder
source · [−]pub struct UpdateBuilder<'a> { /* private fields */ }Expand description
Builder to contruct a update command
Implementations
sourceimpl<'a> UpdateBuilder<'a>
impl<'a> UpdateBuilder<'a>
sourcepub fn and(self, condition: &'a str) -> Self
pub fn and(self, condition: &'a str) -> Self
The same as where_clause method, useful to write more idiomatic SQL query
use sql_query_builder::UpdateBuilder;
let update = UpdateBuilder::new()
.update("users")
.set("name = $1")
.where_clause("login = $2")
.and("active = true");sourcepub fn as_string(&self) -> String
pub fn as_string(&self) -> String
Gets the current state of the UpdateBuilder and returns it as string
sourcepub fn debug(self) -> Self
pub fn debug(self) -> Self
Prints the current state of the UpdateBuilder into console output in a more ease to read version. This method is useful to debug complex queries or just to print the generated SQL while you type
use sql_query_builder::UpdateBuilder;
let update_query = UpdateBuilder::new()
.update("users")
.set("login = 'foo'")
.debug()
.set("name = 'Foo'")
.as_string();Output
UPDATE users
SET login = 'foo'sourcepub fn from(self, tables: &'a str) -> Self
pub fn from(self, tables: &'a str) -> Self
The from clause, this method can be used enabling the feature flag postgresql
sourcepub fn print(self) -> Self
pub fn print(self) -> Self
Prints the current state of the UpdateBuilder into console output similar to debug method, the difference is that this method prints in one line.
sourcepub fn raw(self, raw_sql: &'a str) -> Self
pub fn raw(self, raw_sql: &'a str) -> Self
Adds at the beginning a raw SQL query.
use sql_query_builder::UpdateBuilder;
let raw_query = "update users";
let update_query = UpdateBuilder::new()
.raw(raw_query)
.set("login = 'foo'")
.as_string();Output
update users
SET login = 'foo'sourcepub fn raw_after(self, clause: UpdateClause, raw_sql: &'a str) -> Self
pub fn raw_after(self, clause: UpdateClause, raw_sql: &'a str) -> Self
Adds a raw SQL query after a specified clause.
use sql_query_builder::{UpdateClause, UpdateBuilder};
let raw = "set name = 'Foo'";
let update_query = UpdateBuilder::new()
.update("users")
.raw_after(UpdateClause::Update, raw)
.as_string();Output
UPDATE users
set name = 'Foo'sourcepub fn raw_before(self, clause: UpdateClause, raw_sql: &'a str) -> Self
pub fn raw_before(self, clause: UpdateClause, raw_sql: &'a str) -> Self
Adds a raw SQL query before a specified clause.
use sql_query_builder::{UpdateClause, UpdateBuilder};
let raw = "update users";
let update_query = UpdateBuilder::new()
.raw_before(UpdateClause::Set, raw)
.set("name = 'Bar'")
.as_string();Output
update users
SET name = 'Bar'sourcepub fn returning(self, output_name: &'a str) -> Self
pub fn returning(self, output_name: &'a str) -> Self
The returning clause, this method can be used enabling the feature flag postgresql
sourcepub fn update(self, table_name: &'a str) -> Self
pub fn update(self, table_name: &'a str) -> Self
The update clause. This method overrides the previous value
use sql_query_builder::UpdateBuilder;
let update = UpdateBuilder::new()
.update("orders");
let update = UpdateBuilder::new()
.update("address")
.update("orders");sourcepub fn where_clause(self, condition: &'a str) -> Self
pub fn where_clause(self, condition: &'a str) -> Self
The where clause
use sql_query_builder::UpdateBuilder;
let update = UpdateBuilder::new()
.update("users")
.set("name = $1")
.where_clause("login = $2");sourcepub fn with(self, name: &'a str, query: impl WithQuery + 'static) -> Self
pub fn with(self, name: &'a str, query: impl WithQuery + 'static) -> Self
The with clause, this method can be used enabling the feature flag postgresql
use sql_query_builder::{InsertBuilder, UpdateBuilder};
let user = InsertBuilder::new()
.insert_into("users(login, name)")
.values("('foo', 'Foo')")
.returning("group_id");
let update = UpdateBuilder::new()
.with("user", user)
.update("user_group")
.set("count = count + 1")
.where_clause("id = (select group_id from user)")
.debug();Output
WITH user AS (
INSERT INTO users(login, name)
VALUES ('foo', 'Foo')
RETURNING group_id
)
UPDATE user_group
SET count = count + 1
WHERE id = (select group_id from user)Trait Implementations
sourceimpl<'a> Clone for UpdateBuilder<'a>
impl<'a> Clone for UpdateBuilder<'a>
sourcefn clone(&self) -> UpdateBuilder<'a>
fn clone(&self) -> UpdateBuilder<'a>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for UpdateBuilder<'_>
impl Debug for UpdateBuilder<'_>
sourceimpl<'a> Default for UpdateBuilder<'a>
impl<'a> Default for UpdateBuilder<'a>
sourcefn default() -> UpdateBuilder<'a>
fn default() -> UpdateBuilder<'a>
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl<'a> !RefUnwindSafe for UpdateBuilder<'a>
impl<'a> !Send for UpdateBuilder<'a>
impl<'a> !Sync for UpdateBuilder<'a>
impl<'a> Unpin for UpdateBuilder<'a>
impl<'a> !UnwindSafe for UpdateBuilder<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more