pub struct UpdateBuilder<'a> { /* private fields */ }
Expand description

Builder to contruct a update command

Implementations

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");

Gets the current state of the UpdateBuilder and returns it as string

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'

The from clause, this method can be used enabling the feature flag postgresql

Create UpdateBuilder’s instance

Prints the current state of the UpdateBuilder into console output similar to debug method, the difference is that this method prints in one line.

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'

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'

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'

The returning clause, this method can be used enabling the feature flag postgresql

The set clause

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");

The where clause

use sql_query_builder::UpdateBuilder;

let update = UpdateBuilder::new()
  .update("users")
  .set("name = $1")
  .where_clause("login = $2");

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.