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.2.2 to 0.2.3

test/postgres/aggregate-tests.js

8

lib/column.js

@@ -9,2 +9,3 @@ var ColumnNode = require(__dirname + '/node/column');

this.name = config.name;
this.star = config.star;
this.asc = this.ascending = this;

@@ -82,2 +83,9 @@ this.alias = null;

Column.prototype.count = function(alias) {
var context = contextify(this);
context.aggCount = true;
context.alias = alias || context.name + '_count';
return new ColumnNode(context);
}
binaryMethod('equals', '=');

@@ -84,0 +92,0 @@ binaryMethod('equal', '=');

21

lib/dialect/postgres.js

@@ -116,3 +116,3 @@ var util = require('util');

var col_nodes = table.columns.map(function(col) { return col.toNode(); });
var result = ['CREATE TABLE'];

@@ -246,4 +246,8 @@ result = result.concat(create.nodes.map(this.visit.bind(this)));

var txt = "";
if(inSelectClause && columnNode.asArray) {
txt += 'array_agg(';
if(inSelectClause) {
if (columnNode.asArray) {
txt += 'array_agg(';
} else if (columnNode.aggCount) {
txt += 'COUNT(';
}
}

@@ -262,8 +266,11 @@ if(!this._visitedInsert && !this._visitingUpdateTargetColumn && !this._visitingCreate && !this._visitingAlter) {

}
txt += this.quote(columnNode.name);
if(inSelectClause && columnNode.asArray) {
if (columnNode.star) {
txt += '*';
} else {
txt += this.quote(columnNode.name);
}
if(inSelectClause && (columnNode.asArray || columnNode.aggCount)) {
txt += ')';
txt += ' as ' + this.quote(columnNode.alias);
}
else if(inSelectClause && columnNode.alias) {
if(inSelectClause && columnNode.alias) {
txt += ' as ' + this.quote(columnNode.alias);

@@ -270,0 +277,0 @@ }

@@ -8,7 +8,13 @@ var Node = require(__dirname);

this.alias = config.alias;
this.star = config.star;
this.asArray = config.asArray;
this.aggCount = config.aggCount;
this.table = config.table;
this.value = config.getValue();
this.dataType = config.dataType;
},
as: function(alias) {
this.alias = alias;
return this;
}
});

@@ -51,2 +51,8 @@ var Query = require(__dirname + '/node/query');

Table.prototype.count = function(alias) {
var name = this.alias || this._name,
col = new Column({table: this, star: true});
return col.count(alias || name + '_count'); //ColumnNode
}
Table.prototype.select = function() {

@@ -53,0 +59,0 @@ //create the query and pass it off

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

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

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

@@ -42,3 +42,3 @@ # node-sql

).toQuery();
//query is parameterized by default

@@ -53,7 +53,7 @@ console.log(query.text); //SELECT "user"."id" FROM "user" WHERE ((("user"."name" = $1) AND ("user"."id" = $2)) OR (("user"."name" = $3) AND ("user"."id" = $4)))

.from(user.join(post).on(user.id.equals(post.userId))).toQuery();
console.log(query.text); //'SELECT "user"."name", "post"."content" FROM "user" INNER JOIN "post" ON ("user"."id" = "post"."userId")'
```
There are a __lot__ more examples under `test/dialect-tests.js`
There are a __lot__ more examples included in the `test` folder.

@@ -80,3 +80,3 @@ ## contributing

If you think your changes are too off-the-wall, open an issue or a pull-request without code so we can discuss them.
If you think your changes are too off-the-wall, open an issue or a pull-request without code so we can discuss them.

@@ -83,0 +83,0 @@ __Seriously:__

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