where.in.test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. var Test = require('../../support/test-runner');
  2. describe('Query Generation ::', function() {
  3. describe('WHERE 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. in: [1, 2, 3]
  14. }
  15. }
  16. ]
  17. }
  18. },
  19. outcomes: [
  20. {
  21. dialect: 'postgresql',
  22. sql: 'select "name" from "users" where "id" in ($1, $2, $3)',
  23. bindings: ['1', '2', '3']
  24. },
  25. {
  26. dialect: 'mysql',
  27. sql: 'select `name` from `users` where `id` in (?, ?, ?)',
  28. bindings: ['1', '2', '3']
  29. },
  30. {
  31. dialect: 'sqlite3',
  32. sql: 'select "name" from "users" where "id" in (?, ?, ?)',
  33. bindings: ['1', '2', '3']
  34. },
  35. {
  36. dialect: 'oracle',
  37. sql: 'select "name" from "users" where "id" in (:1, :2, :3)',
  38. bindings: ['1', '2', '3']
  39. },
  40. {
  41. dialect: 'mariadb',
  42. sql: 'select `name` from `users` where `id` 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. in: [1, 2, 3]
  58. }
  59. },
  60. {
  61. id: {
  62. in: [4, 5, 6]
  63. }
  64. }
  65. ]
  66. }
  67. },
  68. outcomes: [
  69. {
  70. dialect: 'postgresql',
  71. sql: 'select "name" from "users" where "id" in ($1, $2, $3) or "id" 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` in (?, ?, ?) or `id` in (?, ?, ?)',
  77. bindings: ['1', '2', '3', '4', '5', '6']
  78. },
  79. {
  80. dialect: 'sqlite3',
  81. sql: 'select "name" from "users" where "id" in (?, ?, ?) or "id" in (?, ?, ?)',
  82. bindings: ['1', '2', '3', '4', '5', '6']
  83. },
  84. {
  85. dialect: 'oracle',
  86. sql: 'select "name" from "users" where "id" in (:1, :2, :3) or "id" 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` in (?, ?, ?) or `id` in (?, ?, ?)',
  92. bindings: ['1', '2', '3', '4', '5', '6']
  93. }
  94. ]
  95. }, done);
  96. });
  97. });
  98. });