[@types/knex] Update ChainableInterface. (#28716)

Fixes #28679.

As I [noted in a comment](https://github.com/DefinitelyTyped/DefinitelyTyped/issues/28679#issuecomment-419265731) on the original issue, the class-like objects [`Raw`](https://github.com/tgriesser/knex/blob/master/src/raw.js#L191-L193), [`QueryBuilder`](2183a27826/src/query/builder.js (L1074)), and [`SchemaBuilder`](232fe9f151/src/schema/builder.js (L68)) use a [utility file](https://github.com/tgriesser/knex/blob/master/src/interface.js) to extend a handful of methods onto them.
The contents of this file are represented in the `ChainableInterface` interface.

Changes made:
- Updated `SchemaBuilder` to extend `ChainableInterface`.
- Moved `debug`, `transacting`, and `connection` from `QueryInterface` to `ChainableInterface`.
- Removed `exec` from `ChainableInterface` as it was [removed 0.12.0](https://github.com/tgriesser/knex/blob/master/CHANGELOG.md#0120---13-sep-2016).
This commit is contained in:
Matt R. Wilson
2018-09-10 15:41:16 -06:00
committed by Ryan Cavanaugh
parent 3ff332729a
commit 2cbd45cb2a
2 changed files with 10 additions and 20 deletions

18
types/knex/index.d.ts vendored
View File

@@ -156,7 +156,6 @@ declare namespace Knex {
// Others
first: Select;
debug(enabled?: boolean): QueryBuilder;
pluck(column: string): QueryBuilder;
insert(data: any, returning?: string | string[]): QueryBuilder;
@@ -169,9 +168,6 @@ declare namespace Knex {
delete(returning?: string | string[]): QueryBuilder;
truncate(): QueryBuilder;
transacting(trx?: Transaction): QueryBuilder;
connection(connection: any): QueryBuilder;
clone(): QueryBuilder;
}
@@ -390,12 +386,14 @@ declare namespace Knex {
interface ChainableInterface extends Bluebird<any> {
toQuery(): string;
options(options: any): QueryBuilder;
stream(callback: (readable: stream.PassThrough) => any): Bluebird<any>;
options(options: { [key: string]: any }): this;
connection(connection: any): this;
debug(enabled: boolean): this;
transacting(trx: Transaction): this;
stream(handler: (readable: stream.PassThrough) => any): Bluebird<any>;
stream(options: { [key: string]: any }, handler: (readable: stream.PassThrough) => any): Bluebird<any>;
stream(options?: { [key: string]: any }): stream.PassThrough;
stream(options: { [key: string]: any }, callback: (readable: stream.PassThrough) => any): Bluebird<any>;
pipe(writable: any): stream.PassThrough;
exec(callback: Function): QueryBuilder;
pipe<T extends NodeJS.WritableStream>(writable: T, options?: { [key: string]: any }): stream.PassThrough;
}
interface Transaction extends Knex {
@@ -408,7 +406,7 @@ declare namespace Knex {
// Schema builder
//
interface SchemaBuilder extends Bluebird<any> {
interface SchemaBuilder extends ChainableInterface {
createTable(tableName: string, callback: (tableBuilder: CreateTableBuilder) => any): SchemaBuilder;
createTableIfNotExists(tableName: string, callback: (tableBuilder: CreateTableBuilder) => any): SchemaBuilder;
alterTable(tableName: string, callback: (tableBuilder: CreateTableBuilder) => any): SchemaBuilder;

View File

@@ -982,19 +982,11 @@ knex.select('name').from('users')
.where('id', '>', 20)
.andWhere('id', '<', 200)
.limit(10)
.offset(x)
.exec(function(err: any, rows: any[]) {
if (err) return console.error(err);
knex.select('id').from('nicknames').whereIn('nickname', rows.map((r: any) => r.name))
.exec(function(err: any, rows: any[]) {
if (err) return console.error(err);
console.log(rows);
});
});
.offset(x);
// Retrieve the stream:
var stream = knex.select('*').from('users').stream();
var writableStream: any;
var writableStream: NodeJS.WritableStream;
stream.pipe(writableStream);
// With options: