Function scooby::postgres::statements::update

source ·
pub fn update(table_name: impl Into<TableName>) -> BareUpdate
Expand description

Start building a new UPDATE statement with the given table name.

Returns a BareUpdate structure that requires that you at least set one column + expression pair through set method.

The set method, in turn, returns an Update structure, through which more values may be set, and additional clauses may be added.

Call to_string on the Update structure to finalize and get an SQL string.

Supported clauses

ClauseMethod
SETset
WHEREwhere_
RETURNINGreturning

Specifying a WITH clause

To create a UPDATE statement with a WITH clause, start with with instead of this function.

Examples

use scooby::postgres::update;

let sql = update("Dummy").set("x", "$1").to_string();

assert_eq!(sql, "UPDATE Dummy SET x = $1");
use scooby::postgres::update;

let sql = update("Dummy")
    .set("x", "$1")
    .where_("x > 0")
    .where_("y < 10")
    .returning("id")
    .to_string();

assert_eq!(sql, "UPDATE Dummy SET x = $1 WHERE x > 0 AND y < 10 RETURNING id");