Fix mysql insert batch tests

This commit is contained in:
Timothy Warren 2016-02-10 13:09:06 -05:00
parent 763a29d733
commit 383d632bb0
6 changed files with 64 additions and 39 deletions

View File

@ -89,7 +89,7 @@ gulp.task('sloc', () => gulp.src(SRC_FILES).pipe(sloc()));
gulp.task('test-sloc', () => gulp.src(TEST_FILES).pipe(sloc()));
gulp.task('docs', () => {
gulp.src(['lib/**/*.js'])
gulp.src(['lib/*.js'])
.pipe(documentation({format: 'html'}))
.pipe(gulp.dest('docs'));
gulp.src(['lib/*.js'])

View File

@ -1,6 +1,7 @@
'use strict';
let helpers = require('./helpers');
const XRegExp = require('xregexp');
const helpers = require('./helpers');
// --------------------------------------------------------------------------
@ -20,7 +21,7 @@ class QueryParser {
constructor(driver) {
this.driver = driver;
let matchPatterns = {
const matchPatterns = {
function: /([a-z0-9_]+\((.*)\))/i,
operator: /\!=?|\=|\+|&&?|~|\|\|?|\^|\/|<>|>=?|<=?|\-|%|OR|AND|NOT|XOR/ig,
literal: /([0-9]+)|'(.*?)'|true|false/ig,
@ -28,21 +29,21 @@ class QueryParser {
// Full pattern for identifiers
// Making sure that literals and functions aren't matched
matchPatterns.identifier = new RegExp(
'('
+ '(?!'
+ matchPatterns['function'].source + '|'
+ matchPatterns.literal.source
+ ')'
+ '([a-z_\-]+[0-9]*\\.?)'
+ ')+', 'ig');
matchPatterns.identifier = XRegExp(
`(
(?!
${matchPatterns['function'].source}|
${matchPatterns.literal.source}
)
([a-z_\-]+[0-9]*\\.?)
)+`, 'igx');
// Full pattern for determining ordering of the pieces
matchPatterns.joinCombined = new RegExp(
matchPatterns['function'].source + '+|'
+ matchPatterns.literal.source + '+|'
+ matchPatterns.identifier.source
+ '|(' + matchPatterns.operator.source + ')+', 'ig');
matchPatterns.joinCombined = XRegExp(
`${matchPatterns['function'].source}+| # functions
${matchPatterns.literal.source}+| # literal values
${matchPatterns.identifier.source} # identifiers
|(${matchPatterns.operator.source})+`, 'igx');
this.matchPatterns = matchPatterns;
this.identifierBlacklist = ['true', 'false', 'null'];

View File

@ -22,28 +22,6 @@ module.exports = function mysqlBase(qb, nodeQuery, expect, testRunner, promiseTe
return done();
});
});
test('Test Insert Batch', done => {
let data = [
{
id: 544,
key: 3,
val: new Buffer('7'),
}, {
id: 89,
key: 34,
val: new Buffer('10 o\'clock'),
}, {
id: 48,
key: 403,
val: new Buffer('97'),
},
];
qb.insertBatch('create_test', data, (err, rows) => {
expect(err).is.not.ok;
return done();
});
});
/*---------------------------------------------------------------------------
Promise Tests

View File

@ -26,4 +26,27 @@ let qb = nodeQuery.init('mysql', connection, adapterName);
suite('Mysql2 adapter tests -', () => {
require('./mysql-base')(qb, nodeQuery, expect, testRunner, promiseTestRunner);
test('Test Insert Batch', done => {
let data = [
{
id: 5441,
key: 3,
val: new Buffer('7'),
}, {
id: 891,
key: 34,
val: new Buffer('10 o\'clock'),
}, {
id: 481,
key: 403,
val: new Buffer('97'),
},
];
qb.insertBatch('create_test', data, (err, rows) => {
expect(err).is.not.ok;
return done();
});
});
});

View File

@ -26,4 +26,27 @@ let qb = nodeQuery.init('mysql', connection);
suite('Mysql adapter tests -', () => {
require('./mysql-base')(qb, nodeQuery, expect, testRunner, promiseTestRunner);
test('Test Insert Batch', done => {
let data = [
{
id: 544,
key: 3,
val: new Buffer('7'),
}, {
id: 89,
key: 34,
val: new Buffer('10 o\'clock'),
}, {
id: 48,
key: 403,
val: new Buffer('97'),
},
];
qb.insertBatch('create_test', data, (err, rows) => {
expect(err).is.not.ok;
return done();
});
});
});

View File

@ -1,7 +1,7 @@
--ui tdd
--bail
--recursive
--reporter list
--reporter nyan
--slow 200
--timeout 10000
--check-leaks