analyzer.where.not.in.test.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. var Analyzer = require('../../../index').query.analyzer;
  2. var tokenize = require('../../support/tokenize');
  3. var assert = require('assert');
  4. describe('Analyzer ::', function() {
  5. describe('WHERE NOT IN statements', function() {
  6. it('should generate a valid group', function() {
  7. var tokens = tokenize({
  8. select: ['name'],
  9. from: 'users',
  10. where: {
  11. and: [
  12. {
  13. id: {
  14. nin: [1, 2, 3]
  15. }
  16. }
  17. ]
  18. }
  19. });
  20. var result = Analyzer(tokens);
  21. assert.deepEqual(result, [
  22. [
  23. { type: 'IDENTIFIER', value: 'SELECT' },
  24. { type: 'VALUE', value: 'name' }
  25. ],
  26. [
  27. { type: 'IDENTIFIER', value: 'FROM' },
  28. { type: 'VALUE', value: 'users' }
  29. ],
  30. [
  31. { type: 'IDENTIFIER', value: 'WHERE' },
  32. { type: 'CONDITION', value: 'AND' },
  33. [
  34. { type: 'KEY', value: 'id' },
  35. { type: 'CONDITION', value: 'NOTIN' },
  36. { type: 'VALUE', value: [1, 2, 3] }
  37. ]
  38. ]
  39. ]);
  40. });
  41. it('should generate a valid group when in an OR statement', function() {
  42. var tokens = tokenize({
  43. select: ['name'],
  44. from: 'users',
  45. where: {
  46. or: [
  47. {
  48. id: {
  49. nin: [1, 2, 3]
  50. }
  51. },
  52. {
  53. id: {
  54. nin: [4, 5, 6]
  55. }
  56. }
  57. ]
  58. }
  59. });
  60. var result = Analyzer(tokens);
  61. assert.deepEqual(result, [
  62. [
  63. { type: 'IDENTIFIER', value: 'SELECT' },
  64. { type: 'VALUE', value: 'name' }
  65. ],
  66. [
  67. { type: 'IDENTIFIER', value: 'FROM' },
  68. { type: 'VALUE', value: 'users' }
  69. ],
  70. [
  71. { type: 'IDENTIFIER', value: 'WHERE' },
  72. [
  73. { type: 'KEY', value: 'id' },
  74. { type: 'CONDITION', value: 'NOTIN' },
  75. { type: 'VALUE', value: [1, 2, 3] }
  76. ],
  77. [
  78. { type: 'KEY', value: 'id' },
  79. { type: 'CONDITION', value: 'NOTIN' },
  80. { type: 'VALUE', value: [4, 5, 6] }
  81. ]
  82. ]
  83. ]);
  84. });
  85. });
  86. });