A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

12 years ago
  1. var common = require('../../common');
  2. var connection = common.createConnection();
  3. var assert = require('assert');
  4. common.useTestDb(connection);
  5. var table = 'nested_test';
  6. connection.query([
  7. 'CREATE TEMPORARY TABLE `' + table + '` (',
  8. '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
  9. '`title` varchar(255),',
  10. 'PRIMARY KEY (`id`)',
  11. ') ENGINE=InnoDB DEFAULT CHARSET=utf8'
  12. ].join('\n'));
  13. connection.query('INSERT INTO ' + table + ' SET ?', {title: 'test'});
  14. var options1 = {
  15. nestTables: true,
  16. sql: 'SELECT * FROM ' + table
  17. };
  18. var options2 = {
  19. nestTables: '_',
  20. sql: 'SELECT * FROM ' + table
  21. };
  22. var rows1, rows2;
  23. connection.query(options1, function(err, _rows) {
  24. if (err) throw err;
  25. rows1 = _rows;
  26. });
  27. connection.query(options2, function(err, _rows) {
  28. if (err) throw err;
  29. rows2 = _rows;
  30. });
  31. connection.end();
  32. process.on('exit', function() {
  33. assert.equal(rows1.length, 1);
  34. assert.equal(rows1[0].nested_test.id, 1);
  35. assert.equal(rows1[0].nested_test.title, 'test');
  36. assert.equal(rows2.length, 1);
  37. assert.equal(rows2[0].nested_test_id, 1);
  38. assert.equal(rows2[0].nested_test_title, 'test');
  39. });