Skip to content

Commit

Permalink
Changed the JoinClause's interface for on, andOn and orOn to ac…
Browse files Browse the repository at this point in the history
…cept a callback that takes another JoinClause, instead of QueryCallback. This was invalid and prevented deeper nesting join on statements. (DefinitelyTyped#29252)
  • Loading branch information
Gregroam authored and weswigham committed Oct 4, 2018
1 parent 2debc8b commit 9d4276a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
12 changes: 8 additions & 4 deletions types/knex/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ declare namespace Knex {
interface Distinct extends ColumnNameQueryBuilder {
}

interface JoinCallback {
(this: JoinClause, join: JoinClause): void;
}

interface Join {
(raw: Raw): QueryBuilder;
(tableName: TableName | QueryCallback, clause: (this: JoinClause, join: JoinClause) => void): QueryBuilder;
(tableName: TableName | QueryCallback, clause: JoinCallback): QueryBuilder;
(tableName: TableName | QueryCallback, columns: { [key: string]: string | number | Raw }): QueryBuilder;
(tableName: TableName | QueryCallback, raw: Raw): QueryBuilder;
(tableName: TableName | QueryCallback, column1: string, column2: string): QueryBuilder;
Expand All @@ -200,19 +204,19 @@ declare namespace Knex {

interface JoinClause {
on(raw: Raw): JoinClause;
on(callback: QueryCallback): JoinClause;
on(callback: JoinCallback): JoinClause;
on(columns: { [key: string]: string | Raw }): JoinClause;
on(column1: string, column2: string): JoinClause;
on(column1: string, raw: Raw): JoinClause;
on(column1: string, operator: string, column2: string | Raw): JoinClause;
andOn(raw: Raw): JoinClause;
andOn(callback: QueryCallback): JoinClause;
andOn(callback: JoinCallback): JoinClause;
andOn(columns: { [key: string]: string | Raw }): JoinClause;
andOn(column1: string, column2: string): JoinClause;
andOn(column1: string, raw: Raw): JoinClause;
andOn(column1: string, operator: string, column2: string | Raw): JoinClause;
orOn(raw: Raw): JoinClause;
orOn(callback: QueryCallback): JoinClause;
orOn(callback: JoinCallback): JoinClause;
orOn(columns: { [key: string]: string | Raw }): JoinClause;
orOn(column1: string, column2: string): JoinClause;
orOn(column1: string, raw: Raw): JoinClause;
Expand Down
13 changes: 10 additions & 3 deletions types/knex/knex-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,13 @@ knex.select('*').from('users').leftJoin('accounts', (join: Knex.JoinClause) => {
join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
});

knex.select('*').from('users').leftJoin('accounts', (join) => {
join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
.andOn((join2) => {
join2.on('col1', 'col2').orOn('col3', 'col4');
});
});

knex.select('*').from('users').leftOuterJoin('accounts', 'users.id', 'accounts.user_id');

knex.select('*').from('users').leftOuterJoin('accounts', function() {
Expand Down Expand Up @@ -1035,13 +1042,13 @@ knex('users')
.select('*')
.join('contacts', function(builder) {
this.on(function(builder) {
let self: Knex.QueryBuilder = this;
let self: Knex.JoinClause = this;
self = builder;
}).andOn(function(builder) {
let self: Knex.QueryBuilder = this;
let self: Knex.JoinClause = this;
self = builder;
}).orOn(function(builder) {
let self: Knex.QueryBuilder = this;
let self: Knex.JoinClause = this;
self = builder;
}).onExists(function(builder) {
let self: Knex.QueryBuilder = this;
Expand Down

0 comments on commit 9d4276a

Please sign in to comment.