Skip to content

Commit abafca7

Browse files
committed
Merge pull request #377 from maxnachlinger/master
Bulk INSERT is too awesome to not have a test :)
2 parents 8eb068e + 40ea775 commit abafca7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var common = require('../../common');
2+
var connection = common.createConnection();
3+
var assert = require('assert');
4+
var _ = require('underscore');
5+
6+
common.useTestDb(connection);
7+
8+
var table = 'insert_test';
9+
connection.query([
10+
'CREATE TEMPORARY TABLE `' + table + '` (',
11+
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
12+
'`title` varchar(255),',
13+
'PRIMARY KEY (`id`)',
14+
') ENGINE=InnoDB DEFAULT CHARSET=utf8'
15+
].join('\n'));
16+
17+
var result;
18+
var items = [];
19+
var itemsFoundInTable = [];
20+
21+
for(var i = 0; i < 100; i++)
22+
items[i] = ['test '+i];
23+
24+
connection.query('INSERT INTO ' + table + ' (title) VALUES ? ', [items], function(err, _result) {
25+
if (err) throw err;
26+
27+
result = _result;
28+
29+
connection.query('SELECT title FROM '+table+';', [], function(err, _items) {
30+
itemsFoundInTable = _.map(_items, function(row) { return [row.title]; });
31+
connection.end();
32+
});
33+
});
34+
35+
process.on('exit', function() {
36+
assert.deepEqual(items, itemsFoundInTable);
37+
});

0 commit comments

Comments
 (0)