Skip to content

Latest commit

 

History

History
72 lines (54 loc) · 979 Bytes

UPDATE.md

File metadata and controls

72 lines (54 loc) · 979 Bytes

update

import {
  update
} from 'slonik-utilities';

/**
 * @param connection Instance of Slonik connection.
 * @param {string} tableName Target table name.
 * @param {Object.<string, ValueExpression>} namedValueBindings Object describing the desired column values.
 * @param {Object.<string, EqualPredicate>} [booleanExpressionValues] Object describing the boolean expression used to construct WHERE condition.
 * @returns {UpdateResultType}
 */
update;

Constructs and executes UPDATE query.

Example: Update all rows

Operation:

update(
  connection,
  'user',
  {
    givenName: 'foo'
  }
);

Is equivalent to:

UPDATE "user"
SET
  "given_name" = $1;

Example: Update rows matching a boolean WHERE condition

Operation:

update(
  connection,
  'user',
  {
    givenName: 'foo'
  },
  {
    lastName: 'bar'
  }
);

Is equivalent to:

UPDATE "user"
SET
  "given_name" = $1
WHERE
  "last_name" = $2;