123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- var Test = require('../../support/test-runner');
- describe('Query Generation ::', function() {
- describe('Simple WHERE statements', function() {
- it('should generate a query with a simple WHERE statement', function(done) {
- Test({
- query: {
- select: ['id'],
- where: {
- and: [
- {
- firstName: 'Test'
- },
- {
- lastName: 'User'
- }
- ]
- },
- from: 'users'
- },
- outcomes: [
- {
- dialect: 'postgresql',
- sql: 'select "id" from "users" where "firstName" = $1 and "lastName" = $2',
- bindings: ['Test', 'User']
- },
- {
- dialect: 'mysql',
- sql: 'select `id` from `users` where `firstName` = ? and `lastName` = ?',
- bindings: ['Test', 'User']
- },
- {
- dialect: 'sqlite3',
- sql: 'select "id" from "users" where "firstName" = ? and "lastName" = ?',
- bindings: ['Test', 'User']
- },
- {
- dialect: 'oracle',
- sql: 'select "id" from "users" where "firstName" = :1 and "lastName" = :2',
- bindings: ['Test', 'User']
- },
- {
- dialect: 'mariadb',
- sql: 'select `id` from `users` where `firstName` = ? and `lastName` = ?',
- bindings: ['Test', 'User']
- }
- ]
- }, done);
- });
- it('should generate a query when operators are used', function(done) {
- Test({
- query: {
- select: ['*'],
- where: {
- and: [
- {
- votes: {
- '>': 100
- }
- }
- ]
- },
- from: 'users'
- },
- outcomes: [
- {
- dialect: 'postgresql',
- sql: 'select * from "users" where "votes" > $1',
- bindings: ['100']
- },
- {
- dialect: 'mysql',
- sql: 'select * from `users` where `votes` > ?',
- bindings: ['100']
- },
- {
- dialect: 'sqlite3',
- sql: 'select * from "users" where "votes" > ?',
- bindings: ['100']
- },
- {
- dialect: 'oracle',
- sql: 'select * from "users" where "votes" > :1',
- bindings: ['100']
- },
- {
- dialect: 'mariadb',
- sql: 'select * from `users` where `votes` > ?',
- bindings: ['100']
- }
- ]
- }, done);
- });
- it('should generate a query when multiple operators are used', function(done) {
- Test({
- query: {
- select: ['*'],
- where: {
- and: [
- {
- votes: {
- '>': 100
- }
- },
- {
- votes: {
- '<': 200
- }
- }
- ]
- },
- from: 'users'
- },
- outcomes: [
- {
- dialect: 'postgresql',
- sql: 'select * from "users" where "votes" > $1 and "votes" < $2',
- bindings: ['100', '200']
- },
- {
- dialect: 'mysql',
- sql: 'select * from `users` where `votes` > ? and `votes` < ?',
- bindings: ['100', '200']
- },
- {
- dialect: 'sqlite3',
- sql: 'select * from "users" where "votes" > ? and "votes" < ?',
- bindings: ['100', '200']
- },
- {
- dialect: 'oracle',
- sql: 'select * from "users" where "votes" > :1 and "votes" < :2',
- bindings: ['100', '200']
- },
- {
- dialect: 'mariadb',
- sql: 'select * from `users` where `votes` > ? and `votes` < ?',
- bindings: ['100', '200']
- }
- ]
- }, done);
- });
- it('should generate a query when multiple columns and operators are used', function(done) {
- Test({
- query: {
- select: ['*'],
- where: {
- and: [
- {
- votes: {
- '>': 100
- }
- },
- {
- age: {
- '<': 50
- }
- }
- ]
- },
- from: 'users'
- },
- outcomes: [
- {
- dialect: 'postgresql',
- sql: 'select * from "users" where "votes" > $1 and "age" < $2',
- bindings: ['100', '50']
- },
- {
- dialect: 'mysql',
- sql: 'select * from `users` where `votes` > ? and `age` < ?',
- bindings: ['100', '50']
- },
- {
- dialect: 'sqlite3',
- sql: 'select * from "users" where "votes" > ? and "age" < ?',
- bindings: ['100', '50']
- },
- {
- dialect: 'oracle',
- sql: 'select * from "users" where "votes" > :1 and "age" < :2',
- bindings: ['100', '50']
- },
- {
- dialect: 'mariadb',
- sql: 'select * from `users` where `votes` > ? and `age` < ?',
- bindings: ['100', '50']
- }
- ]
- }, done);
- });
- });
- });
|