test-bulk-insert.js 973 B

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