New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More →

node-sql-2

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-sql-2 - npm Package Compare versions

Comparing version

to
0.80.0

@@ -156,3 +156,5 @@ 'use strict';

descending : orderMethod('DESC'),
case : caseMethod
case : caseMethod,
existsKeyElement :binaryMethod('?|'),
existsAllKeyElements :binaryMethod('?&')
};

@@ -159,0 +161,0 @@ };

@@ -181,2 +181,4 @@

}
array(arr:T[]):BinaryNode
}

@@ -217,2 +219,4 @@

desc:OrderByValueNode
existsKeyElement(node:BinaryNode):BinaryNode
existsAllKeyElements(node:BinaryNode):BinaryNode
}

@@ -219,0 +223,0 @@

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

"description": "sql builder",
"version": "0.79.0",
"version": "0.80.0",
"homepage": "https://github.com/TokyoFarmer/node-sql-2",

@@ -16,3 +16,3 @@ "license": "MIT",

"scripts": {
"test": "node_modules/.bin/mocha",
"test": "mocha",
"lint": "jshint lib test",

@@ -30,4 +30,8 @@ "posttest": "jshint lib test"

"jshint": "*",
"mocha": "*"
"mocha": ">6.0.0"
},
"mocha": {
"reporter": "dot",
"ui": "tdd"
}
}

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

describe('column', function() {
suite('column', function() {
var table = sql.define({

@@ -13,24 +13,24 @@ name: 'user',

it('can be accessed by property and array', function() {
test('can be accessed by property and array', function() {
assert.equal(table.created, table.columns[1], 'should be able to access created both by array and property');
});
describe('toQuery()', function() {
it('works', function() {
suite('toQuery()', function() {
test('works', function() {
assert.equal(table.id.toQuery().text, '"user"."id"');
});
it('works with a column name of "alias"', function() {
test('works with a column name of "alias"', function() {
assert.equal(table.alias.toQuery().text, '"user"."alias"');
});
it('respects AS rename', function() {
test('respects AS rename', function() {
assert.equal(table.id.as('userId').toQuery().text, '"user"."id" AS "userId"');
});
it('respects count and distinct', function() {
test('respects count and distinct', function() {
assert.equal(table.id.count().distinct().as("userIdCount").toQuery().text, 'COUNT(DISTINCT("user"."id")) AS "userIdCount"');
});
describe('in subquery with min', function() {
suite('in subquery with min', function() {
var subquery = table.subQuery('subTable').select(table.id.min().as('subId'));

@@ -41,3 +41,3 @@ var col = subquery.subId.toQuery().text;

describe('property', function() {
suite('property', function() {
var table = sql.define({

@@ -49,15 +49,15 @@ name: 'roundtrip',

});
it('used as alias when !== column name', function() {
test('used as alias when !== column name', function() {
assert.equal(table.propertyName.toQuery().text, '"roundtrip"."column_name" AS "propertyName"');
});
it('uses explicit alias when !== column name', function() {
test('uses explicit alias when !== column name', function() {
assert.equal(table.propertyName.as('alias').toQuery().text, '"roundtrip"."column_name" AS "alias"');
});
it('maps to column name in insert', function() {
test('maps to column name in insert', function() {
assert.equal(table.insert({propertyName:'propVal'}).toQuery().text, 'INSERT INTO "roundtrip" ("column_name") VALUES ($1)');
});
it('maps to column name in update', function() {
test('maps to column name in update', function() {
assert.equal(table.update({propertyName:'propVal'}).toQuery().text, 'UPDATE "roundtrip" SET "column_name" = $1');
});
it('explicitly selected by *', function() {
test('explicitly selected by *', function() {
assert.equal(table.select(table.star()).from(table).toQuery().text, 'SELECT "roundtrip"."column_name" AS "propertyName" FROM "roundtrip"');

@@ -67,3 +67,3 @@ });

describe('autoGenerate', function() {
suite('autoGenerate', function() {
var table = sql.define({

@@ -76,6 +76,6 @@ name: 'ag',

});
it('does not include auto generated columns in insert', function() {
test('does not include auto generated columns in insert', function() {
assert.equal(table.insert({id:0, name:'name'}).toQuery().text,'INSERT INTO "ag" ("name") VALUES ($1)');
});
it('does not include auto generated columns in update', function() {
test('does not include auto generated columns in update', function() {
assert.equal(table.update({id:0, name:'name'}).toQuery().text,'UPDATE "ag" SET "name" = $1');

@@ -85,3 +85,3 @@ });

describe('white listed', function() {
suite('white listed', function() {
var table = sql.define({

@@ -92,6 +92,6 @@ name: 'wl',

});
it('excludes insert properties that are not a column', function() {
test('excludes insert properties that are not a column', function() {
assert.equal(table.insert({id:0, _private:'_private', name:'name'}).toQuery().text, 'INSERT INTO "wl" ("id", "name") VALUES ($1, $2)');
});
it('excludes update properties that are not a column', function() {
test('excludes update properties that are not a column', function() {
assert.equal(table.update({id:0, _private:'_private', name:'name'}).toQuery().text, 'UPDATE "wl" SET "id" = $1, "name" = $2');

@@ -101,3 +101,3 @@ });

describe('not white listed', function() {
suite('not white listed', function() {
var table = sql.define({

@@ -107,6 +107,6 @@ name: 'wl',

});
it('throws for insert properties that are not a column', function() {
test('throws for insert properties that are not a column', function() {
assert.throws(function() { table.insert({id:0, _private:'_private', name:'name'}); }, Error);
});
it('throws for update properties that are not a column', function() {
test('throws for update properties that are not a column', function() {
assert.throws(function() { table.update({id:0, _private:'_private', name:'name'}); }, Error);

@@ -116,3 +116,3 @@ });

describe('snake to camel', function() {
suite('snake to camel', function() {
var table = sql.define({

@@ -126,13 +126,13 @@ name: 'sc',

});
it('for snake column names with no explicit property name', function(){
test('for snake column names with no explicit property name', function(){
assert.equal(table.makeMeCamel.toQuery().text, '"sc"."make_me_camel" AS "makeMeCamel"');
});
it('but not when with explicit property name', function() {
test('but not when with explicit property name', function() {
assert.equal(table.not2Cam.toQuery().text, '"sc"."not_to_camel" AS "not2Cam"');
});
it('does not use property alias within CASE ... END', function() {
test('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() {
test('respects AS rename in RETURNING clause', function() {
assert.equal(table.update({makeMeCamel:0}).returning(table.makeMeCamel.as('rename')).toQuery().text,

@@ -139,0 +139,0 @@ 'UPDATE "sc" SET "make_me_camel" = $1 RETURNING "make_me_camel" AS "rename"');

@@ -97,1 +97,23 @@ 'use strict';

});
Harness.test({
query: post.select(
post.tags.existsKeyElement(Sql.array('nodejs', 'js', 'node'))
),
pg: {
text : 'SELECT ("post"."tags" ?| ARRAY[$1, $2, $3]) FROM "post"',
string: 'SELECT ("post"."tags" ?| ARRAY[\'nodejs\', \'js\', \'node\']) FROM "post"'
},
params: ['nodejs', 'js', 'node']
});
Harness.test({
query: post.select(
post.tags.existsAllKeyElements(Sql.array('nodejs', 'js'))
),
pg: {
text : 'SELECT ("post"."tags" ?& ARRAY[$1, $2]) FROM "post"',
string: 'SELECT ("post"."tags" ?& ARRAY[\'nodejs\', \'js\']) FROM "post"'
},
params: ['nodejs', 'js']
});