pub struct Update<'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

Examples
use sql_query_builder as sql;

let update = sql::Update::new()
  .update("users")
  .set("name = $1")
  .where_clause("login = $2")
  .and("active = true");

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

Examples
use sql_query_builder as sql;

let query = sql::Update::new()
  .update("users")
  .set("login = 'foo'")
  .as_string();

Output

 UPDATE users SET login = 'foo'

Prints the current state of the Update 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

Examples
use sql_query_builder as sql;

let update_query = sql::Update::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 Update’s instance

Prints the current state of the Update 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.

Examples
use sql_query_builder as sql;

let raw_query = "update users";
let update_query = sql::Update::new()
  .raw(raw_query)
  .set("login = 'foo'")
  .as_string();

Output

update users
SET login = 'foo'

Adds a raw SQL query after a specified clause.

Examples
use sql_query_builder as sql;

let raw = "set name = 'Foo'";
let update_query = sql::Update::new()
  .update("users")
  .raw_after(sql::UpdateClause::Update, raw)
  .as_string();

Output

UPDATE users
set name = 'Foo'

Adds a raw SQL query before a specified clause.

Examples
use sql_query_builder as sql;

let raw = "update users";
let update_query = sql::Update::new()
  .raw_before(sql::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

Examples
use sql_query_builder as sql;

let update = sql::Update::new()
  .update("orders");

let update = sql::Update::new()
  .update("address")
  .update("orders");

The where clause

Examples
use sql_query_builder as sql;

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

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

Examples
use sql_query_builder as sql;

let user = sql::Insert::new()
  .insert_into("users(login, name)")
  .values("('foo', 'Foo')")
  .returning("group_id");
let update = sql::Update::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.