Knex - Add connection Client for extension.

This commit is contained in:
Matt R. Wilson
2017-12-05 12:29:04 -07:00
parent 3785084f44
commit 8c230bbd78
2 changed files with 28 additions and 2 deletions
+21 -2
View File
@@ -1,6 +1,9 @@
// Type definitions for Knex.js
// 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>
// 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>
// 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<any>;
destroyRawConnection(connection: any): Promise<void>;
validateConnection(connection: any): Promise<boolean>;
}
}
export = Knex;
+7
View File
@@ -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