Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sql-query

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql-query - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

23

lib/Select.js

@@ -121,8 +121,17 @@ var Where = require("./Where");

for (j = 0; j < sql.from[i].select.length; j++) {
tmp.push(
sql.from[i].select[j].f + "(" +
(sql.from[i].select[j].c ? Dialect.escapeId(sql.from[i].a, sql.from[i].select[j].c) : "*") +
")" +
(sql.from[i].select[j].a ? " AS " + Dialect.escapeId(sql.from[i].select[j].a) : "")
);
if (sql.from.length == 1) {
tmp.push(
sql.from[i].select[j].f + "(" +
(sql.from[i].select[j].c ? Dialect.escapeId(sql.from[i].select[j].c) : "*") +
")" +
(sql.from[i].select[j].a ? " AS " + Dialect.escapeId(sql.from[i].select[j].a) : "")
);
} else {
tmp.push(
sql.from[i].select[j].f + "(" +
(sql.from[i].select[j].c ? Dialect.escapeId(sql.from[i].a, sql.from[i].select[j].c) : "*") +
")" +
(sql.from[i].select[j].a ? " AS " + Dialect.escapeId(sql.from[i].select[j].a) : "")
);
}
}

@@ -174,3 +183,3 @@ }

} else {
query.push(Dialect.escapeId(sql.from[i].t) + " AS " + Dialect.escapeId(sql.from[i].a));
query.push(Dialect.escapeId(sql.from[i].t) + " " + Dialect.escapeId(sql.from[i].a));
}

@@ -177,0 +186,0 @@ if (i > 0) {

@@ -9,3 +9,3 @@ {

],
"version": "0.0.8",
"version": "0.0.9",
"license": "MIT",

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

@@ -27,3 +27,3 @@ var common = require('../common');

.from('table2', 'id2', 'id1').select('id2').build(),
"SELECT `t1`.`id1`, `t1`.`name`, `t2`.`id2` FROM `table1` AS `t1` JOIN `table2` AS `t2` ON `t2`.`id2` = `t1`.`id1`"
"SELECT `t1`.`id1`, `t1`.`name`, `t2`.`id2` FROM `table1` `t1` JOIN `table2` `t2` ON `t2`.`id2` = `t1`.`id1`"
);

@@ -34,3 +34,3 @@

.from('table2', 'id2', 'table1', 'id1').select('id2').build(),
"SELECT `t1`.`id1`, `t1`.`name`, `t2`.`id2` FROM `table1` AS `t1` JOIN `table2` AS `t2` ON `t2`.`id2` = `t1`.`id1`"
"SELECT `t1`.`id1`, `t1`.`name`, `t2`.`id2` FROM `table1` `t1` JOIN `table2` `t2` ON `t2`.`id2` = `t1`.`id1`"
);

@@ -41,3 +41,3 @@

.from('table2', 'id2', 'table1', 'id1').count().build(),
"SELECT COUNT(*) FROM `table1` AS `t1` JOIN `table2` AS `t2` ON `t2`.`id2` = `t1`.`id1`"
"SELECT COUNT(*) FROM `table1` `t1` JOIN `table2` `t2` ON `t2`.`id2` = `t1`.`id1`"
);

@@ -48,3 +48,3 @@

.from('table2', 'id2', 'table1', 'id1').count(null, 'c').build(),
"SELECT COUNT(*) AS `c` FROM `table1` AS `t1` JOIN `table2` AS `t2` ON `t2`.`id2` = `t1`.`id1`"
"SELECT COUNT(*) AS `c` FROM `table1` `t1` JOIN `table2` `t2` ON `t2`.`id2` = `t1`.`id1`"
);

@@ -55,3 +55,3 @@

.from('table2', 'id2', 'table1', 'id1').count('id').build(),
"SELECT COUNT(`t2`.`id`) FROM `table1` AS `t1` JOIN `table2` AS `t2` ON `t2`.`id2` = `t1`.`id1`"
"SELECT COUNT(`t2`.`id`) FROM `table1` `t1` JOIN `table2` `t2` ON `t2`.`id2` = `t1`.`id1`"
);

@@ -62,3 +62,3 @@

.from('table2', 'id2', 'table1', 'id1').count('id').build(),
"SELECT COUNT(`t1`.`id`), COUNT(`t2`.`id`) FROM `table1` AS `t1` JOIN `table2` AS `t2` ON `t2`.`id2` = `t1`.`id1`"
"SELECT COUNT(`t1`.`id`), COUNT(`t2`.`id`) FROM `table1` `t1` JOIN `table2` `t2` ON `t2`.`id2` = `t1`.`id1`"
);

@@ -69,3 +69,3 @@

.from('table2', 'id2', 'table1', 'id1').count('id').count('col').build(),
"SELECT COUNT(`t2`.`id`), COUNT(`t2`.`col`) FROM `table1` AS `t1` JOIN `table2` AS `t2` ON `t2`.`id2` = `t1`.`id1`"
"SELECT COUNT(`t2`.`id`), COUNT(`t2`.`col`) FROM `table1` `t1` JOIN `table2` `t2` ON `t2`.`id2` = `t1`.`id1`"
);

@@ -76,3 +76,3 @@

.from('table2', 'id2', 'table1', 'id1').fun('AVG', 'col').build(),
"SELECT AVG(`t2`.`col`) FROM `table1` AS `t1` JOIN `table2` AS `t2` ON `t2`.`id2` = `t1`.`id1`"
"SELECT AVG(`t2`.`col`) FROM `table1` `t1` JOIN `table2` `t2` ON `t2`.`id2` = `t1`.`id1`"
);

@@ -5,49 +5,49 @@ var common = require('../common');

assert.equal(
common.Select().from('t1').where().build(),
"SELECT * FROM `t1`"
common.Select().from('table1').where().build(),
"SELECT * FROM `table1`"
);
assert.equal(
common.Select().from('t1').where(null).build(),
"SELECT * FROM `t1`"
common.Select().from('table1').where(null).build(),
"SELECT * FROM `table1`"
);
assert.equal(
common.Select().from('t1').where({ col: 1 }).build(),
"SELECT * FROM `t1` WHERE (`col` = 1)"
common.Select().from('table1').where({ col: 1 }).build(),
"SELECT * FROM `table1` WHERE (`col` = 1)"
);
assert.equal(
common.Select().from('t1').where({ col: 'a' }).build(),
"SELECT * FROM `t1` WHERE (`col` = 'a')"
common.Select().from('table1').where({ col: 'a' }).build(),
"SELECT * FROM `table1` WHERE (`col` = 'a')"
);
assert.equal(
common.Select().from('t1').where({ col: 'a\'' }).build(),
"SELECT * FROM `t1` WHERE (`col` = 'a\\'')"
common.Select().from('table1').where({ col: 'a\'' }).build(),
"SELECT * FROM `table1` WHERE (`col` = 'a\\'')"
);
assert.equal(
common.Select().from('t1').where({ col: [ 1, 2, 3 ] }).build(),
"SELECT * FROM `t1` WHERE (`col` IN (1, 2, 3))"
common.Select().from('table1').where({ col: [ 1, 2, 3 ] }).build(),
"SELECT * FROM `table1` WHERE (`col` IN (1, 2, 3))"
);
assert.equal(
common.Select().from('t1').where({ col1: 1, col2: 2 }).build(),
"SELECT * FROM `t1` WHERE (`col1` = 1 AND `col2` = 2)"
common.Select().from('table1').where({ col1: 1, col2: 2 }).build(),
"SELECT * FROM `table1` WHERE (`col1` = 1 AND `col2` = 2)"
);
assert.equal(
common.Select().from('t1').where({ col1: 1 }, { col2: 2 }).build(),
"SELECT * FROM `t1` WHERE (`col1` = 1 AND `col2` = 2)"
common.Select().from('table1').where({ col1: 1 }, { col2: 2 }).build(),
"SELECT * FROM `table1` WHERE (`col1` = 1 AND `col2` = 2)"
);
assert.equal(
common.Select().from('t1').where({ col: 1 }).where({ col: 2 }).build(),
"SELECT * FROM `t1` WHERE (`col` = 1) OR (`col` = 2)"
common.Select().from('table1').where({ col: 1 }).where({ col: 2 }).build(),
"SELECT * FROM `table1` WHERE (`col` = 1) OR (`col` = 2)"
);
assert.equal(
common.Select().from('t1').where({ col1: 1, col2: 2 }).where({ col3: 3 }).build(),
"SELECT * FROM `t1` WHERE (`col1` = 1 AND `col2` = 2) OR (`col3` = 3)"
common.Select().from('table1').where({ col1: 1, col2: 2 }).where({ col3: 3 }).build(),
"SELECT * FROM `table1` WHERE (`col1` = 1 AND `col2` = 2) OR (`col3` = 3)"
);

@@ -59,3 +59,3 @@

.where('table1', { col: 1 }, 'table2', { col: 2 }).build(),
"SELECT * FROM `table1` AS `t1` JOIN `table2` AS `t2` ON `t2`.`id` = `t1`.`id` WHERE (`t1`.`col` = 1 AND `t2`.`col` = 2)"
"SELECT * FROM `table1` `t1` JOIN `table2` `t2` ON `t2`.`id` = `t1`.`id` WHERE (`t1`.`col` = 1 AND `t2`.`col` = 2)"
);

@@ -67,43 +67,43 @@

.where('table1', { col: 1 }, { col: 2 }).build(),
"SELECT * FROM `table1` AS `t1` JOIN `table2` AS `t2` ON `t2`.`id` = `t1`.`id` WHERE (`t1`.`col` = 1 AND `col` = 2)"
"SELECT * FROM `table1` `t1` JOIN `table2` `t2` ON `t2`.`id` = `t1`.`id` WHERE (`t1`.`col` = 1 AND `col` = 2)"
);
assert.equal(
common.Select().from('t1').where({ col: common.Query.gt(1) }).build(),
"SELECT * FROM `t1` WHERE (`col` > 1)"
common.Select().from('table1').where({ col: common.Query.gt(1) }).build(),
"SELECT * FROM `table1` WHERE (`col` > 1)"
);
assert.equal(
common.Select().from('t1').where({ col: common.Query.gte(1) }).build(),
"SELECT * FROM `t1` WHERE (`col` >= 1)"
common.Select().from('table1').where({ col: common.Query.gte(1) }).build(),
"SELECT * FROM `table1` WHERE (`col` >= 1)"
);
assert.equal(
common.Select().from('t1').where({ col: common.Query.lt(1) }).build(),
"SELECT * FROM `t1` WHERE (`col` < 1)"
common.Select().from('table1').where({ col: common.Query.lt(1) }).build(),
"SELECT * FROM `table1` WHERE (`col` < 1)"
);
assert.equal(
common.Select().from('t1').where({ col: common.Query.lte(1) }).build(),
"SELECT * FROM `t1` WHERE (`col` <= 1)"
common.Select().from('table1').where({ col: common.Query.lte(1) }).build(),
"SELECT * FROM `table1` WHERE (`col` <= 1)"
);
assert.equal(
common.Select().from('t1').where({ col: common.Query.eq(1) }).build(),
"SELECT * FROM `t1` WHERE (`col` = 1)"
common.Select().from('table1').where({ col: common.Query.eq(1) }).build(),
"SELECT * FROM `table1` WHERE (`col` = 1)"
);
assert.equal(
common.Select().from('t1').where({ col: common.Query.ne(1) }).build(),
"SELECT * FROM `t1` WHERE (`col` <> 1)"
common.Select().from('table1').where({ col: common.Query.ne(1) }).build(),
"SELECT * FROM `table1` WHERE (`col` <> 1)"
);
assert.equal(
common.Select().from('t1').where({ col: common.Query.between('a', 'b') }).build(),
"SELECT * FROM `t1` WHERE (`col` BETWEEN 'a' AND 'b')"
common.Select().from('table1').where({ col: common.Query.between('a', 'b') }).build(),
"SELECT * FROM `table1` WHERE (`col` BETWEEN 'a' AND 'b')"
);
assert.equal(
common.Select().from('t1').where({ col: common.Query.like('abc') }).build(),
"SELECT * FROM `t1` WHERE (`col` LIKE 'abc')"
common.Select().from('table1').where({ col: common.Query.like('abc') }).build(),
"SELECT * FROM `table1` WHERE (`col` LIKE 'abc')"
);
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