where.not.test.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. var Test = require('../../support/test-runner');
  2. describe('Query Generation ::', function() {
  3. describe('WHERE NOT EQUAL statements', function() {
  4. it('should generate a query with a WHERE NOT EQUAL statement', function(done) {
  5. Test({
  6. query: {
  7. select: ['id'],
  8. from: 'users',
  9. where: {
  10. and: [
  11. {
  12. firstName: {
  13. '!=': 'Test'
  14. }
  15. },
  16. {
  17. lastName: {
  18. '!=': 'User'
  19. }
  20. }
  21. ]
  22. }
  23. },
  24. outcomes: [
  25. {
  26. dialect: 'postgresql',
  27. sql: 'select "id" from "users" where "firstName" != $1 and "lastName" != $2',
  28. bindings: ['Test', 'User']
  29. },
  30. {
  31. dialect: 'mysql',
  32. sql: 'select `id` from `users` where `firstName` != ? and `lastName` != ?',
  33. bindings: ['Test', 'User']
  34. },
  35. {
  36. dialect: 'sqlite3',
  37. sql: 'select "id" from "users" where "firstName" != ? and "lastName" != ?',
  38. bindings: ['Test', 'User']
  39. },
  40. {
  41. dialect: 'oracle',
  42. sql: 'select "id" from "users" where "firstName" != :1 and "lastName" != :2',
  43. bindings: ['Test', 'User']
  44. },
  45. {
  46. dialect: 'mariadb',
  47. sql: 'select `id` from `users` where `firstName` != ? and `lastName` != ?',
  48. bindings: ['Test', 'User']
  49. }
  50. ]
  51. }, done);
  52. });
  53. it('should generate a query when nested WHERE NOT statements are used', function(done) {
  54. Test({
  55. query: {
  56. select: '*',
  57. from: 'users',
  58. where: {
  59. or: [
  60. {
  61. or: [
  62. {
  63. id: {
  64. '!=': 1
  65. }
  66. },
  67. {
  68. id: {
  69. '<': 10
  70. }
  71. }
  72. ]
  73. },
  74. {
  75. name: {
  76. '!=': 'Tester'
  77. }
  78. }
  79. ]
  80. }
  81. },
  82. outcomes: [
  83. {
  84. dialect: 'postgresql',
  85. sql: 'select * from "users" where ("id" != $1 or "id" < $2) or "name" != $3',
  86. bindings: ['1', '10', 'Tester']
  87. },
  88. {
  89. dialect: 'mysql',
  90. sql: 'select * from `users` where (`id` != ? or `id` < ?) or `name` != ?',
  91. bindings: ['1', '10', 'Tester']
  92. },
  93. {
  94. dialect: 'sqlite3',
  95. sql: 'select * from "users" where ("id" != ? or "id" < ?) or "name" != ?',
  96. bindings: ['1', '10', 'Tester']
  97. },
  98. {
  99. dialect: 'oracle',
  100. sql: 'select * from "users" where ("id" != :1 or "id" < :2) or "name" != :3',
  101. bindings: ['1', '10', 'Tester']
  102. },
  103. {
  104. dialect: 'mariadb',
  105. sql: 'select * from `users` where (`id` != ? or `id` < ?) or `name` != ?',
  106. bindings: ['1', '10', 'Tester']
  107. }
  108. ]
  109. }, done);
  110. });
  111. it('should generate a query when multiple operators are used', function(done) {
  112. Test({
  113. query: {
  114. select: ['*'],
  115. from: 'users',
  116. where: {
  117. or: [
  118. { name: 'John' },
  119. {
  120. votes: { '>': 100 },
  121. title: {
  122. '!=': 'Admin'
  123. }
  124. }
  125. ]
  126. }
  127. },
  128. outcomes: [
  129. {
  130. dialect: 'postgresql',
  131. sql: 'select * from "users" where "name" = $1 or ("votes" > $2 and "title" != $3)',
  132. bindings: ['John', '100', 'Admin']
  133. },
  134. {
  135. dialect: 'mysql',
  136. sql: 'select * from `users` where `name` = ? or (`votes` > ? and `title` != ?)',
  137. bindings: ['John', '100', 'Admin']
  138. },
  139. {
  140. dialect: 'sqlite3',
  141. sql: 'select * from "users" where "name" = ? or ("votes" > ? and "title" != ?)',
  142. bindings: ['John', '100', 'Admin']
  143. },
  144. {
  145. dialect: 'oracle',
  146. sql: 'select * from "users" where "name" = :1 or ("votes" > :2 and "title" != :3)',
  147. bindings: ['John', '100', 'Admin']
  148. },
  149. {
  150. dialect: 'mariadb',
  151. sql: 'select * from `users` where `name` = ? or (`votes` > ? and `title` != ?)',
  152. bindings: ['John', '100', 'Admin']
  153. }
  154. ]
  155. }, done);
  156. });
  157. it('should generate a query when an AND array is used', function(done) {
  158. Test({
  159. query: {
  160. select: ['*'],
  161. from: 'users',
  162. where: {
  163. and: [
  164. {
  165. name: 'John'
  166. },
  167. {
  168. title: {
  169. '!=': 'Admin'
  170. }
  171. }
  172. ]
  173. }
  174. },
  175. outcomes: [
  176. {
  177. dialect: 'postgresql',
  178. sql: 'select * from "users" where "name" = $1 and "title" != $2',
  179. bindings: ['John', 'Admin']
  180. },
  181. {
  182. dialect: 'mysql',
  183. sql: 'select * from `users` where `name` = ? and `title` != ?',
  184. bindings: ['John', 'Admin']
  185. },
  186. {
  187. dialect: 'sqlite3',
  188. sql: 'select * from "users" where "name" = ? and "title" != ?',
  189. bindings: ['John', 'Admin']
  190. },
  191. {
  192. dialect: 'oracle',
  193. sql: 'select * from "users" where "name" = :1 and "title" != :2',
  194. bindings: ['John', 'Admin']
  195. },
  196. {
  197. dialect: 'mariadb',
  198. sql: 'select * from `users` where `name` = ? and `title` != ?',
  199. bindings: ['John', 'Admin']
  200. }
  201. ]
  202. }, done);
  203. });
  204. });
  205. });