diff --git a/.travis.yml b/.travis.yml index 07becfb2..81f06d48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,6 @@ language: node_js node_js: - - "5.0" - - "4.2" - - "0.10" - - "0.11" + - "16.15" matrix: allow_failures: - - node_js: "0.10" - - node_js: "0.11" \ No newline at end of file diff --git a/README.md b/README.md index e1a3af8c..061d4ef3 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,14 @@ _sql string builder for node_ - supports PostgreSQL, mysql, Microsoft SQL Server Building SQL statements by hand is no fun, especially in a language which has clumsy support for multi-line strings. -So let's build it with JavaScript. +Forked because we needed this package working (with out any security vulnerabilities), and brianc/node-sql is stale and is not taking pull requests https://github.com/brianc/node-sql/pull/423 -Maybe it's still not fun, but at least it's _less not fun_. - -[![Build Status](https://secure.travis-ci.org/brianc/node-sql.png)](http://travis-ci.org/brianc/node-sql) +[![Build Status](https://app.travis-ci.com/atul898/node-sql.svg)](https://app.travis-ci.com/github/atul898/node-sql) ## install ```sh -$ npm install sql +$ npm install @atul898/node-sql ``` ## use diff --git a/package.json b/package.json index dc250c01..fc1295d6 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,18 @@ { - "author": "brianc ", - "name": "sql", - "description": "sql builder", - "version": "0.78.0", - "homepage": "https://github.com/brianc/node-sql", + "author": "Atul ", + "name": "@atul898/node-sql", + "description": "sql builder, forked from https://github.com/brianc/node-sql since that package has gone stale, this is forked so we can keep it udpated, so 'npm audit' does not have any issue", + "version": "1.0.2", + "homepage": "https://github.com/atul898/node-sql", "license": "MIT", "repository": { "type": "git", - "url": "git://github.com/brianc/node-sql.git" + "url": "git://github.com/atul898/node-sql.git" }, "main": "lib/", "types": "lib/types.d.ts", "scripts": { - "test": "node_modules/.bin/mocha", + "test": "mocha", "lint": "jshint lib test", "posttest": "jshint lib test" }, @@ -20,8 +20,8 @@ "node": "*" }, "dependencies": { - "sliced": "0.0.x", - "lodash": "4.1.x" + "sliced": "1.0.x", + "lodash": "4.17.x" }, "devDependencies": { "jshint": "*", diff --git a/test/binary-clause-tests.js b/test/binary-clause-tests.js index 10c50737..9d4f6157 100644 --- a/test/binary-clause-tests.js +++ b/test/binary-clause-tests.js @@ -8,7 +8,7 @@ var Foo = Table.define({ columns: ['baz','bar'] }); -test('operators', function() { +it ('operators', function() { assert.equal(Foo.baz.equals(1).operator, '='); assert.equal(Foo.baz.equal(1).operator, '='); assert.equal(Foo.baz.notEqual(1).operator, '<>'); diff --git a/test/clause-definition.js b/test/clause-definition.js index ebbf936d..993233af 100644 --- a/test/clause-definition.js +++ b/test/clause-definition.js @@ -15,7 +15,7 @@ var Boom = Node.define({ } }); -test('clause definition', function() { +it('clause definition', function() { var select = new Bang(); assert.equal(select.type, 'SELECT'); assert.equal(select.nodes.length, 0); diff --git a/test/dialects/support.js b/test/dialects/support.js index 4a9fa427..5739b3da 100644 --- a/test/dialects/support.js +++ b/test/dialects/support.js @@ -22,7 +22,7 @@ module.exports = { var DialectClass = dialects[dialect]; var title = dialect + ': ' + (expected.title || expectedObject.text || expectedObject); - test(title, function() { + it(title, function() { // check if this query is expected to throw if (expectedObject.throws) { diff --git a/test/function-tests.js b/test/function-tests.js index 6c53072d..8edde5b2 100644 --- a/test/function-tests.js +++ b/test/function-tests.js @@ -13,15 +13,15 @@ var user = sql.define({ ] }); -suite('function', function() { - test('alias function call', function() { +describe('function', function() { + it('alias function call', function() { var upper = sql.functions.UPPER; var aliasedUpper = upper(user.email).as('upperAlias').toQuery(); assert.equal(aliasedUpper.text, 'UPPER("user"."email") AS "upperAlias"'); }); - test('function call on aliased column', function() { + it('function call on aliased column', function() { var round = sql.functions.ROUND; var aliasedRound = round(user.howOld, 2).toQuery(); @@ -29,7 +29,7 @@ suite('function', function() { assert.equal(aliasedRound.values[0], 2); }); - test('creating function call works', function() { + it('creating function call works', function() { var upper = sql.functionCallCreator('UPPER'); var functionCall = upper('hello', 'world').toQuery(); @@ -38,7 +38,7 @@ suite('function', function() { assert.equal(functionCall.values[1], 'world'); }); - test('creating function call on columns works', function() { + it('creating function call on columns works', function() { var upper = sql.functionCallCreator('UPPER'); var functionCall = upper(user.id, user.email).toQuery(); @@ -46,7 +46,7 @@ suite('function', function() { assert.equal(functionCall.values.length, 0); }); - test('function call inside select works', function() { + it('function call inside select works', function() { var upper = sql.functionCallCreator('UPPER'); var query = sql.select(upper(user.id, user.email)).from(user).where(user.email.equals('brian.m.carlson@gmail.com')).toQuery(); @@ -54,7 +54,7 @@ suite('function', function() { assert.equal(query.values[0], 'brian.m.carlson@gmail.com'); }); - test('standard aggregate functions with having clause', function() { + it('standard aggregate functions with having clause', function() { var count = sql.functions.COUNT; var distinct = sql.functions.DISTINCT; var distinctEmailCount = count(distinct(user.email)); @@ -65,7 +65,7 @@ suite('function', function() { assert.equal(query.values[0], 100); }); - test('custom and standard functions behave the same', function() { + it('custom and standard functions behave the same', function() { var standardUpper = sql.functions.UPPER; var customUpper = sql.functionCallCreator('UPPER'); @@ -77,7 +77,7 @@ suite('function', function() { assert.equal(customQuery.text, expectedQuery); }); - test('combine function with operations', function() { + it('combine function with operations', function() { var f = sql.functions; var query = user.select(f.AVG(f.DISTINCT(f.COUNT(user.id).plus(f.MAX(user.id))).minus(f.MIN(user.id))).multiply(100)).toQuery(); @@ -85,7 +85,7 @@ suite('function', function() { assert.equal(query.values[0], 100); }); - test('use custom function', function() { + it('use custom function', function() { var query = user.select(sql.function('PHRASE_TO_TSQUERY')('simple', user.name)).toQuery(); assert.equal(query.text, 'SELECT PHRASE_TO_TSQUERY($1, "user"."name") FROM "user"'); assert.equal(query.values[0], 'simple'); diff --git a/test/index-tests.js b/test/index-tests.js index f25839e1..082a8b31 100644 --- a/test/index-tests.js +++ b/test/index-tests.js @@ -8,55 +8,55 @@ var user = sql.define({ columns: ['id', 'email'] }); -suite('index', function() { - test('unknown dialect throws exception', function() { +describe('index', function() { + it('unknown dialect throws exception', function() { assert.throws(function() { sql.setDialect('asdf'); }); }); - test('stores the default dialect\'s name if none has been passed', function() { + it('stores the default dialect\'s name if none has been passed', function() { assert.equal(sql.create().dialectName, 'postgres'); }); - test('stores the sqlite dialect', function() { + it('stores the sqlite dialect', function() { assert.equal(sql.create('sqlite').dialectName, 'sqlite'); }); - test('stores the mysql dialect', function() { + it('stores the mysql dialect', function() { assert.equal(sql.create('mysql').dialectName, 'mysql'); }); - test('stores the mssql dialect', function() { + it('stores the mssql dialect', function() { assert.equal(sql.create('mssql').dialectName, 'mssql'); }); - test('stores the oracle dialect', function() { + it('stores the oracle dialect', function() { assert.equal(sql.create('oracle').dialectName, 'oracle'); }); - test('can create a query using the default dialect', function() { + it('can create a query using the default dialect', function() { var query = sql.select(user.id).from(user).where(user.email.equals('brian.m.carlson@gmail.com')).toQuery(); assert.equal(query.text, 'SELECT "user"."id" FROM "user" WHERE ("user"."email" = $1)'); assert.equal(query.values[0], 'brian.m.carlson@gmail.com'); }); - test('setting dialect to postgres works', function() { + it('setting dialect to postgres works', function() { sql.setDialect('postgres'); var query = sql.select(user.id).from(user).where(user.email.equals('brian.m.carlson@gmail.com')).toQuery(); assert.equal(query.text, 'SELECT "user"."id" FROM "user" WHERE ("user"."email" = $1)'); assert.equal(query.values[0], 'brian.m.carlson@gmail.com'); }); - test('sql.create creates an instance with a new dialect', function() { + it('sql.create creates an instance with a new dialect', function() { var mysql = sql.create('mysql'); var query = mysql.select(user.id).from(user).where(user.email.equals('brian.m.carlson@gmail.com')).toQuery(); assert.equal(query.text, 'SELECT `user`.`id` FROM `user` WHERE (`user`.`email` = ?)'); assert.equal(query.values[0], 'brian.m.carlson@gmail.com'); }); - test('sql.define for parallel dialects work independently', function() { + it('sql.define for parallel dialects work independently', function() { var mssql = sql.create('mssql'); var mysql = sql.create('mysql'); var postgres = sql.create('postgres'); @@ -76,7 +76,7 @@ suite('index', function() { assert.equal(oracleTable.sql, oracle); }); - test('using Sql as a class', function() { + it('using Sql as a class', function() { var Sql = sql.Sql; var mssql = new Sql('mssql'); var mysql = new Sql('mysql'); @@ -91,7 +91,7 @@ suite('index', function() { assert.equal(oracle.dialect, require(__dirname + '/../lib/dialect/oracle')); }); - test('override dialect for toQuery using dialect name', function() { + it('override dialect for toQuery using dialect name', function() { var Sql = sql.Sql; var mssql = new Sql('mssql'); var mysql = new Sql('mysql'); @@ -122,35 +122,35 @@ suite('index', function() { assert.deepEqual(oracleQuery.values, values); }); - test('override dialect for toQuery using invalid dialect name', function() { + it('override dialect for toQuery using invalid dialect name', function() { var query = sql.select(user.id).from(user); assert.throws(function() { query.toQuery('invalid'); }); }); - test('using named queries with toNamedQuery', function() { + it('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() { + it('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() { + it('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() { + it('override dialect for toNamedQuery using dialect name', function() { var Sql = sql.Sql; var mysql = new Sql('mysql'); var postgres = new Sql('postgres'); @@ -188,14 +188,14 @@ suite('index', function() { }); - test('override dialect for toNamedQuery using invalid dialect name', function() { + it('override dialect for toNamedQuery using invalid dialect name', function() { var query = sql.select(user.id).from(user); assert.throws(function() { query.toNamedQuery('name', 'invalid'); }); }); - test('mssql default parameter place holder is @index', function() { + it('mssql default parameter place holder is @index', function() { var Sql = sql.Sql; var mssql = new Sql('mssql'); var query = mssql.select(user.id).from(user).where(user.email.equals('x@y.com')).toQuery(); @@ -203,7 +203,7 @@ suite('index', function() { assert.equal(query.values[0], 'x@y.com'); }); - test('mssql override default parameter placeholder with ?', function() { + it('mssql override default parameter placeholder with ?', function() { var Sql = sql.Sql; var mssql = new Sql('mssql',{questionMarkParameterPlaceholder:true}); var query = mssql.select(user.id).from(user).where(user.email.equals('x@y.com')).toQuery(); diff --git a/test/select-tests.js b/test/select-tests.js index a0befc4c..2accd70f 100644 --- a/test/select-tests.js +++ b/test/select-tests.js @@ -5,11 +5,11 @@ var Select = require(__dirname + '/../lib/node/select'); var select = new Select({sql: require('../lib/index')}); -test('has SELECT type', function() { +it('has SELECT type', function() { assert.equal(select.type, 'SELECT'); }); -test('can go toQuery', function() { +it('can go toQuery', function() { assert.equal(select.toQuery().text, 'SELECT '); }); diff --git a/test/table-tests.js b/test/table-tests.js index 73d43367..bef7c340 100644 --- a/test/table-tests.js +++ b/test/table-tests.js @@ -5,20 +5,20 @@ var Table = require(__dirname + '/../lib/table'); var Column = require(__dirname + '/../lib/column'); var Sql = require('../'); -suite('table', function() { +describe('table', function() { var table = new Table({ name: 'bang' }); - test('has name', function() { + it('has name', function() { assert.equal(table.getName(), 'bang'); }); - test('has no columns', function() { + it('has no columns', function() { assert.equal(table.columns.length, 0); }); - test('can add column', function() { + it('can add column', function() { var col = new Column({ table: table, name: 'boom' @@ -32,17 +32,17 @@ suite('table', function() { assert.equal(table.boom, col); }); - test('creates query node', function() { + it('creates query node', function() { var sel = table.select(table.boom); assert.equal(sel.type, 'QUERY'); }); - test('creates *-query if no args is provided to select()', function() { + it('creates *-query if no args is provided to select()', function() { var sel = table.select(); assert.ok(sel.nodes[0].nodes[0].star); }); - test('can be defined', function() { + it('can be defined', function() { var user = Table.define({ name: 'user', columns: ['id', 'name'] @@ -57,7 +57,7 @@ suite('table', function() { }); }); -test('table with user-defined column property names', function () { +it('table with user-defined column property names', function () { var table = Table.define({ name: 'blah', columns: [{ @@ -78,7 +78,7 @@ test('table with user-defined column property names', function () { assert(table.email === undefined, 'Expected table.email to not exist'); }); -test('table with fancier column definitions', function() { +it('table with fancier column definitions', function() { var table = Table.define({ name: 'blah', columns: [{ @@ -109,7 +109,7 @@ test('table with fancier column definitions', function() { assert.equal(email.anythingYouWant, 'awesome'); }); -test('table with object structured column definitions', function() { +it('table with object structured column definitions', function() { var table = Table.define({ name: 'blah', columns: { @@ -141,7 +141,7 @@ test('table with object structured column definitions', function() { assert.equal(email.anythingYouWant, 'awesome'); }); -test('table with dynamic column definition', function() { +it('table with dynamic column definition', function() { var table = Table.define({ name: 'foo', columns: [] }); assert.equal(table.columns.length, 0); @@ -159,7 +159,7 @@ test('table with dynamic column definition', function() { assert.equal(table.columns.length, 1); }); -test('hasColumn', function() { +it('hasColumn', function() { var table = Table.define({ name: 'foo', columns: [] }); assert.equal(table.hasColumn('baz'), false); @@ -167,7 +167,7 @@ test('hasColumn', function() { assert.equal(table.hasColumn('baz'), true); }); -test('hasColumn with user-defined column property', function() { +it('hasColumn with user-defined column property', function() { var table = Table.define({ name: 'blah', columns: [{ @@ -180,40 +180,40 @@ test('hasColumn with user-defined column property', function() { assert.equal(table.hasColumn('theId'), true); }); -test('the column "from" does not overwrite the from method', function() { +it('the column "from" does not overwrite the from method', function() { var table = Table.define({ name: 'foo', columns: [] }); table.addColumn('from'); assert.equal(typeof table.from, 'function'); }); -test('getColumn returns the from column', function() { +it('getColumn returns the from column', function() { var table = Table.define({ name: 'foo', columns: [] }); table.addColumn('from'); assert(table.getColumn('from') instanceof Column); assert(table.get('from') instanceof Column); }); -test('set and get schema', function () { +it('set and get schema', function () { var table = Table.define({ name: 'foo', schema: 'bar', columns: [] }); assert.equal(table.getSchema(), 'bar'); table.setSchema('barbarz'); assert.equal(table.getSchema(), 'barbarz'); }); -suite('table.clone', function() { - test('check if it is a copy, not just a reference', function() { +describe('table.clone', function() { + it('check if it is a copy, not just a reference', function() { var table = Table.define({ name: 'foo', columns: [] }); var copy = table.clone(); assert.notEqual(table, copy); }); - test('copy columns', function() { + it('copy columns', function() { var table = Table.define({ name: 'foo', columns: ['bar'] }); var copy = table.clone(); assert(copy.get('bar') instanceof Column); }); - test('overwrite config while copying', function() { + it('overwrite config while copying', function() { var table = Table.define({ name: 'foo', schema: 'foobar', @@ -234,7 +234,7 @@ suite('table.clone', function() { }); }); -test('dialects', function () { +it('dialects', function () { var sql = new Sql.Sql('mysql'); var foo = sql.define({ name: 'foo', columns: [ 'id' ] }), bar = sql.define({ name: 'bar', columns: [ 'id' ] }); @@ -249,7 +249,7 @@ test('dialects', function () { assert.equal(actual, '"foo" INNER JOIN "bar" ON ("bar"."id" = 1)'); }); -test('limit', function () { +it('limit', function () { var user = Table.define({name: 'user', columns: ['id', 'name']}); var query = user.limit(3); assert.equal(query.nodes.length, 1); @@ -257,7 +257,7 @@ test('limit', function () { assert.equal(query.nodes[0].count, 3); }); -test('offset', function () { +it('offset', function () { var user = Table.define({name: 'user', columns: ['id', 'name']}); var query = user.offset(20); assert.equal(query.nodes.length, 1); @@ -265,7 +265,7 @@ test('offset', function () { assert.equal(query.nodes[0].count, 20); }); -test('order', function () { +it('order', function () { var user = Table.define({name: 'user', columns: ['id', 'name']}); var query = user.order(user.name); assert.equal(query.nodes.length, 1); diff --git a/test/ternary-clause-tests.js b/test/ternary-clause-tests.js index 1e7c975f..416d6ee7 100644 --- a/test/ternary-clause-tests.js +++ b/test/ternary-clause-tests.js @@ -8,7 +8,7 @@ var Foo = Table.define({ columns: ['baz','bar'] }); -test('operators', function() { +it('operators', function() { assert.equal(Foo.bar.between(1, 2).operator, 'BETWEEN'); assert.equal(Foo.baz.between(1, 2).separator, 'AND'); }); diff --git a/test/unary-clause-tests.js b/test/unary-clause-tests.js index f5b36a1b..d5597ebd 100644 --- a/test/unary-clause-tests.js +++ b/test/unary-clause-tests.js @@ -8,7 +8,7 @@ var Foo = Table.define({ columns: ['baz','bar'] }); -test('operators', function() { +it('operators', function() { assert.equal(Foo.bar.isNull().operator, 'IS NULL'); assert.equal(Foo.baz.isNotNull().operator, 'IS NOT NULL'); }); diff --git a/test/value-expression-tests.js b/test/value-expression-tests.js index ec80415a..9b195951 100644 --- a/test/value-expression-tests.js +++ b/test/value-expression-tests.js @@ -4,8 +4,8 @@ var assert = require('assert'); var valueExpressionMixin = require(__dirname + './../lib/node/valueExpression'); var Node = require(__dirname + './../lib/node'); -suite('value-expression', function() { - test("value expression mixin should not overwrite Node prototype properties", function() { +describe('value-expression', function() { + it("value expression mixin should not overwrite Node prototype properties", function() { var mixin = valueExpressionMixin(); // make sure that the node class doesn't have any conflicting properties