From 27db1e8c730bae64bf86953626f99ca55d231696 Mon Sep 17 00:00:00 2001 From: cybermerlin Date: Sun, 19 Nov 2017 01:43:15 +0300 Subject: [PATCH 1/3] fix converts.Array --- postgres.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/postgres.js b/postgres.js index 5045429..2bdb347 100644 --- a/postgres.js +++ b/postgres.js @@ -100,26 +100,26 @@ this._addListArgs(arguments, '_onConflict'); this.where = this.and = function() { return this._addExpression(arguments, '_onConflictWhere'); - } + }; this.onConstraint = function(name) { this._onConstraint = name; return this; - } + }; return this; - } + }; Insert.prototype.doNothing = function () { this._doNothing = true; return this; - } + }; Insert.prototype.doUpdate = function (cols) { this._doUpdate = cols || true; this.where = this.and = function () { return this._addExpression(arguments, '_doUpdateWhere'); - } + }; return this; - } + }; // Add "template tag" sql.templ.helpers.ifNotEmpty = function(val, opts, contents, ctx) { @@ -176,7 +176,7 @@ } : function (row, opts) { return sql._handleValues(_.values(row), opts); - } + }; var values = this._values.map(function (row) { return '(' + handleRow(row, opts).join(', ') + ')'; @@ -189,7 +189,7 @@ Values.prototype.types = function (types) { this._types = types || true; return this; - } + }; function typeCoerce(val) { if (typeof val === 'number') { @@ -210,7 +210,7 @@ Values.prototype.columns = function () { this._columns = true; return this; - } + }; Values.prototype.as = Select.prototype.as; Values.prototype._toNestedString = Select.prototype._toNestedString; Values.prototype._aliasToString = function (opts) { @@ -221,7 +221,7 @@ alias += ' (' + sql._handleColumns(_.keys(this._values[0])) + ')'; } return alias; - } + }; // Convert objects to JSON // HACK: we are pollluting sql namepsace here, but currently there is no way around, @@ -236,14 +236,18 @@ return _convert(JSON.stringify(val)); return _convert(val); - } + }; // Use SQL-99 syntax for arrays since it's easier to implement sql.conversions.Array = function(arr) { - return 'ARRAY[' + arr.map(sql.convert).join(', ') + ']'; + const pgTypes = { + number: 'bigint[]', + string: 'text[]' + }; + return `ARRAY[${arr.map(sql.convert).join()}]::${pgTypes[(typeof arr[0]).toLowerCase()]}`; }; - if (typeof exports != 'undefined') + if (typeof exports !== 'undefined') module.exports = pgsql; else window.PostgresBricks = pgsql; From 8e3759e70d0e319800a90bbd16a9dcc9525350e6 Mon Sep 17 00:00:00 2001 From: cybermerlin Date: Sun, 19 Nov 2017 22:29:15 +0300 Subject: [PATCH 2/3] const 2 var --- postgres.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres.js b/postgres.js index 2bdb347..9ef6fe5 100644 --- a/postgres.js +++ b/postgres.js @@ -240,7 +240,7 @@ // Use SQL-99 syntax for arrays since it's easier to implement sql.conversions.Array = function(arr) { - const pgTypes = { + var pgTypes = { number: 'bigint[]', string: 'text[]' }; From fdb60908cc4b57eb50933cf04609c0533afca3c5 Mon Sep 17 00:00:00 2001 From: cybermerlin Date: Tue, 21 Nov 2017 15:21:46 +0300 Subject: [PATCH 3/3] why not use es6? >_< --- postgres.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres.js b/postgres.js index 9ef6fe5..cb59887 100644 --- a/postgres.js +++ b/postgres.js @@ -244,7 +244,7 @@ number: 'bigint[]', string: 'text[]' }; - return `ARRAY[${arr.map(sql.convert).join()}]::${pgTypes[(typeof arr[0]).toLowerCase()]}`; + return 'ARRAY[' + arr.map(sql.convert).join() + ']::' + pgTypes[(typeof arr[0]).toLowerCase()]; }; if (typeof exports !== 'undefined')