diff --git a/README.md b/README.md index b65be3a..c7cc30a 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Utilities for manipulating data in PostgreSQL database using [Slonik](https://gi * [Contents](#slonik-utilities-contents) * [Usage](#slonik-utilities-usage) * [`update`](#slonik-utilities-usage-update) + * [`updateDistinct`](#slonik-utilities-usage-updatedistinct) * [`upsert`](#slonik-utilities-usage-upsert) @@ -33,7 +34,7 @@ import { /** * @param connection Instance of Slonik connection. * @param {string} tableName Target table name. - * @param {Object.} Object describing the desired column values. + * @param {Object.} namedValueBindings Object describing the desired column values. * @param {Object.} [booleanExpressionValues] Object describing the boolean expression used to construct WHERE condition. */ update; @@ -97,6 +98,86 @@ WHERE ``` + + +### updateDistinct + +```js +import { + updateDistinct +} from 'slonik-utilities'; + +/** + * @param connection Instance of Slonik connection. + * @param {string} tableName Target table name. + * @param {Object.} namedValueBindings Object describing the desired column values. + * @param {Object.} [booleanExpressionValues] Object describing the boolean expression used to construct WHERE condition. + */ +updateDistinct; + +``` + +Constructs and executes `UPDATE` query matching only rows with distinct values. + + +#### Example: Update all rows + +Operation: + +```js +update( + connection, + 'user', + { + givenName: 'foo' + } +); + +``` + +Is equivalent to: + +```sql +UPDATE "user" +SET + "given_name" = $1 +WHERE + "given_name" IS DISTINCT FROM $1; + +``` + + +#### Example: Update rows matching a boolean WHERE condition + +Operation: + +```js +update( + connection, + 'user', + { + givenName: 'foo' + }, + { + lastName: 'bar' + } +); + +``` + +Is equivalent to: + +```sql +UPDATE "user" +SET + "given_name" = $1 +WHERE + "last_name" = $2 AND + "given_name" IS DISTINCT FROM $1; + +``` + + ### upsert