diff --git a/postgres.js b/postgres.js index 5045429..cb59887 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(', ') + ']'; + var 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;