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.34.0 to 0.35.0

21

lib/dialect/postgres.js

@@ -378,2 +378,4 @@ 'use strict';

this.visitingCase = true;
for (var i = 0; i < caseExp.whenList.length; i++) {

@@ -389,2 +391,4 @@ var whenExp = ' WHEN ' + this.visit(caseExp.whenList[i]);

this.visitingCase = false;
text += ' END)';

@@ -499,6 +503,9 @@ return [text];

var inSelectClause =
!this._selectOrDeleteEndIndex
&& !this._visitingWhere
&& !inInsertUpdateClause
&& !inDdlClause
this.visitingReturning ||
(!this._selectOrDeleteEndIndex
&& !this._visitingWhere
&& !inInsertUpdateClause
&& !inDdlClause
&& !this.visitingCase
);
var txt = [];

@@ -637,3 +644,7 @@ var closeParen = 0;

Postgres.prototype.visitReturning = function(returning) {
return ['RETURNING', returning.nodes.map(this.visit.bind(this)).join(', ')];
this.visitingReturning = true;
var r = ['RETURNING', returning.nodes.map(this.visit.bind(this)).join(', ')];
this.visitingReturning = false;
return r;
};

@@ -640,0 +651,0 @@

@@ -53,2 +53,11 @@ 'use strict';

Node.prototype.toNamedQuery = function(name, dialect) {
if (!name || typeof name !== 'string' || name === '') {
throw new Error('A query name has to be a non-empty String.');
}
var query = this.toQuery(dialect);
query.name = name;
return query;
};
Node.prototype.toString = function(dialect) {

@@ -55,0 +64,0 @@ var Dialect = determineDialect(this, dialect);

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

if (node) {
set.push(new ParameterNode(node.value));
set.push(ParameterNode.getNodeOrParameterNode(node.value));
}

@@ -65,0 +65,0 @@ else {

@@ -164,2 +164,5 @@ 'use strict';

query.alias = alias;
query.join = function(other) {
return new JoinNode('INNER', this.toNode(), other.toNode(), other);
}
return query;

@@ -166,0 +169,0 @@ };

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

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

@@ -8,0 +8,0 @@ "repository": {

@@ -48,2 +48,5 @@ # node-sql

//queries can be named
var query = user.select(user.star()).from(user).toNamedQuery('user.all');
console.log(query.name); //'user.all'

@@ -151,3 +154,3 @@ //how about a join?

node-sql wouldn't be anything without all the contributors and collaborators who've worked on it.
node-sql wouldn't be anything without all the contributors and collaborators who've worked on it.
If you'd like to become a collaborator here's how it's done:

@@ -161,3 +164,3 @@

At this point the tests should pass for you. If they don't pass please open an issue with the output or you can even send me an email directly.
At this point the tests should pass for you. If they don't pass please open an issue with the output or you can even send me an email directly.
My email address is on my github profile and also on every commit I contributed in the repo.

@@ -171,3 +174,3 @@

Usually after a few high-quality pull requests and friendly interactions we will gladly share collaboration rights with you.
Usually after a few high-quality pull requests and friendly interactions we will gladly share collaboration rights with you.

@@ -174,0 +177,0 @@ After all, open source belongs to everyone.

@@ -117,4 +117,12 @@ 'use strict';

});
})
it('does not use property alias within CASE ... END', function() {
assert.equal(table.makeMeCamel.case([table.makeMeCamel.equals(0)],[table.makeMeCamel]).as('rename').toQuery().text,
'(CASE WHEN ("sc"."make_me_camel" = $1) THEN "sc"."make_me_camel" END) AS "rename"');
});
it('respects AS rename in RETURNING clause', function() {
assert.equal(table.update({makeMeCamel:0}).returning(table.makeMeCamel.as('rename')).toQuery().text,
'UPDATE "sc" SET "make_me_camel" = $1 RETURNING "sc"."make_me_camel" AS "rename"');
});
});
});
});

@@ -61,2 +61,22 @@ 'use strict';

Harness.test({
query: post.insert({
content: post.sql.functions.LOWER('TEST'),
userId: 2
}),
pg: {
text : 'INSERT INTO "post" ("content", "userId") VALUES (LOWER($1), $2)',
string: 'INSERT INTO "post" ("content", "userId") VALUES (LOWER(\'TEST\'), 2)'
},
sqlite: {
text : 'INSERT INTO "post" ("content", "userId") VALUES (LOWER($1), $2)',
string: 'INSERT INTO "post" ("content", "userId") VALUES (LOWER(\'TEST\'), 2)'
},
mysql: {
text : 'INSERT INTO `post` (`content`, `userId`) VALUES (LOWER(?), ?)',
string: 'INSERT INTO `post` (`content`, `userId`) VALUES (LOWER(\'TEST\'), 2)'
},
params: ['TEST', 2]
});
// allow bulk insert

@@ -376,3 +396,3 @@ Harness.test({

text : 'INSERT INTO "post" ("content") VALUES ($1), ($2)',
string: 'INSERT INTO "post" ("content") ' +
string: 'INSERT INTO "post" ("content") ' +
'VALUES (\'\\x77686f6168\'), (\'\\x686579\')'

@@ -379,0 +399,0 @@ },

@@ -103,2 +103,56 @@ 'use strict';

});
test('using named queries with toNamedQuery', function() {
var query = sql.select(user.id).from(user).where(user.email.equals('brian.m.carlson@gmail.com')).toNamedQuery('users');
assert.equal(query.text, 'SELECT "user"."id" FROM "user" WHERE ("user"."email" = $1)');
assert.equal(query.values[0], 'brian.m.carlson@gmail.com');
assert.equal(query.name, 'users');
});
test('provide an empty query name for toNamedQuery', function() {
var query = sql.select(user.id).from(user);
assert.throws(function() {
query.toNamedQuery('');
});
});
test('provide an undefined query name for toNamedQuery', function() {
var query = sql.select(user.id).from(user);
assert.throws(function() {
query.toNamedQuery();
});
});
test('override dialect for toNamedQuery using dialect name', function() {
var Sql = sql.Sql;
var mysql = new Sql('mysql');
var postgres = new Sql('postgres');
var sqlite = new Sql('sqlite');
var sqliteQuery = mysql.select(user.id).from(user).where(user.email.equals('brian.m.carlson@gmail.com')).toNamedQuery('user.select_brian','sqlite');
var postgresQuery = sqlite.select(user.id).from(user).where(user.email.equals('brian.m.carlson@gmail.com')).toNamedQuery('user.select_brian','postgres');
var mysqlQuery = postgres.select(user.id).from(user).where(user.email.equals('brian.m.carlson@gmail.com')).toNamedQuery('user.select_brian','mysql');
var values = ['brian.m.carlson@gmail.com'];
assert.equal(sqliteQuery.text, 'SELECT "user"."id" FROM "user" WHERE ("user"."email" = $1)');
assert.deepEqual(sqliteQuery.values, values);
assert.equal('user.select_brian', sqliteQuery.name);
assert.equal(postgresQuery.text, 'SELECT "user"."id" FROM "user" WHERE ("user"."email" = $1)');
assert.deepEqual(postgresQuery.values, values);
assert.equal('user.select_brian', postgresQuery.name);
assert.equal(mysqlQuery.text, 'SELECT `user`.`id` FROM `user` WHERE (`user`.`email` = ?)');
assert.deepEqual(mysqlQuery.values, values);
assert.equal('user.select_brian', mysqlQuery.name);
});
test('override dialect for toNamedQuery using invalid dialect name', function() {
var query = sql.select(user.id).from(user);
assert.throws(function() {
query.toNamedQuery('name', 'invalid');
});
});
});

Sorry, the diff of this file is not supported yet

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