Skip to content

Commit

Permalink
Merge pull request #33 from carpiediem/knex-upgrade
Browse files Browse the repository at this point in the history
Knex upgrade
  • Loading branch information
eashaw authored Jul 8, 2022
2 parents 96217b5 + e0efac0 commit 3008992
Show file tree
Hide file tree
Showing 40 changed files with 144 additions and 136 deletions.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ module.exports = function sqlBuilder(options) {
throw new Error('Missing Dialect!');
}

// Modify deprecated dialect values
if (options.dialect==='mariadb') {
options.dialect='mysql';
}
if (options.dialect==='oracle') {
options.dialect='oracledb';
}

// Build up a Knex instance to use in the query builder
var knexInstance = Knex({
dialect: options.dialect,
client: options.dialect,
useNullAsDefault: true
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],
"license": "MIT",
"dependencies": {
"knex": "0.12.7",
"knex": "0.21.1",
"@sailshq/lodash": "^3.10.2",
"waterline-utils": "^1.3.8"
},
Expand Down
8 changes: 4 additions & 4 deletions test/unit/generate/and.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select * from "users" where "firstName" = ? and "lastName" = ?',
sql: 'select * from `users` where `firstName` = ? and `lastName` = ?',
bindings: ['foo', 'bar']
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select * from "users" where "firstName" = :1 and "lastName" = :2',
bindings: ['foo', 'bar']
},
Expand Down Expand Up @@ -95,11 +95,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select * from "users" where ("firstName" = ? or "lastName" = ?) and ("qty" > ? or "price" < ?)',
sql: 'select * from `users` where (`firstName` = ? or `lastName` = ?) and (`qty` > ? or `price` < ?)',
bindings: ['John', 'Smith', '100', '10.01']
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select * from "users" where ("firstName" = :1 or "lastName" = :2) and ("qty" > :3 or "price" < :4)',
bindings: ['John', 'Smith', '100', '10.01']
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/avg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select avg("active") from "users"',
sql: 'select avg(`active`) from `users`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select avg("active") from "users"',
bindings: []
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select count(*) from "users"',
sql: 'select count(*) from `users`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select count(*) from "users"',
bindings: []
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/crossJoin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select "users"."id", "contacts"."phone" from "users" cross join "contacts" on "users"."id" = "contacts"."user_id"',
sql: 'select `users`.`id`, `contacts`.`phone` from `users` cross join `contacts` on `users`.`id` = `contacts`.`user_id`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select "users"."id", "contacts"."phone" from "users" cross join "contacts" on "users"."id" = "contacts"."user_id"',
bindings: []
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/delete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'delete from "accounts" where "activated" = ?',
sql: 'delete from `accounts` where `activated` = ?',
bindings: [false]
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'delete from "accounts" where "activated" = :1',
bindings: ['0']
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/distinct.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select distinct "firstName", "lastName" from "customers"',
sql: 'select distinct `firstName`, `lastName` from `customers`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select distinct "firstName", "lastName" from "customers"',
bindings: []
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/from.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select * from "books"',
sql: 'select * from `books`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select * from "books"',
bindings: []
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/fullOuterJoin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select "users"."id", "contacts"."phone" from "users" full outer join "contacts" on "users"."id" = "contacts"."user_id"',
sql: 'select `users`.`id`, `contacts`.`phone` from `users` full outer join `contacts` on `users`.`id` = `contacts`.`user_id`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select "users"."id", "contacts"."phone" from "users" full outer join "contacts" on "users"."id" = "contacts"."user_id"',
bindings: []
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/groupBy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select * from "users" group by "count"',
sql: 'select * from `users` group by `count`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select * from "users" group by "count"',
bindings: []
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/innerJoin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select "users"."id", "contacts"."phone" from "users" inner join "contacts" on "users"."id" = "contacts"."user_id"',
sql: 'select `users`.`id`, `contacts`.`phone` from `users` inner join `contacts` on `users`.`id` = `contacts`.`user_id`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select "users"."id", "contacts"."phone" from "users" inner join "contacts" on "users"."id" = "contacts"."user_id"',
bindings: []
},
Expand Down
12 changes: 6 additions & 6 deletions test/unit/generate/insert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'insert into "books" ("title") values (?)',
sql: 'insert into `books` (`title`) values (?)',
bindings: ['Slaughterhouse Five']
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'insert into "books" ("title") values (:1)',
bindings: ['Slaughterhouse Five']
},
Expand Down Expand Up @@ -62,11 +62,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'insert into "books" ("author", "title") values (?, ?)',
sql: 'insert into `books` (`author`, `title`) values (?, ?)',
bindings: ['Kurt Vonnegut', 'Slaughterhouse Five']
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'insert into "books" ("author", "title") values (:1, :2)',
bindings: ['Kurt Vonnegut', 'Slaughterhouse Five']
},
Expand Down Expand Up @@ -107,11 +107,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'insert into "books" ("author", "title") select ? as "author", ? as "title" union all select ? as "author", ? as "title"',
sql: 'insert into `books` (`author`, `title`) select ? as `author`, ? as `title` union all select ? as `author`, ? as `title`',
bindings: ['Kurt Vonnegut', 'Slaughterhouse Five', 'F. Scott Fitzgerald', 'The Great Gatsby']
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'begin execute immediate \'insert into "books" ("author", "title") values (:1, :2)\' using :1, :2; execute immediate \'insert into "books" ("author", "title") values (:1, :2)\' using :3, :4;end;',
bindings: ['Kurt Vonnegut', 'Slaughterhouse Five', 'F. Scott Fitzgerald', 'The Great Gatsby']
},
Expand Down
12 changes: 6 additions & 6 deletions test/unit/generate/join.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select "users"."id", "contacts"."phone" from "users" inner join "contacts" on "users"."id" = "contacts"."user_id"',
sql: 'select `users`.`id`, `contacts`.`phone` from `users` inner join `contacts` on `users`.`id` = `contacts`.`user_id`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select "users"."id", "contacts"."phone" from "users" inner join "contacts" on "users"."id" = "contacts"."user_id"',
bindings: []
},
Expand Down Expand Up @@ -82,11 +82,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select "users"."id", "contacts"."phone", "carriers"."name" from "users" inner join "contacts" on "users"."id" = "contacts"."user_id" inner join "carriers" on "users"."id" = "carriers"."user_id"',
sql: 'select `users`.`id`, `contacts`.`phone`, `carriers`.`name` from `users` inner join `contacts` on `users`.`id` = `contacts`.`user_id` inner join `carriers` on `users`.`id` = `carriers`.`user_id`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select "users"."id", "contacts"."phone", "carriers"."name" from "users" inner join "contacts" on "users"."id" = "contacts"."user_id" inner join "carriers" on "users"."id" = "carriers"."user_id"',
bindings: []
},
Expand Down Expand Up @@ -135,11 +135,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select * from "users" inner join "accounts" on "accounts"."id" = "users"."account_id" or "accounts"."owner_id" = "users"."id"',
sql: 'select * from `users` inner join `accounts` on `accounts`.`id` = `users`.`account_id` or `accounts`.`owner_id` = `users`.`id`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select * from "users" inner join "accounts" on "accounts"."id" = "users"."account_id" or "accounts"."owner_id" = "users"."id"',
bindings: []
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/leftJoin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select "users"."id", "contacts"."phone" from "users" left join "contacts" on "users"."id" = "contacts"."user_id"',
sql: 'select `users`.`id`, `contacts`.`phone` from `users` left join `contacts` on `users`.`id` = `contacts`.`user_id`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select "users"."id", "contacts"."phone" from "users" left join "contacts" on "users"."id" = "contacts"."user_id"',
bindings: []
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/leftOuterJoin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select "users"."id", "contacts"."phone" from "users" left outer join "contacts" on "users"."id" = "contacts"."user_id"',
sql: 'select `users`.`id`, `contacts`.`phone` from `users` left outer join `contacts` on `users`.`id` = `contacts`.`user_id`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select "users"."id", "contacts"."phone" from "users" left outer join "contacts" on "users"."id" = "contacts"."user_id"',
bindings: []
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/like.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select * from "users" where "name" like ? or "id" not in (?, ?, ?)',
sql: 'select * from `users` where `name` like ? or `id` not in (?, ?, ?)',
bindings: ['%Test%', '1', '2', '3']
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select * from "users" where "name" like :1 or "id" not in (:2, :3, :4)',
bindings: ['%Test%', '1', '2', '3']
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/limit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select "id" from "users" limit ?',
sql: 'select `id` from `users` limit ?',
bindings: ['10']
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select * from (select "id" from "users") where rownum <= :1',
bindings: ['10']
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/null.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select * from "users" where "updatedAt" is null',
sql: 'select * from `users` where `updatedAt` is null',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select * from "users" where "updatedAt" is null',
bindings: []
},
Expand Down
8 changes: 4 additions & 4 deletions test/unit/generate/or.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select * from "users" where "id" > ? or "name" = ?',
sql: 'select * from `users` where `id` > ? or `name` = ?',
bindings: ['10', 'Tester']
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select * from "users" where "id" > :1 or "name" = :2',
bindings: ['10', 'Tester']
},
Expand Down Expand Up @@ -80,11 +80,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select * from "users" where ("id" = ? or "id" > ?) or "name" = ?',
sql: 'select * from `users` where (`id` = ? or `id` > ?) or `name` = ?',
bindings: ['1', '10', 'Tester']
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select * from "users" where ("id" = :1 or "id" > :2) or "name" = :3',
bindings: ['1', '10', 'Tester']
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/orderBy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select * from "users" order by "name" desc, "age" asc',
sql: 'select * from `users` order by `name` desc, `age` asc',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select * from "users" order by "name" desc, "age" asc',
bindings: []
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/generate/outerJoin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe('Query Generation ::', function() {
},
{
dialect: 'sqlite3',
sql: 'select "users"."id", "contacts"."phone" from "users" outer join "contacts" on "users"."id" = "contacts"."user_id"',
sql: 'select `users`.`id`, `contacts`.`phone` from `users` outer join `contacts` on `users`.`id` = `contacts`.`user_id`',
bindings: []
},
{
dialect: 'oracle',
dialect: 'oracledb',
sql: 'select "users"."id", "contacts"."phone" from "users" outer join "contacts" on "users"."id" = "contacts"."user_id"',
bindings: []
},
Expand Down
Loading

0 comments on commit 3008992

Please sign in to comment.