Skip to content

Commit

Permalink
docs: generate docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jun 22, 2019
1 parent 59199d1 commit 8e86d52
Showing 1 changed file with 82 additions and 1 deletion.
83 changes: 82 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -33,7 +34,7 @@ import {
/**
* @param connection Instance of Slonik connection.
* @param {string} tableName Target table name.
* @param {Object.<string, ValueExpression>} Object describing the desired column values.
* @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.
*/
update;
Expand Down Expand Up @@ -97,6 +98,86 @@ WHERE

```


<a name="slonik-utilities-usage-updatedistinct"></a>
### <code>updateDistinct</code>

```js
import {
updateDistinct
} 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.
*/
updateDistinct;

```

Constructs and executes `UPDATE` query matching only rows with distinct values.

<a name="slonik-utilities-usage-updatedistinct-example-update-all-rows-1"></a>
#### 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;

```

<a name="slonik-utilities-usage-updatedistinct-example-update-rows-matching-a-boolean-where-condition-1"></a>
#### 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;

```


<a name="slonik-utilities-usage-upsert"></a>
### <code>upsert</code>

Expand Down

0 comments on commit 8e86d52

Please sign in to comment.