Move from grunt to gulp
This commit is contained in:
parent
002d21b25f
commit
f85358aff0
@ -1,9 +1,6 @@
|
|||||||
reporting:
|
reporting:
|
||||||
reports:
|
reports:
|
||||||
- lcov
|
- lcov
|
||||||
- clover
|
|
||||||
- text-summary
|
|
||||||
- lcovonly
|
- lcovonly
|
||||||
report-config:
|
report-config:
|
||||||
clover: {file: ../build/clover.xml}
|
lcovonly: {file: ../coverage/lcov.info}
|
||||||
lcovonly: {file: ../build/lcov.info}
|
|
@ -11,8 +11,11 @@ node_js:
|
|||||||
- "0.10"
|
- "0.10"
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
|
- npm install -g gulp
|
||||||
- psql -c 'DROP DATABASE IF EXISTS test;' -U postgres
|
- psql -c 'DROP DATABASE IF EXISTS test;' -U postgres
|
||||||
- psql -c 'create database test;' -U postgres
|
- psql -c 'create database test;' -U postgres
|
||||||
- mysql -e 'create database IF NOT EXISTS test;'
|
- mysql -e 'create database IF NOT EXISTS test;'
|
||||||
- mysql -v -uroot test < ./tests/sql/mysql.sql
|
- mysql -v -uroot test < ./tests/sql/mysql.sql
|
||||||
- psql test postgres -f ./tests/sql/pgsql.sql
|
- psql test postgres -f ./tests/sql/pgsql.sql
|
||||||
|
|
||||||
|
script: gulp
|
30
Gruntfile.js
30
Gruntfile.js
@ -1,30 +0,0 @@
|
|||||||
module.exports = function(grunt) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Project configuration
|
|
||||||
grunt.initConfig({
|
|
||||||
pkg: grunt.file.readJSON('package.json'),
|
|
||||||
jsdoc: {
|
|
||||||
dist: {
|
|
||||||
src: ['lib/*.js', 'README.md'],
|
|
||||||
options: {
|
|
||||||
destination: 'docs'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
nodeunit: {
|
|
||||||
all: ['tests/**/*_test.js'],
|
|
||||||
options: {
|
|
||||||
reporter: 'verbose'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
grunt.loadNpmTasks('grunt-jsdoc');
|
|
||||||
grunt.loadNpmTasks('grunt-contrib-nodeunit');
|
|
||||||
|
|
||||||
|
|
||||||
grunt.registerTask('default', ['nodeunit','jsdoc']);
|
|
||||||
grunt.registerTask('tests', 'nodeunit');
|
|
||||||
grunt.registerTask('docs', 'jsdoc');
|
|
||||||
};
|
|
30
gulpfile.js
Normal file
30
gulpfile.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
var gulp = require('gulp'),
|
||||||
|
documentation = require('gulp-documentation'),
|
||||||
|
nodeunit_runner = require('gulp-nodeunit-runner'),
|
||||||
|
istanbul = require('gulp-istanbul');
|
||||||
|
|
||||||
|
gulp.task('default', ['docs', 'test']);
|
||||||
|
|
||||||
|
gulp.task('docs', function() {
|
||||||
|
gulp.src('./lib/node-query.js')
|
||||||
|
.pipe(documentation({format: 'html'}))
|
||||||
|
.pipe(gulp.dest('docs'));
|
||||||
|
gulp.src('./lib/node-query.js')
|
||||||
|
.pipe(documentation({format: 'md'}))
|
||||||
|
.pipe(gulp.dest('api-docs'));
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('pre-test', function() {
|
||||||
|
return gulp.src(['lib/**/*.js'])
|
||||||
|
.pipe(istanbul())
|
||||||
|
.pipe(istanbul.hookRequire());
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('test', ['pre-test'], function() {
|
||||||
|
return gulp.src(['tests/**/*_test.js'])
|
||||||
|
.pipe(nodeunit_runner())
|
||||||
|
.pipe(istanbul.writeReports({
|
||||||
|
dir: './coverage',
|
||||||
|
reporters: ['lcov', 'lcovonly', 'html', 'text']
|
||||||
|
}));
|
||||||
|
});
|
@ -11,7 +11,7 @@ module.exports = {
|
|||||||
* @param {Function} callback - Callback to run when a response is recieved
|
* @param {Function} callback - Callback to run when a response is recieved
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
execute: function(sql, params, callback) {
|
execute: function(/*sql, params, callback*/) {
|
||||||
throw new Error("Correct adapter not defined for query execution");
|
throw new Error("Correct adapter not defined for query execution");
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -22,7 +22,7 @@ var Pg = function(instance) {
|
|||||||
|
|
||||||
// Replace question marks with numbered placeholders, because this adapter is different...
|
// Replace question marks with numbered placeholders, because this adapter is different...
|
||||||
var count = 0;
|
var count = 0;
|
||||||
args.sql = args.sql.replace(/\?/g, function(match, offset, string) {
|
args.sql = args.sql.replace(/\?/g, function() {
|
||||||
count++;
|
count++;
|
||||||
return '$' + count;
|
return '$' + count;
|
||||||
});
|
});
|
||||||
|
@ -8,7 +8,8 @@ var helpers = require('./helpers');
|
|||||||
* @module driver
|
* @module driver
|
||||||
*/
|
*/
|
||||||
var d = {
|
var d = {
|
||||||
identifierChar: '"',
|
identifierStartChar: '"',
|
||||||
|
identifierEndChar: '"',
|
||||||
tablePrefix: null,
|
tablePrefix: null,
|
||||||
hasTruncate: true,
|
hasTruncate: true,
|
||||||
|
|
||||||
@ -20,8 +21,8 @@ var d = {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_quote: function(str) {
|
_quote: function(str) {
|
||||||
return (helpers.isString(str) && ! (str.startsWith(d.identifierChar) || str.endsWith(d.identifierChar)))
|
return (helpers.isString(str) && ! (str.startsWith(d.identifierStartChar) || str.endsWith(d.identifierEndChar)))
|
||||||
? d.identifierChar + str + d.identifierChar
|
? d.identifierStartChar + str + d.identifierEndChar
|
||||||
: str;
|
: str;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ var d = {
|
|||||||
*/
|
*/
|
||||||
quoteIdentifiers: function(str) {
|
quoteIdentifiers: function(str) {
|
||||||
var hiers, raw;
|
var hiers, raw;
|
||||||
var pattern = new RegExp(d.identifierChar + '(' + '([a-zA-Z0-9_]+)' + '(\((.*?)\))' + ')' + d.identifierChar, 'ig');
|
var pattern = new RegExp(d.identifierStartChar + '(' + '([a-zA-Z0-9_]+)' + '(\((.*?)\))' + ')' + d.identifierEndChar, 'ig');
|
||||||
|
|
||||||
// Recurse for arrays of identifiiers
|
// Recurse for arrays of identifiiers
|
||||||
if (Array.isArray(str))
|
if (Array.isArray(str))
|
||||||
@ -122,10 +123,15 @@ var d = {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
insertBatch: function(table, data) {
|
insertBatch: function(table, data) {
|
||||||
|
var vals = [],
|
||||||
|
fields = Object.keys(data[0]),
|
||||||
|
sql = "",
|
||||||
|
params = [],
|
||||||
|
paramString = "",
|
||||||
|
paramList = [];
|
||||||
|
|
||||||
// Get the data values to insert, so they can
|
// Get the data values to insert, so they can
|
||||||
// be parameterized
|
// be parameterized
|
||||||
var vals = [];
|
|
||||||
data.forEach(function(obj) {
|
data.forEach(function(obj) {
|
||||||
Object.keys(obj).forEach(function(key) {
|
Object.keys(obj).forEach(function(key) {
|
||||||
vals.push(obj[key]);
|
vals.push(obj[key]);
|
||||||
@ -134,17 +140,16 @@ var d = {
|
|||||||
|
|
||||||
// Get the field names from the keys of the first
|
// Get the field names from the keys of the first
|
||||||
// object inserted
|
// object inserted
|
||||||
var fields = Object.keys(data[0]);
|
|
||||||
table = d.quoteTable(table);
|
table = d.quoteTable(table);
|
||||||
|
|
||||||
var sql = "INSERT INTO " + table + " ("
|
sql += "INSERT INTO " + table + " ("
|
||||||
+ d.quoteIdentifiers(fields).join(",")
|
+ d.quoteIdentifiers(fields).join(",")
|
||||||
+ ") VALUES ";
|
+ ") VALUES ";
|
||||||
|
|
||||||
// Create placeholder groups
|
// Create placeholder groups
|
||||||
var params = new Array(fields.length).fill('?');
|
params = Array(fields.length).fill('?');
|
||||||
var paramString = "(" + params.join(',') + ")";
|
paramString = "(" + params.join(',') + ")";
|
||||||
var paramList = new Array(data.length).fill(paramString);
|
paramList = Array(data.length).fill(paramString);
|
||||||
|
|
||||||
sql += paramList.join(',');
|
sql += paramList.join(',');
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@ module.exports = (function() {
|
|||||||
var driver = require('../driver'),
|
var driver = require('../driver'),
|
||||||
helpers = require('../helpers');
|
helpers = require('../helpers');
|
||||||
|
|
||||||
driver.identifierChar = '`';
|
driver.identifierStartChar = '`';
|
||||||
|
driver.identifierEndChar = '`';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override default limit method because mysql likes to be different
|
* Override default limit method because mysql likes to be different
|
||||||
|
@ -1,16 +1,71 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Driver for PostgreSQL databases
|
* Driver for Sqlite databases
|
||||||
*
|
*
|
||||||
* @module drivers/pg
|
* @module drivers/sqlite
|
||||||
*/
|
*/
|
||||||
module.exports = (function() {
|
module.exports = (function() {
|
||||||
delete require.cache[require.resolve('../driver')];
|
delete require.cache[require.resolve('../driver')];
|
||||||
var driver = require('../driver');
|
var driver = require('../driver'),
|
||||||
|
helpers = require('../helpers');
|
||||||
|
|
||||||
// Sqlite doesn't have a truncate command
|
// Sqlite doesn't have a truncate command
|
||||||
driver.hasTruncate = false;
|
driver.hasTruncate = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL to insert a group of rows
|
||||||
|
* Override default to have better compatibility
|
||||||
|
*
|
||||||
|
* @param {String} table - The table to insert to
|
||||||
|
* @param {Array} [data] - The array of object containing data to insert
|
||||||
|
* @return {String}
|
||||||
|
*/
|
||||||
|
driver.insertBatch = function(table, data) {
|
||||||
|
|
||||||
|
// Get the data values to insert, so they can
|
||||||
|
// be parameterized
|
||||||
|
var sql = "",
|
||||||
|
vals = [],
|
||||||
|
cols = [],
|
||||||
|
fields = [],
|
||||||
|
first = data.shift(),
|
||||||
|
params = [],
|
||||||
|
paramString = "",
|
||||||
|
paramList = [];
|
||||||
|
|
||||||
|
|
||||||
|
data.forEach(function(obj) {
|
||||||
|
var row = [];
|
||||||
|
Object.keys(obj).forEach(function(key) {
|
||||||
|
row.push(obj[key]);
|
||||||
|
});
|
||||||
|
vals.push(row);
|
||||||
|
});
|
||||||
|
|
||||||
|
sql += "INSERT INTO " + driver.quoteTable(table) + "\n";
|
||||||
|
|
||||||
|
// Get the field names from the keys of the first
|
||||||
|
// object to be inserted
|
||||||
|
fields = Object.keys(first);
|
||||||
|
Object.keys(first).forEach(function(key) {
|
||||||
|
cols.push("'" + driver._quote(first[key]) + "' AS " + driver.quoteIdentifiers(key));
|
||||||
|
});
|
||||||
|
|
||||||
|
sql += "SELECT " + cols.join(', ') + "\n";
|
||||||
|
|
||||||
|
vals.forEach(function(row_values) {
|
||||||
|
var quoted = row_values.map(function(value) {
|
||||||
|
return String(value).replace("'", "'\'");
|
||||||
|
});
|
||||||
|
sql += "UNION ALL SELECT '" + quoted.join("', '") + "'\n";
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
sql: sql,
|
||||||
|
values: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return driver;
|
return driver;
|
||||||
}());
|
}());
|
@ -1,7 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/** @module helpers */
|
/** @module helpers */
|
||||||
require('es6-shim');
|
|
||||||
|
|
||||||
/** @alias module:helpers */
|
/** @alias module:helpers */
|
||||||
var h = {
|
var h = {
|
||||||
|
18
package.json
18
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ci-node-query",
|
"name": "ci-node-query",
|
||||||
"version": "2.2.0",
|
"version": "2.2.1",
|
||||||
"description": "A query builder for node based on the one in CodeIgniter",
|
"description": "A query builder for node based on the one in CodeIgniter",
|
||||||
"author": "Timothy J Warren <tim@timshomepage.net>",
|
"author": "Timothy J Warren <tim@timshomepage.net>",
|
||||||
"engines": {
|
"engines": {
|
||||||
@ -33,9 +33,7 @@
|
|||||||
},
|
},
|
||||||
"main": "lib/node-query.js",
|
"main": "lib/node-query.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"es6-shim": "*",
|
|
||||||
"getargs": "",
|
"getargs": "",
|
||||||
"grunt-istanbul": "*",
|
|
||||||
"mysql": "^2.9.0",
|
"mysql": "^2.9.0",
|
||||||
"mysql2": "^0.15.8",
|
"mysql2": "^0.15.8",
|
||||||
"node-firebird": "^0.7.0",
|
"node-firebird": "^0.7.0",
|
||||||
@ -47,14 +45,14 @@
|
|||||||
"pg": "*"
|
"pg": "*"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"documentation": "",
|
||||||
"nodeunit": "",
|
"nodeunit": "",
|
||||||
"grunt": "",
|
"gulp": "",
|
||||||
"grunt-cli": "",
|
"gulp-documentation": "",
|
||||||
"grunt-contrib-clean": "^0.6.0",
|
"gulp-istanbul": "",
|
||||||
"grunt-contrib-nodeunit": "^0.4.1",
|
"gulp-nodeunit-runner": "",
|
||||||
"grunt-istanbul": "",
|
"jsdoc": "",
|
||||||
"grunt-jsdoc": ">=0.6.1",
|
"istanbul": ""
|
||||||
"jsdoc": ""
|
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
sonar.projectKey=node-query
|
sonar.projectKey=node-query
|
||||||
sonar.projectName=NodeJS Query Builder
|
sonar.projectName=NodeJS Query Builder
|
||||||
sonar.projectVersion=1.0
|
sonar.projectVersion=2.2.1
|
||||||
sonar.sources=lib
|
sonar.sources=lib
|
||||||
sonar.javascript.lcov.reportPath=build/lcov.info
|
sonar.javascript.lcov.reportPath=coverage/lcov.info
|
@ -12,7 +12,7 @@ var connection = null;
|
|||||||
|
|
||||||
// Set up the connection
|
// Set up the connection
|
||||||
try {
|
try {
|
||||||
sqlite = require(adapterName).withSQLite('3.8.6+');
|
sqlite = require(adapterName).withSQLite('3.7.11');
|
||||||
connection = sqlite(':memory:');
|
connection = sqlite(':memory:');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Export an empty testsuite if module not loaded
|
// Export an empty testsuite if module not loaded
|
||||||
@ -44,7 +44,7 @@ if (connection)
|
|||||||
rows = {};
|
rows = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
test.ok(rows, 'dblite: Valid result for generated query');
|
test.ok(rows, 'dblite: Invalid result for generated query');
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,16 +19,7 @@ var connection = mysql2.createConnection(config.conn);
|
|||||||
var nodeQuery = require('../../lib/node-query');
|
var nodeQuery = require('../../lib/node-query');
|
||||||
var qb = nodeQuery.init('mysql', connection, adapterName);
|
var qb = nodeQuery.init('mysql', connection, adapterName);
|
||||||
|
|
||||||
// Set up the test base
|
|
||||||
testBase._setUp(qb, function(test, err, rows) {
|
|
||||||
if (err != null) {
|
|
||||||
test.done();
|
|
||||||
throw new Error(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
test.ok(rows, 'mysql2: Valid result for generated query');
|
|
||||||
test.done();
|
|
||||||
});
|
|
||||||
|
|
||||||
tests['nodeQuery.getQuery = nodeQuery.init'] = function(test) {
|
tests['nodeQuery.getQuery = nodeQuery.init'] = function(test) {
|
||||||
test.expect(1);
|
test.expect(1);
|
||||||
@ -46,5 +37,15 @@ tests["mysql2 adapter with query builder"] = function(test) {
|
|||||||
test.done();
|
test.done();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Set up the test base
|
||||||
|
testBase._setUp(qb, function(test, err, rows) {
|
||||||
|
if (err != null) {
|
||||||
|
test.done();
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
test.ok(rows, 'mysql2: Invalid result for generated query');
|
||||||
|
test.done();
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = tests;
|
module.exports = tests;
|
@ -352,10 +352,6 @@ module.exports = (function QueryBuilderTestBase() {
|
|||||||
setUp: function(callback) {
|
setUp: function(callback) {
|
||||||
var sql = base.qb.driver.truncate('create_test');
|
var sql = base.qb.driver.truncate('create_test');
|
||||||
base.qb.adapter.execute(sql, function(err, result) {
|
base.qb.adapter.execute(sql, function(err, result) {
|
||||||
if (err) {
|
|
||||||
throw new Error(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user