From 8c230bbd78f7fa02c4c0e048c32dcd583f56685c Mon Sep 17 00:00:00 2001 From: "Matt R. Wilson" Date: Tue, 5 Dec 2017 12:27:30 -0700 Subject: [PATCH] Knex - Add connection Client for extension. --- types/knex/index.d.ts | 23 +++++++++++++++++++++-- types/knex/knex-tests.ts | 7 +++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/types/knex/index.d.ts b/types/knex/index.d.ts index e96dfbefd8..479e38c286 100644 --- a/types/knex/index.d.ts +++ b/types/knex/index.d.ts @@ -1,6 +1,9 @@ // Type definitions for Knex.js // Project: https://github.com/tgriesser/knex -// Definitions by: Qubo , Baronfel , Pablo Rodríguez +// Definitions by: Qubo +// Baronfel +// Pablo Rodríguez +// Matt R. Wilson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -510,7 +513,7 @@ declare namespace Knex { interface Config { debug?: boolean; - client?: string; + client?: string | typeof Client; dialect?: string; version?: string; connection?: string | ConnectionConfig | MariaSqlConnectionConfig | @@ -676,6 +679,22 @@ declare namespace Knex { interface FunctionHelper { now(): Raw; } + + // + // Clients + // + + class Client extends events.EventEmitter { + constructor(config: Config); + config: Config; + dialect: string; + driverName: string; + connectionSettings: object; + + acquireRawConnection(): Promise; + destroyRawConnection(connection: any): Promise; + validateConnection(connection: any): Promise; + } } export = Knex; diff --git a/types/knex/knex-tests.ts b/types/knex/knex-tests.ts index c7c99813f1..910f0ee427 100644 --- a/types/knex/knex-tests.ts +++ b/types/knex/knex-tests.ts @@ -128,6 +128,13 @@ var knex = Knex({ useNullAsDefault: true, }); +// Using custom client +class TestClient extends Knex.Client {} + +var knex = Knex({ + client: TestClient, +}); + knex('books').insert({title: 'Test'}).returning('*').toString(); // Migrations