Skip to content

Commit dc773f2

Browse files
author
Vitaly Tomilov
committed
adding tests + examples.
1 parent 34802dc commit dc773f2

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

lib/helpers/columnSet.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ var $arr = require('../array');
5353
* @see
5454
*
5555
* {@link helpers.ColumnSet#columns columns},
56+
* {@link helpers.ColumnSet#names names},
5657
* {@link helpers.ColumnSet#table table},
58+
* {@link helpers.ColumnSet#variables variables} |
5759
* {@link helpers.ColumnSet.extend extend},
5860
* {@link helpers.ColumnSet.merge merge}
5961
*
@@ -234,11 +236,17 @@ function ColumnSet(columns, options) {
234236

235237
/**
236238
* @name helpers.ColumnSet#names
237-
* @private
238239
* @type String
239240
* @readonly
240241
* @description
241-
* A string that contains a comma-separated list of escaped column names, wrapped in `()`.
242+
* **Added in v5.6.0**
243+
*
244+
* Returns a string - comma-separated list of all column names, properly escaped.
245+
*
246+
* @example
247+
* var cs = new ColumnSet(['id^', {name: 'cells', cast: 'int[]'}, 'doc:json']);
248+
* console.log(cs.names);
249+
* //=> "id","cells","doc"
242250
*/
243251
Object.defineProperty(this, 'names', {
244252
get: function () {
@@ -253,12 +261,17 @@ function ColumnSet(columns, options) {
253261

254262
/**
255263
* @name helpers.ColumnSet#variables
256-
* @private
257264
* @type String
258265
* @readonly
259266
* @description
260-
* Generates a formatting template - a string that contains
261-
* a comma-separated list of all variables with casting.
267+
* **Added in v5.6.0**
268+
*
269+
* Returns a string - formatting template for all column values.
270+
*
271+
* @example
272+
* var cs = new ColumnSet(['id^', {name: 'cells', cast: 'int[]'}, 'doc:json']);
273+
* console.log(cs.variables);
274+
* //=> ${id^},${cells}::int[],${doc:json}
262275
*/
263276
Object.defineProperty(this, 'variables', {
264277
get: function () {

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.5.4",
3+
"version": "5.6.0",
44
"description": "Promises interface for PostgreSQL",
55
"main": "lib/index.js",
66
"typings": "typescript/pg-promise.d.ts",

test/helpSpec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,18 @@ describe("ColumnSet", function () {
547547
});
548548
});
549549

550+
describe("property 'variables'", function () {
551+
var cs = new helpers.ColumnSet(['id^', {name: 'cells', cast: 'int[]'}, 'doc:json']);
552+
var csEmpty = new helpers.ColumnSet([]);
553+
it("must return the right string", function () {
554+
expect(cs.variables).toBe('${id^},${cells}::int[],${doc:json}');
555+
expect(csEmpty.variables).toBe('');
556+
});
557+
it("must reuse the data", function () {
558+
expect(cs.variables).toBe('${id^},${cells}::int[],${doc:json}');
559+
});
560+
});
561+
550562
describe("method 'getUpdates'", function () {
551563
var cs = new helpers.ColumnSet(dataSingle);
552564
var csEmpty = new helpers.ColumnSet([]);

0 commit comments

Comments
 (0)