mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 14:27:04 +00:00
[@types/knex] Fixed search path incomplete typing (#22698)
* [@types/knex] Added multiple searchPath support for 0.14.1 * [@types/knex] Fixed whitespace lint * [@types/knex] Fixed typedef-whitespace lint * [@types/knex] Fixed semicolon lint
This commit is contained in:
committed by
Mohamed Hegazy
parent
95f835b77e
commit
3f0cbf20fc
Vendored
+5
-4
@@ -1,9 +1,10 @@
|
||||
// Type definitions for Knex.js
|
||||
// Type definitions for Knex.js 0.14
|
||||
// Project: https://github.com/tgriesser/knex
|
||||
// Definitions by: Qubo <https://github.com/tkQubo>
|
||||
// Baronfel <https://github.com/baronfel>
|
||||
// Pablo Rodríguez <https://github.com/MeLlamoPablo>
|
||||
// Matt R. Wilson <https://github.com/mastermatt>
|
||||
// Satana Charuwichitratana <https://github.com/micksatana>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
@@ -28,7 +29,7 @@ interface Knex extends Knex.QueryInterface {
|
||||
transaction<T>(transactionScope: (trx: Knex.Transaction) => Promise<T> | Bluebird<T> | void): Bluebird<T>;
|
||||
destroy(callback: Function): void;
|
||||
destroy(): Bluebird<void>;
|
||||
batchInsert(tableName : TableName, data: any[], chunkSize : number) : Knex.QueryBuilder;
|
||||
batchInsert(tableName: TableName, data: any[], chunkSize: number): Knex.QueryBuilder;
|
||||
schema: Knex.SchemaBuilder;
|
||||
queryBuilder(): Knex.QueryBuilder;
|
||||
|
||||
@@ -250,7 +251,7 @@ declare namespace Knex {
|
||||
}
|
||||
|
||||
interface WithSchema {
|
||||
(schema: string): QueryBuilder
|
||||
(schema: string): QueryBuilder;
|
||||
}
|
||||
|
||||
interface WithWrapped {
|
||||
@@ -523,7 +524,7 @@ declare namespace Knex {
|
||||
seeds?: SeedsConfig;
|
||||
acquireConnectionTimeout?: number;
|
||||
useNullAsDefault?: boolean;
|
||||
searchPath?: string;
|
||||
searchPath?: string | string[];
|
||||
}
|
||||
|
||||
interface ConnectionConfig {
|
||||
|
||||
+54
-50
@@ -118,8 +118,12 @@ var knex = Knex({
|
||||
|
||||
// searchPath
|
||||
var knex = Knex({
|
||||
client: 'pg',
|
||||
searchPath: 'public',
|
||||
client: 'pg',
|
||||
searchPath: 'public',
|
||||
});
|
||||
var knex = Knex({
|
||||
client: 'pg',
|
||||
searchPath: ['public', 'private'],
|
||||
});
|
||||
|
||||
// useNullAsDefault
|
||||
@@ -159,7 +163,7 @@ knex.select('title', 'author', 'year').from('books');
|
||||
knex.select().table('books');
|
||||
|
||||
knex.avg('sum_column1').from(function() {
|
||||
this.sum('column1 as sum_column1').from('t1').groupBy('column1').as('t1')
|
||||
this.sum('column1 as sum_column1').from('t1').groupBy('column1').as('t1');
|
||||
}).as('ignored_alias');
|
||||
|
||||
knex.column('title', 'author', 'year').select().from('books');
|
||||
@@ -174,7 +178,7 @@ knex('users').where({
|
||||
knex('users').where('id', 1);
|
||||
|
||||
knex('users').where(() => {
|
||||
this.where('id', 1).orWhere('id', '>', 10)
|
||||
this.where('id', 1).orWhere('id', '>', 10);
|
||||
}).orWhere({name: 'Tester'});
|
||||
|
||||
knex('users').where('votes', '>', 100);
|
||||
@@ -242,11 +246,11 @@ knex('users')
|
||||
.select('users.id', 'contacts.phone');
|
||||
|
||||
knex.select('*').from('users').join(knex('accounts').select('id', 'owner_id').as('accounts'), function() {
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('accounts', function() {
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('accounts', function(join: Knex.JoinClause) {
|
||||
@@ -262,121 +266,121 @@ knex.select('*').from('user').join('contacts', () => {
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').onIn('contacts.id', [7, 15, 23, 41])
|
||||
this.on('users.id', '=', 'contacts.id').onIn('contacts.id', [7, 15, 23, 41]);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').andOnIn('contacts.id', [7, 15, 23, 41])
|
||||
this.on('users.id', '=', 'contacts.id').andOnIn('contacts.id', [7, 15, 23, 41]);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').orOnIn('contacts.id', [7, 15, 23, 41])
|
||||
this.on('users.id', '=', 'contacts.id').orOnIn('contacts.id', [7, 15, 23, 41]);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').onNotIn('contacts.id', [7, 15, 23, 41])
|
||||
this.on('users.id', '=', 'contacts.id').onNotIn('contacts.id', [7, 15, 23, 41]);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').andOnNotIn('contacts.id', [7, 15, 23, 41])
|
||||
this.on('users.id', '=', 'contacts.id').andOnNotIn('contacts.id', [7, 15, 23, 41]);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').orOnNotIn('contacts.id', [7, 15, 23, 41])
|
||||
this.on('users.id', '=', 'contacts.id').orOnNotIn('contacts.id', [7, 15, 23, 41]);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').onNull('contacts.email')
|
||||
this.on('users.id', '=', 'contacts.id').onNull('contacts.email');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').andOnNull('contacts.email')
|
||||
this.on('users.id', '=', 'contacts.id').andOnNull('contacts.email');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').orOnNull('contacts.email')
|
||||
this.on('users.id', '=', 'contacts.id').orOnNull('contacts.email');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').onNotNull('contacts.email')
|
||||
this.on('users.id', '=', 'contacts.id').onNotNull('contacts.email');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').andOnNotNull('contacts.email')
|
||||
this.on('users.id', '=', 'contacts.id').andOnNotNull('contacts.email');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').orOnNotNull('contacts.email')
|
||||
this.on('users.id', '=', 'contacts.id').orOnNotNull('contacts.email');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').onExists(function() {
|
||||
this.select('*').from('accounts').whereRaw('users.account_id = accounts.id');
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').andOnExists(function() {
|
||||
this.select('*').from('accounts').whereRaw('users.account_id = accounts.id');
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').orOnExists(function() {
|
||||
this.select('*').from('accounts').whereRaw('users.account_id = accounts.id');
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').onNotExists(function() {
|
||||
this.select('*').from('accounts').whereRaw('users.account_id = accounts.id');
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').andOnNotExists(function() {
|
||||
this.select('*').from('accounts').whereRaw('users.account_id = accounts.id');
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').orOnNotExists(function() {
|
||||
this.select('*').from('accounts').whereRaw('users.account_id = accounts.id');
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').onBetween('contacts.id', [5, 30])
|
||||
this.on('users.id', '=', 'contacts.id').onBetween('contacts.id', [5, 30]);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').andOnBetween('contacts.id', [5, 30])
|
||||
this.on('users.id', '=', 'contacts.id').andOnBetween('contacts.id', [5, 30]);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').orOnBetween('contacts.id', [5, 30])
|
||||
this.on('users.id', '=', 'contacts.id').orOnBetween('contacts.id', [5, 30]);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').onNotBetween('contacts.id', [5, 30])
|
||||
this.on('users.id', '=', 'contacts.id').onNotBetween('contacts.id', [5, 30]);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').andOnNotBetween('contacts.id', [5, 30])
|
||||
this.on('users.id', '=', 'contacts.id').andOnNotBetween('contacts.id', [5, 30]);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').orOnNotBetween('contacts.id', [5, 30])
|
||||
this.on('users.id', '=', 'contacts.id').orOnNotBetween('contacts.id', [5, 30]);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('contacts', function() {
|
||||
this.on('users.id', '=', 'contacts.id').onNotExists(function() {
|
||||
this.select('*').from('accounts').whereRaw('users.account_id = accounts.id');
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('accounts', (join: Knex.JoinClause) => {
|
||||
join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').join('accounts', 'accounts.type', knex.raw('?', ['admin']));
|
||||
@@ -388,7 +392,7 @@ knex.from('users').innerJoin('accounts', 'users.id', 'accounts.user_id');
|
||||
knex.table('users').innerJoin('accounts', 'users.id', '=', 'accounts.user_id');
|
||||
|
||||
knex('users').innerJoin('accounts', function() {
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex('users').innerJoin('accounts', (join: Knex.JoinClause) => {
|
||||
@@ -398,53 +402,53 @@ knex('users').innerJoin('accounts', (join: Knex.JoinClause) => {
|
||||
knex.select('*').from('users').leftJoin('accounts', 'users.id', 'accounts.user_id');
|
||||
|
||||
knex.select('*').from('users').leftJoin('accounts', function() {
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').leftJoin('accounts', (join: Knex.JoinClause) => {
|
||||
join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').leftOuterJoin('accounts', 'users.id', 'accounts.user_id');
|
||||
|
||||
knex.select('*').from('users').leftOuterJoin('accounts', function() {
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').rightJoin('accounts', 'users.id', 'accounts.user_id');
|
||||
|
||||
knex.select('*').from('users').rightJoin('accounts', function() {
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').rightJoin('accounts', (join: Knex.JoinClause) => {
|
||||
join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').rightOuterJoin('accounts', 'users.id', 'accounts.user_id');
|
||||
|
||||
knex.select('*').from('users').rightOuterJoin('accounts', function() {
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').outerJoin('accounts', 'users.id', 'accounts.user_id');
|
||||
|
||||
knex.select('*').from('users').outerJoin('accounts', function() {
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').outerJoin('accounts', (join: Knex.JoinClause) => {
|
||||
join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').fullOuterJoin('accounts', 'users.id', 'accounts.user_id');
|
||||
|
||||
knex.select('*').from('users').fullOuterJoin('accounts', function() {
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').fullOuterJoin('accounts', (join: Knex.JoinClause) => {
|
||||
join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id')
|
||||
join.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id');
|
||||
});
|
||||
|
||||
knex.select('*').from('users').crossJoin('accounts', 'users.id', 'accounts.user_id');
|
||||
@@ -480,7 +484,7 @@ knex('books')
|
||||
.returning('id')
|
||||
.insert([{title: 'Great Gatsby'}, {title: 'Fahrenheit 451'}]);
|
||||
|
||||
knex.batchInsert('books', [{title:'Great Gatsby'}, {title: 'Fahrenheit 451'}], 200);
|
||||
knex.batchInsert('books', [{title: 'Great Gatsby'}, {title: 'Fahrenheit 451'}], 200);
|
||||
knex.queryBuilder().table('books');
|
||||
|
||||
knex('books').where('published_date', '<', 2000).update({status: 'archived'});
|
||||
@@ -546,15 +550,15 @@ knex.transaction(function(trx) {
|
||||
knex('tableName')
|
||||
.transacting(trx)
|
||||
.forShare()
|
||||
.select('*')
|
||||
})
|
||||
.select('*');
|
||||
});
|
||||
|
||||
const transactionReturnValue = knex.transaction(function(trx) {
|
||||
return knex("table")
|
||||
.insert({ foo: "bar" })
|
||||
.returning(["id"])
|
||||
.then(function(result) { return result[0].id as number })
|
||||
})
|
||||
.then(function(result) { return result[0].id as number; });
|
||||
});
|
||||
|
||||
// Tests that the transaction has kept the type of its return value by referencing a method of number
|
||||
transactionReturnValue.then(value => value.toExponential);
|
||||
@@ -781,7 +785,7 @@ knex.select('name').from('users')
|
||||
console.log(rows);
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.error(error)
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
knex.select('*').from('users').where({name: 'Tim'})
|
||||
@@ -825,7 +829,7 @@ knex.select('name').from('users').limit(10).then(function (rows: any[]) {
|
||||
memo.names.push(row.name);
|
||||
memo.count++;
|
||||
return memo;
|
||||
}, {count: 0, names: []})
|
||||
}, {count: 0, names: []});
|
||||
}).then(function(obj: any) {
|
||||
console.log(obj);
|
||||
}).catch(function(e: Error) {
|
||||
|
||||
@@ -21,4 +21,4 @@
|
||||
"index.d.ts",
|
||||
"knex-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,15 +65,11 @@
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
"unified-signatures": false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user