waterline-sql-builder
Version:
Generate SQL (stage 5 query) from a Waterline statement (stage 4 query).
114 lines (110 loc) • 3.22 kB
JavaScript
var Test = require('../../support/test-runner');
describe('Query Generation ::', function() {
describe('SELECT statements', function() {
it('should generate a select * query', function(done) {
Test({
query: {
select: ['*'],
from: 'books'
},
outcomes: [
{
dialect: 'postgresql',
sql: 'select * from "books"',
bindings: []
},
{
dialect: 'mysql',
sql: 'select * from `books`',
bindings: []
},
{
dialect: 'sqlite3',
sql: 'select * from `books`',
bindings: []
},
{
dialect: 'oracledb',
sql: 'select * from "books"',
bindings: []
},
{
dialect: 'mariadb',
sql: 'select * from `books`',
bindings: []
}
]
}, done);
});
it('should generate a select query using defined columns', function(done) {
Test({
query: {
select: ['title', 'author', 'year'],
from: 'books'
},
outcomes: [
{
dialect: 'postgresql',
sql: 'select "title", "author", "year" from "books"',
bindings: []
},
{
dialect: 'mysql',
sql: 'select `title`, `author`, `year` from `books`',
bindings: []
},
{
dialect: 'sqlite3',
sql: 'select `title`, `author`, `year` from `books`',
bindings: []
},
{
dialect: 'oracledb',
sql: 'select "title", "author", "year" from "books"',
bindings: []
},
{
dialect: 'mariadb',
sql: 'select `title`, `author`, `year` from `books`',
bindings: []
}
]
}, done);
});
it('should generate a select query using aliased columns', function(done) {
Test({
query: {
select: ['title as book_title', 'author as book_author', 'year as book_year'],
from: 'books'
},
outcomes: [
{
dialect: 'postgresql',
sql: 'select "title" as "book_title", "author" as "book_author", "year" as "book_year" from "books"',
bindings: []
},
{
dialect: 'mysql',
sql: 'select `title` as `book_title`, `author` as `book_author`, `year` as `book_year` from `books`',
bindings: []
},
{
dialect: 'sqlite3',
sql: 'select `title` as `book_title`, `author` as `book_author`, `year` as `book_year` from `books`',
bindings: []
},
{
dialect: 'oracledb',
sql: 'select "title" "book_title", "author" "book_author", "year" "book_year" from "books"',
bindings: []
},
{
dialect: 'mariadb',
sql: 'select `title` as `book_title`, `author` as `book_author`, `year` as `book_year` from `books`',
bindings: []
}
]
}, done);
});
});
});