where.not.in.test.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. var Test = require('../../support/test-runner');
  2. describe('Query Generation ::', function() {
  3. describe('WHERE NOT IN statements', function() {
  4. it('should generate a query', function(done) {
  5. Test({
  6. query: {
  7. select: ['name'],
  8. from: 'users',
  9. where: {
  10. and: [
  11. {
  12. id: {
  13. nin: [1, 2, 3]
  14. }
  15. }
  16. ]
  17. }
  18. },
  19. outcomes: [
  20. {
  21. dialect: 'postgresql',
  22. sql: 'select "name" from "users" where "id" not in ($1, $2, $3)',
  23. bindings: ['1', '2', '3']
  24. },
  25. {
  26. dialect: 'mysql',
  27. sql: 'select `name` from `users` where `id` not in (?, ?, ?)',
  28. bindings: ['1', '2', '3']
  29. },
  30. {
  31. dialect: 'sqlite3',
  32. sql: 'select "name" from "users" where "id" not in (?, ?, ?)',
  33. bindings: ['1', '2', '3']
  34. },
  35. {
  36. dialect: 'oracle',
  37. sql: 'select "name" from "users" where "id" not in (:1, :2, :3)',
  38. bindings: ['1', '2', '3']
  39. },
  40. {
  41. dialect: 'mariadb',
  42. sql: 'select `name` from `users` where `id` not in (?, ?, ?)',
  43. bindings: ['1', '2', '3']
  44. }
  45. ]
  46. }, done);
  47. });
  48. it('should generate a query when inside an OR statement', function(done) {
  49. Test({
  50. query: {
  51. select: ['name'],
  52. from: 'users',
  53. where: {
  54. or: [
  55. {
  56. id: {
  57. nin: [1, 2, 3]
  58. }
  59. },
  60. {
  61. id: {
  62. nin: [4, 5, 6]
  63. }
  64. }
  65. ]
  66. }
  67. },
  68. outcomes: [
  69. {
  70. dialect: 'postgresql',
  71. sql: 'select "name" from "users" where "id" not in ($1, $2, $3) or "id" not in ($4, $5, $6)',
  72. bindings: ['1', '2', '3', '4', '5', '6']
  73. },
  74. {
  75. dialect: 'mysql',
  76. sql: 'select `name` from `users` where `id` not in (?, ?, ?) or `id` not in (?, ?, ?)',
  77. bindings: ['1', '2', '3', '4', '5', '6']
  78. },
  79. {
  80. dialect: 'sqlite3',
  81. sql: 'select "name" from "users" where "id" not in (?, ?, ?) or "id" not in (?, ?, ?)',
  82. bindings: ['1', '2', '3', '4', '5', '6']
  83. },
  84. {
  85. dialect: 'oracle',
  86. sql: 'select "name" from "users" where "id" not in (:1, :2, :3) or "id" not in (:4, :5, :6)',
  87. bindings: ['1', '2', '3', '4', '5', '6']
  88. },
  89. {
  90. dialect: 'mariadb',
  91. sql: 'select `name` from `users` where `id` not in (?, ?, ?) or `id` not in (?, ?, ?)',
  92. bindings: ['1', '2', '3', '4', '5', '6']
  93. }
  94. ]
  95. }, done);
  96. });
  97. it('should generate a query when inside an OR statement with multiple criteria', function(done) {
  98. Test({
  99. query: {
  100. select: ['name'],
  101. from: 'users',
  102. where: {
  103. or: [
  104. {
  105. id: {
  106. nin: [1, 2, 3]
  107. },
  108. age: 21
  109. },
  110. {
  111. id: {
  112. nin: [4, 5, 6]
  113. }
  114. }
  115. ]
  116. }
  117. },
  118. outcomes: [
  119. {
  120. dialect: 'postgresql',
  121. sql: 'select "name" from "users" where ("id" not in ($1, $2, $3) and "age" = $4) or "id" not in ($5, $6, $7)',
  122. bindings: ['1', '2', '3', '21', '4', '5', '6']
  123. },
  124. {
  125. dialect: 'mysql',
  126. sql: 'select `name` from `users` where (`id` not in (?, ?, ?) and `age` = ?) or `id` not in (?, ?, ?)',
  127. bindings: ['1', '2', '3', '21', '4', '5', '6']
  128. },
  129. {
  130. dialect: 'sqlite3',
  131. sql: 'select "name" from "users" where ("id" not in (?, ?, ?) and "age" = ?) or "id" not in (?, ?, ?)',
  132. bindings: ['1', '2', '3', '21', '4', '5', '6']
  133. },
  134. {
  135. dialect: 'oracle',
  136. sql: 'select "name" from "users" where ("id" not in (:1, :2, :3) and "age" = :4) or "id" not in (:5, :6, :7)',
  137. bindings: ['1', '2', '3', '21', '4', '5', '6']
  138. },
  139. {
  140. dialect: 'mariadb',
  141. sql: 'select `name` from `users` where (`id` not in (?, ?, ?) and `age` = ?) or `id` not in (?, ?, ?)',
  142. bindings: ['1', '2', '3', '21', '4', '5', '6']
  143. }
  144. ]
  145. }, done);
  146. });
  147. });
  148. });