select.test.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. var Test = require('../../support/test-runner');
  2. describe('Query Generation ::', function() {
  3. describe('SELECT statements', function() {
  4. it('should generate a select * query', function(done) {
  5. Test({
  6. query: {
  7. select: ['*'],
  8. from: 'books'
  9. },
  10. outcomes: [
  11. {
  12. dialect: 'postgresql',
  13. sql: 'select * from "books"',
  14. bindings: []
  15. },
  16. {
  17. dialect: 'mysql',
  18. sql: 'select * from `books`',
  19. bindings: []
  20. },
  21. {
  22. dialect: 'sqlite3',
  23. sql: 'select * from "books"',
  24. bindings: []
  25. },
  26. {
  27. dialect: 'oracle',
  28. sql: 'select * from "books"',
  29. bindings: []
  30. },
  31. {
  32. dialect: 'mariadb',
  33. sql: 'select * from `books`',
  34. bindings: []
  35. }
  36. ]
  37. }, done);
  38. });
  39. it('should generate a select query using defined columns', function(done) {
  40. Test({
  41. query: {
  42. select: ['title', 'author', 'year'],
  43. from: 'books'
  44. },
  45. outcomes: [
  46. {
  47. dialect: 'postgresql',
  48. sql: 'select "title", "author", "year" from "books"',
  49. bindings: []
  50. },
  51. {
  52. dialect: 'mysql',
  53. sql: 'select `title`, `author`, `year` from `books`',
  54. bindings: []
  55. },
  56. {
  57. dialect: 'sqlite3',
  58. sql: 'select "title", "author", "year" from "books"',
  59. bindings: []
  60. },
  61. {
  62. dialect: 'oracle',
  63. sql: 'select "title", "author", "year" from "books"',
  64. bindings: []
  65. },
  66. {
  67. dialect: 'mariadb',
  68. sql: 'select `title`, `author`, `year` from `books`',
  69. bindings: []
  70. }
  71. ]
  72. }, done);
  73. });
  74. it('should generate a select query using aliased columns', function(done) {
  75. Test({
  76. query: {
  77. select: ['title as book_title', 'author as book_author', 'year as book_year'],
  78. from: 'books'
  79. },
  80. outcomes: [
  81. {
  82. dialect: 'postgresql',
  83. sql: 'select "title" as "book_title", "author" as "book_author", "year" as "book_year" from "books"',
  84. bindings: []
  85. },
  86. {
  87. dialect: 'mysql',
  88. sql: 'select `title` as `book_title`, `author` as `book_author`, `year` as `book_year` from `books`',
  89. bindings: []
  90. },
  91. {
  92. dialect: 'sqlite3',
  93. sql: 'select "title" as "book_title", "author" as "book_author", "year" as "book_year" from "books"',
  94. bindings: []
  95. },
  96. {
  97. dialect: 'oracle',
  98. sql: 'select "title" "book_title", "author" "book_author", "year" "book_year" from "books"',
  99. bindings: []
  100. },
  101. {
  102. dialect: 'mariadb',
  103. sql: 'select `title` as `book_title`, `author` as `book_author`, `year` as `book_year` from `books`',
  104. bindings: []
  105. }
  106. ]
  107. }, done);
  108. });
  109. });
  110. });