Skip to content

Commit

Permalink
fixing #272
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jan 27, 2017
1 parent 91a0d3f commit da6bc77
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 29 deletions.
26 changes: 4 additions & 22 deletions lib/helpers/columnSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function ColumnSet(columns, options) {
throw new TypeError("Invalid parameter 'columns' specified.");
}

var inherit, names, variables, castVariables, updates, cndCount = 0, isSimple = true;
var inherit, names, variables, updates, cndCount = 0, isSimple = true;

if (!$npm.utils.isNull(options)) {
if (typeof options !== 'object') {
Expand Down Expand Up @@ -260,35 +260,17 @@ function ColumnSet(columns, options) {
* @type String
* @readonly
* @description
* A string that contains a comma-separated list of all variables.
* Generates a formatting template - a string that contains
* a comma-separated list of all variables with casting.
*/
Object.defineProperty(this, 'variables', {
get: function () {
if (!variables) {
variables = $arr.map(this.columns, function (c) {
return c.variable;
}).join();
}
return variables;
}
});

/**
* @name helpers.ColumnSet#castVariables
* @private
* @type String
* @readonly
* @description
* A string that contains a comma-separated list of all variables with casting.
*/
Object.defineProperty(this, 'castVariables', {
get: function () {
if (!castVariables) {
castVariables = $arr.map(this.columns, function (c) {
return c.variable + c.castText;
}).join();
}
return castVariables;
return variables;
}
});

Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/methods/insert.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ function insert(data, columns, table, capSQL) {
if (!d || typeof d !== 'object') {
throw new Error("Invalid insert object at index " + index + ".");
}
return '(' + format(columns.castVariables, columns.prepare(d)) + ')';
return '(' + format(columns.variables, columns.prepare(d)) + ')';
}).join();
}
return query + '(' + format(columns.castVariables, columns.prepare(data)) + ')';
return query + '(' + format(columns.variables, columns.prepare(data)) + ')';
}

var sql = {
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/methods/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function update(data, columns, table, options, capSQL) {
checkTable();

var targetCols = $arr.map(actualColumns, function (c) {
return c.escapedName + '=' + valueAlias + '.' + c.escapedName + c.castText;
return c.escapedName + '=' + valueAlias + '.' + c.escapedName;
}).join();

var values = $arr.map(data, function (d, index) {
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/methods/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ function values(data, columns) {
if (!d || typeof d !== 'object') {
throw new Error("Invalid object at index " + index + ".");
}
return '(' + format(columns.castVariables, columns.prepare(d)) + ')';
return '(' + format(columns.variables, columns.prepare(d)) + ')';
}).join();
}
return '(' + format(columns.castVariables, columns.prepare(data)) + ')';
return '(' + format(columns.variables, columns.prepare(data)) + ')';
}

module.exports = values;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-promise",
"version": "5.5.2",
"version": "5.5.3",
"description": "Promises interface for PostgreSQL",
"main": "lib/index.js",
"typings": "typescript/pg-promise.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion test/helpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe("UPDATE", function () {
expect(helpers.update(dataMulti, ['?id', 'val', {
name: 'msg',
cast: 'text'
}], 'table')).toBe('update "table" as t set "val"=v."val","msg"=v."msg"::text from (values(1,123,\'hello\'),(2,456,\'world\')) as v("id","val","msg")');
}], 'table')).toBe('update "table" as t set "val"=v."val","msg"=v."msg" from (values(1,123,\'hello\'::text),(2,456,\'world\'::text)) as v("id","val","msg")');
});
});
});
Expand Down

0 comments on commit da6bc77

Please sign in to comment.