or.test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. var Test = require('../../support/test-runner');
  2. describe('Query Generation ::', function() {
  3. describe('Grouping statements with OR', function() {
  4. it('should generate a query when an OR statement is present', function(done) {
  5. Test({
  6. query: {
  7. select: ['*'],
  8. where: {
  9. or: [
  10. {
  11. id: { '>': 10 }
  12. },
  13. {
  14. name: 'Tester'
  15. }
  16. ]
  17. },
  18. from: 'users'
  19. },
  20. outcomes: [
  21. {
  22. dialect: 'postgresql',
  23. sql: 'select * from "users" where "id" > $1 or "name" = $2',
  24. bindings: ['10', 'Tester']
  25. },
  26. {
  27. dialect: 'mysql',
  28. sql: 'select * from `users` where `id` > ? or `name` = ?',
  29. bindings: ['10', 'Tester']
  30. },
  31. {
  32. dialect: 'sqlite3',
  33. sql: 'select * from "users" where "id" > ? or "name" = ?',
  34. bindings: ['10', 'Tester']
  35. },
  36. {
  37. dialect: 'oracle',
  38. sql: 'select * from "users" where "id" > :1 or "name" = :2',
  39. bindings: ['10', 'Tester']
  40. },
  41. {
  42. dialect: 'mariadb',
  43. sql: 'select * from `users` where `id` > ? or `name` = ?',
  44. bindings: ['10', 'Tester']
  45. }
  46. ]
  47. }, done);
  48. });
  49. it('should generate a query when a nested OR statement is used', function(done) {
  50. Test({
  51. query: {
  52. select: ['*'],
  53. where: {
  54. or: [
  55. {
  56. or: [
  57. { id: 1 },
  58. { id: { '>': 10 } }
  59. ]
  60. },
  61. {
  62. name: 'Tester'
  63. }
  64. ]
  65. },
  66. from: 'users'
  67. },
  68. outcomes: [
  69. {
  70. dialect: 'postgresql',
  71. sql: 'select * from "users" where ("id" = $1 or "id" > $2) or "name" = $3',
  72. bindings: ['1', '10', 'Tester']
  73. },
  74. {
  75. dialect: 'mysql',
  76. sql: 'select * from `users` where (`id` = ? or `id` > ?) or `name` = ?',
  77. bindings: ['1', '10', 'Tester']
  78. },
  79. {
  80. dialect: 'sqlite3',
  81. sql: 'select * from "users" where ("id" = ? or "id" > ?) or "name" = ?',
  82. bindings: ['1', '10', 'Tester']
  83. },
  84. {
  85. dialect: 'oracle',
  86. sql: 'select * from "users" where ("id" = :1 or "id" > :2) or "name" = :3',
  87. bindings: ['1', '10', 'Tester']
  88. },
  89. {
  90. dialect: 'mariadb',
  91. sql: 'select * from `users` where (`id` = ? or `id` > ?) or `name` = ?',
  92. bindings: ['1', '10', 'Tester']
  93. }
  94. ]
  95. }, done);
  96. });
  97. });
  98. });