mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
Knex.join: table can be a subquery (#23177)
* Allow tableName in joins to be QueryCallback * Add tests for join with callback as table
This commit is contained in:
12
types/knex/index.d.ts
vendored
12
types/knex/index.d.ts
vendored
@@ -183,12 +183,12 @@ declare namespace Knex {
|
||||
|
||||
interface Join {
|
||||
(raw: Raw): QueryBuilder;
|
||||
(tableName: TableName, clause: (this: JoinClause, join: JoinClause) => void): QueryBuilder;
|
||||
(tableName: TableName, columns: { [key: string]: string | number | Raw }): QueryBuilder;
|
||||
(tableName: TableName, raw: Raw): QueryBuilder;
|
||||
(tableName: TableName, column1: string, column2: string): QueryBuilder;
|
||||
(tableName: TableName, column1: string, raw: Raw): QueryBuilder;
|
||||
(tableName: TableName, column1: string, operator: string, column2: string): QueryBuilder;
|
||||
(tableName: TableName | QueryCallback, clause: (this: JoinClause, join: JoinClause) => void): 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;
|
||||
(tableName: TableName | QueryCallback, column1: string, raw: Raw): QueryBuilder;
|
||||
(tableName: TableName | QueryCallback, column1: string, operator: string, column2: string): QueryBuilder;
|
||||
}
|
||||
|
||||
interface JoinClause {
|
||||
|
||||
@@ -459,6 +459,44 @@ knex.select('*').from('accounts').joinRaw('natural full join table1').where('id'
|
||||
|
||||
knex.select('*').from('accounts').join(knex.raw('natural full join table1')).where('id', 1);
|
||||
|
||||
knex.select('*').from('accounts')
|
||||
.join(function() {
|
||||
this.select('*').from('accounts').as('special_accounts');
|
||||
}, 'special_accounts.a', '=', 'accounts.b');
|
||||
knex.select('*').from('accounts')
|
||||
.leftJoin(function() {
|
||||
this.select('*').from('accounts').as('special_accounts');
|
||||
}, 'special_accounts.a', '=', 'accounts.b');
|
||||
knex.select('*').from('accounts')
|
||||
.leftOuterJoin(function() {
|
||||
this.select('*').from('accounts').as('special_accounts');
|
||||
}, 'special_accounts.a', '=', 'accounts.b');
|
||||
knex.select('*').from('accounts')
|
||||
.rightJoin(function() {
|
||||
this.select('*').from('accounts').as('special_accounts');
|
||||
}, 'special_accounts.a', '=', 'accounts.b');
|
||||
knex.select('*').from('accounts')
|
||||
.rightOuterJoin(function() {
|
||||
this.select('*').from('accounts').as('special_accounts');
|
||||
}, 'special_accounts.a', '=', 'accounts.b');
|
||||
knex.select('*').from('accounts')
|
||||
.innerJoin(function() {
|
||||
this.select('*').from('accounts').as('special_accounts');
|
||||
}, 'special_accounts.a', '=', 'accounts.b');
|
||||
knex.select('*').from('accounts')
|
||||
.crossJoin(function() {
|
||||
this.select('*').from('accounts').as('special_accounts');
|
||||
}, 'special_accounts.a', '=', 'accounts.b');
|
||||
knex.select('*').from('accounts')
|
||||
.fullOuterJoin(function() {
|
||||
this.select('*').from('accounts').as('special_accounts');
|
||||
}, 'special_accounts.a', '=', 'accounts.b');
|
||||
knex.select('*').from('accounts')
|
||||
.outerJoin(function() {
|
||||
this.select('*').from('accounts').as('special_accounts');
|
||||
}, 'special_accounts.a', '=', 'accounts.b');
|
||||
|
||||
|
||||
knex('customers')
|
||||
.distinct('first_name', 'last_name')
|
||||
.select();
|
||||
|
||||
Reference in New Issue
Block a user