subquery.table.test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var Test = require('../../support/test-runner');
  2. describe('Query Generation ::', function() {
  3. describe('Subqueries', function() {
  4. describe('used as table sub query', function() {
  5. it('should generate a valid query when used as a value in a FROM with an AS alias', function(done) {
  6. Test({
  7. query: {
  8. select: ['name', 'age'],
  9. from: {
  10. select: ['age'],
  11. from: 'users',
  12. where: {
  13. and: [
  14. {
  15. age: 21
  16. }
  17. ]
  18. },
  19. as: 'userage'
  20. }
  21. },
  22. outcomes: [
  23. {
  24. dialect: 'postgresql',
  25. sql: 'select "name", "age" from (select "age" from "users" where "age" = $1) as "userage"',
  26. bindings: [21]
  27. },
  28. {
  29. dialect: 'mysql',
  30. sql: 'select `name`, `age` from (select `age` from `users` where `age` = ?) as `userage`',
  31. bindings: [21]
  32. },
  33. {
  34. dialect: 'sqlite3',
  35. sql: 'select "name", "age" from (select "age" from "users" where "age" = ?) as "userage"',
  36. bindings: [21]
  37. },
  38. {
  39. dialect: 'oracle',
  40. sql: 'select "name", "age" from (select "age" from "users" where "age" = :1) "userage"',
  41. bindings: [21]
  42. },
  43. {
  44. dialect: 'mariadb',
  45. sql: 'select `name`, `age` from (select `age` from `users` where `age` = ?) as `userage`',
  46. bindings: [21]
  47. }
  48. ]
  49. }, done);
  50. });
  51. });
  52. });
  53. });