123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- var Analyzer = require('../../../index').query.analyzer;
- var tokenize = require('../../support/tokenize');
- var assert = require('assert');
- describe('Analyzer ::', function() {
- describe('Grouping statements with OR', function() {
- it('should generate a valid group', function() {
- var tokens = tokenize({
- select: ['*'],
- where: {
- or: [
- {
- id: { '>': 10 }
- },
- {
- name: 'Tester'
- }
- ]
- },
- from: 'users'
- });
- var result = Analyzer(tokens);
- assert.deepEqual(result, [
- [
- { type: 'IDENTIFIER', value: 'SELECT' },
- { type: 'VALUE', value: '*' }
- ],
- [
- { type: 'IDENTIFIER', value: 'WHERE' },
- [
- { type: 'KEY', value: 'id' },
- { type: 'OPERATOR', value: '>' },
- { type: 'VALUE', value: 10 }
- ],
- [
- { type: 'KEY', value: 'name' },
- { type: 'VALUE', value: 'Tester' }
- ]
- ],
- [
- { type: 'IDENTIFIER', value: 'FROM' },
- { type: 'VALUE', value: 'users' }
- ]
- ]);
- });
- it('should generate a valid group when using nested OR conditions', function() {
- var tokens = tokenize({
- select: ['*'],
- where: {
- or: [
- {
- or: [
- { id: 1 },
- { id: { '>': 10 } }
- ]
- },
- {
- name: 'Tester'
- }
- ]
- },
- from: 'users'
- });
- var result = Analyzer(tokens);
- assert.deepEqual(result, [
- [
- { type: 'IDENTIFIER', value: 'SELECT' },
- { type: 'VALUE', value: '*' }
- ],
- [
- { type: 'IDENTIFIER', value: 'WHERE' },
- [
- [
- { type: 'KEY', value: 'id' },
- { type: 'VALUE', value: 1 }
- ],
- [
- { type: 'KEY', value: 'id' },
- { type: 'OPERATOR', value: '>' },
- { type: 'VALUE', value: 10 }
- ]
- ],
- [
- { type: 'KEY', value: 'name' },
- { type: 'VALUE', value: 'Tester' }
- ]
- ],
- [
- { type: 'IDENTIFIER', value: 'FROM' },
- { type: 'VALUE', value: 'users' }
- ]
- ]);
- });
- });
- });
|