Socket
Socket
Sign inDemoInstall

sql

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql - npm Package Compare versions

Comparing version 0.66.0 to 0.67.0

28

lib/dialect/postgres.js

@@ -29,3 +29,3 @@ 'use strict';

Postgres.prototype._getParameterValue = function(value) {
Postgres.prototype._getParameterValue = function(value, quoteChar) {
// handle primitives

@@ -40,9 +40,25 @@ if (null === value) {

} else if ('string' === typeof value) {
// string uses single quote
value = this.quote(value, "'");
// string uses single quote by default
value = this.quote(value, quoteChar || "'");
} else if ('object' === typeof value) {
if (_.isArray(value)) {
// convert each element of the array
value = _.map(value, this._getParameterValue, this);
value = '(' + value.join(', ') + ')';
if (this._myClass === Postgres) {
// naive check to see if this is an array of objects, which
// is handled differently than an array of primitives
if (value.length && 'object' === typeof value[0] &&
!_.isFunction(value[0].toISOString) &&
!_.isArray(value[0])) {
value = "'" + JSON.stringify(value) + "'";
} else {
var self = this;
value = value.map(function (item) {
// In a Postgres array, strings must be double-quoted
return self._getParameterValue(item, '"');
});
value = '\'{' + value.join(',') + '}\'';
}
} else {
value = _.map(value, this._getParameterValue, this);
value = '(' + value.join(', ') + ')';
}
} else if (_.isFunction(value.toISOString)) {

@@ -49,0 +65,0 @@ // Date object's default toString format does not get parsed well

@@ -5,3 +5,3 @@ {

"description": "sql builder",
"version": "0.66.0",
"version": "0.67.0",
"homepage": "https://github.com/brianc/node-sql",

@@ -8,0 +8,0 @@ "license": "MIT",

@@ -7,2 +7,7 @@ 'use strict';

var arrayTable = require('../../lib/table').define({
name: 'arraytest',
columns: ['id', 'numbers']
});
Harness.test({

@@ -634,1 +639,41 @@ query: post.insert(post.content.value('test'), post.userId.value(1)),

});
Harness.test({
query: arrayTable.insert(arrayTable.id.value(1), arrayTable.numbers.value([2, 3, 4])),
pg: {
text : 'INSERT INTO "arraytest" ("id", "numbers") VALUES ($1, $2)',
string: 'INSERT INTO "arraytest" ("id", "numbers") VALUES (1, \'{2,3,4}\')'
},
sqlite: {
text : 'INSERT INTO "arraytest" ("id", "numbers") VALUES ($1, $2)',
string: 'INSERT INTO "arraytest" ("id", "numbers") VALUES (1, \'[2,3,4]\')'
},
mysql: {
text : 'INSERT INTO `arraytest` (`id`, `numbers`) VALUES (?, ?)',
string: 'INSERT INTO `arraytest` (`id`, `numbers`) VALUES (1, (2, 3, 4))'
},
oracle: {
text : 'INSERT INTO "arraytest" ("id", "numbers") VALUES (:1, :2)',
string: 'INSERT INTO "arraytest" ("id", "numbers") VALUES (1, (2, 3, 4))'
}
});
Harness.test({
query: arrayTable.insert(arrayTable.id.value(1), arrayTable.numbers.value(["one", "two", "three"])),
pg: {
text : 'INSERT INTO "arraytest" ("id", "numbers") VALUES ($1, $2)',
string: 'INSERT INTO "arraytest" ("id", "numbers") VALUES (1, \'{"one","two","three"}\')'
},
sqlite: {
text : 'INSERT INTO "arraytest" ("id", "numbers") VALUES ($1, $2)',
string: 'INSERT INTO "arraytest" ("id", "numbers") VALUES (1, \'["one","two","three"]\')'
},
mysql: {
text : 'INSERT INTO `arraytest` (`id`, `numbers`) VALUES (?, ?)',
string: 'INSERT INTO `arraytest` (`id`, `numbers`) VALUES (1, (\'one\', \'two\', \'three\'))'
},
oracle: {
text : 'INSERT INTO "arraytest" ("id", "numbers") VALUES (:1, :2)',
string: 'INSERT INTO "arraytest" ("id", "numbers") VALUES (1, (\'one\', \'two\', \'three\'))'
}
});

@@ -231,3 +231,3 @@ 'use strict';

text : 'UPDATE "variable" SET "a" = $1, "b" = $2',
string: 'UPDATE "variable" SET "a" = \'{"id":1,"value":2}\', "b" = (\'{"id":2,"value":3}\', \'{"id":3,"value":4}\')'
string: 'UPDATE "variable" SET "a" = \'{"id":1,"value":2}\', "b" = \'[{"id":2,"value":3},{"id":3,"value":4}]\''
},

@@ -234,0 +234,0 @@ sqlite: {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc