Skip to content

Commit acede7b

Browse files
author
Vitaly Tomilov
committed
documentation updates.
1 parent 4798828 commit acede7b

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ var obj = {
195195
two: 2
196196
};
197197

198-
format("INSERT INTO table(${this~}) VALUES(${one}, ${two})", obj);
198+
format('INSERT INTO table(${this~}) VALUES(${one}, ${two})', obj);
199199
//=>INSERT INTO table("one","two") VALUES(1, 2)
200200
```
201201

@@ -237,13 +237,13 @@ Below is an example of formatting `LIKE` filter that ends with a second name:
237237

238238
```js
239239
// using $1# or $1:value syntax:
240-
query("...WHERE name LIKE '%$1#'", "O'Connor");
241-
query("...WHERE name LIKE '%$1:value'", "O'Connor");
240+
query('...WHERE name LIKE \'%$1#\'', 'O\'Connor');
241+
query('...WHERE name LIKE \'%$1:value\'', 'O\'Connor');
242242
//=> ...WHERE name LIKE '%O''Connor'
243243

244244
// using ${propName#} or ${propName:value} syntax:
245-
query("...WHERE name LIKE '%${filter#}'", {filter: "O'Connor"});
246-
query("...WHERE name LIKE '%${filter:value}'", {filter: "O'Connor"});
245+
query('...WHERE name LIKE \'%${filter#}\'', {filter: 'O\'Connor'});
246+
query('...WHERE name LIKE \'%${filter:value}\'', {filter: 'O\'Connor'});
247247
//=> ...WHERE name LIKE '%O''Connor'
248248
```
249249

@@ -582,7 +582,6 @@ A transaction is a special type of task that automatically executes `BEGIN` + `C
582582

583583
```js
584584
db.tx(t => {
585-
// `t` and `this` here are the same;
586585
// creating a sequence of transaction queries:
587586
var q1 = t.none('UPDATE users SET active=$1 WHERE id=$2', [true, 123]);
588587
var q2 = t.one('INSERT INTO audit(entity, id) VALUES($1, $2) RETURNING id',
@@ -754,7 +753,6 @@ If you prefer writing asynchronous code in a synchronous manner, you can impleme
754753

755754
```js
756755
function * getUser(t) {
757-
// `t` and `this` here are the same;
758756
let user = yield t.oneOrNone('SELECT * FROM users WHERE id = $1', 123);
759757
return yield user || t.one('INSERT INTO users(name) VALUES($1) RETURNING *', 'John');
760758
}

lib/database.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ function Database(cn, dc, config) {
379379
* - `.message` = `Multiple rows were not expected.`
380380
* - `.code` = {@link errors.queryResultErrorCode.multiple queryResultErrorCode.multiple}
381381
*
382+
* @see
383+
* {@link Database.oneOrNone}
384+
*
382385
* @example
383386
*
384387
* // a query with in-line value transformation:
@@ -390,7 +393,7 @@ function Database(cn, dc, config) {
390393
* @example
391394
*
392395
* // a query with in-line value transformation + conversion:
393-
* db.one('SELECT count(*) FROM Users', null, c => +c.count)
396+
* db.one('SELECT count(*) FROM Users', [], c => +c.count)
394397
* .then(count=> {
395398
* // count = a proper integer value, rather than an object with a string
396399
* });
@@ -482,7 +485,8 @@ function Database(cn, dc, config) {
482485
*
483486
* @see
484487
* {@link Database.one one},
485-
* {@link Database.none none}
488+
* {@link Database.none none},
489+
* {@link Database.manyOrNone manyOrNone}
486490
*
487491
* @example
488492
*
@@ -530,7 +534,10 @@ function Database(cn, dc, config) {
530534
* The resolved array is extended with hidden property `duration` - number of milliseconds
531535
* it took the client to execute the query.
532536
*
533-
* @see {@link Database.any any}
537+
* @see
538+
* {@link Database.any any},
539+
* {@link Database.many many},
540+
* {@link Database.none none}
534541
*
535542
*/
536543
obj.manyOrNone = function (query, values) {
@@ -623,7 +630,7 @@ function Database(cn, dc, config) {
623630
*
624631
* // use of value transformation:
625632
* // deleting rows and returning the number of rows deleted
626-
* db.result('DELETE FROM Events WHERE id = $1', [123], r=>r.rowCount)
633+
* db.result('DELETE FROM Events WHERE id = $1', [123], r => r.rowCount)
627634
* .then(data=> {
628635
* // data = number of rows that were deleted
629636
* });
@@ -632,7 +639,7 @@ function Database(cn, dc, config) {
632639
*
633640
* // use of value transformation:
634641
* // getting only column details from a table
635-
* db.result('SELECT * FROM Users LIMIT 0', null, r=>r.fields)
642+
* db.result('SELECT * FROM Users LIMIT 0', null, r => r.fields)
636643
* .then(data=> {
637644
* // data = array of column descriptors
638645
* });
@@ -968,7 +975,6 @@ function Database(cn, dc, config) {
968975
*
969976
* // using the regular callback syntax:
970977
* db.task(t => {
971-
* // t = this
972978
* // t.ctx = task context object
973979
*
974980
* return t.one('SELECT id FROM Users WHERE name = $1', 'John')
@@ -987,7 +993,7 @@ function Database(cn, dc, config) {
987993
* @example
988994
*
989995
* // using the ES6 arrow syntax:
990-
* db.task(t=> {
996+
* db.task(t => {
991997
* // t.ctx = task context object
992998
*
993999
* return t.one('SELECT id FROM Users WHERE name = $1', 'John')
@@ -1006,8 +1012,7 @@ function Database(cn, dc, config) {
10061012
* @example
10071013
*
10081014
* // using an ES6 generator for the callback:
1009-
* db.task(function*(t) {
1010-
* // t = this
1015+
* db.task(function * (t) {
10111016
* // t.ctx = task context object
10121017
*
10131018
* let user = yield t.one('SELECT id FROM Users WHERE name = $1', 'John');
@@ -1067,7 +1072,6 @@ function Database(cn, dc, config) {
10671072
*
10681073
* // using the regular callback syntax:
10691074
* db.tx(t => {
1070-
* // t = this
10711075
* // t.ctx = transaction context object
10721076
*
10731077
* return t.one('INSERT INTO Users(name, age) VALUES($1, $2) RETURNING id', ['Mike', 25])
@@ -1108,8 +1112,7 @@ function Database(cn, dc, config) {
11081112
* @example
11091113
*
11101114
* // using an ES6 generator for the callback:
1111-
* db.tx(function*(t) {
1112-
* // t = this
1115+
* db.tx(function * (t) {
11131116
* // t.ctx = transaction context object
11141117
*
11151118
* let user = yield t.one('INSERT INTO Users(name, age) VALUES($1, $2) RETURNING id', ['Mike', 25]);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-promise",
3-
"version": "5.6.2",
3+
"version": "5.6.3",
44
"description": "Promises interface for PostgreSQL",
55
"main": "lib/index.js",
66
"typings": "typescript/pg-promise.d.ts",

0 commit comments

Comments
 (0)