diff --git a/adonis-typings/database.ts b/adonis-typings/database.ts index 23ae8da6..7eddd0d3 100644 --- a/adonis-typings/database.ts +++ b/adonis-typings/database.ts @@ -323,7 +323,10 @@ declare module '@ioc:Adonis/Addons/Database' { * Connection represents a single knex instance with inbuilt * pooling capabilities. */ - export interface ConnectionContract extends EventEmitter, QueryClientContract { + export interface ConnectionContract extends EventEmitter { + client?: knex, + readClient?: knex, + /** * Read/write connection pools */ @@ -357,5 +360,11 @@ declare module '@ioc:Adonis/Addons/Database' { * Disconnect knex */ disconnect (): Promise, + + /** + * Returns an instance of a given client. A sticky client + * always uses the write connection for all queries + */ + getClient (sticky?: boolean): QueryClientContract, } } diff --git a/index.ts b/index.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Connection/index.ts b/src/Connection/index.ts index 4fb38ddf..6537dc41 100644 --- a/src/Connection/index.ts +++ b/src/Connection/index.ts @@ -15,21 +15,9 @@ import { EventEmitter } from 'events' import { Exception } from '@poppinss/utils' import { LoggerContract } from '@poppinss/logger' import { patchKnex } from 'knex-dynamic-connection' -import { resolveClientNameWithAliases } from 'knex/lib/helpers' import { ConnectionConfigContract, ConnectionContract } from '@ioc:Adonis/Addons/Database' - -import { - DatabaseQueryBuilderContract, - RawContract, - InsertQueryBuilderContract, - TransactionClientContract, -} from '@ioc:Adonis/Addons/DatabaseQueryBuilder' - -import { Transaction } from '../Transaction' -import { RawQueryBuilder } from '../QueryBuilder/Raw' -import { InsertQueryBuilder } from '../QueryBuilder/Insert' -import { DatabaseQueryBuilder } from '../QueryBuilder/Database' +import { QueryClient } from '../QueryClient' /** * Connection class manages a given database connection. Internally it uses @@ -41,23 +29,13 @@ export class Connection extends EventEmitter implements ConnectionContract { * Reference to knex. The instance is created once the `open` * method is invoked */ - private _client?: knex + public client?: knex /** * Read client when read/write replicas are defined in the config, otherwise * it is a reference to the `client`. */ - private _readClient?: knex - - /** - * Not a transaction client - */ - public isTransaction = false - - /** - * The name of the dialect in use - */ - public dialect = resolveClientNameWithAliases(this.config.client) + public readClient?: knex /** * Config for one or more read replicas. Only exists, when replicas are @@ -83,7 +61,7 @@ export class Connection extends EventEmitter implements ConnectionContract { * Raises exception when client or readClient are not defined */ private _ensureClients () { - if (!this._client || !this._readClient) { + if (!this.client || !this.readClient) { throw new Exception('Connection is not in ready state. Make sure to call .connect first') } } @@ -116,8 +94,8 @@ export class Connection extends EventEmitter implements ConnectionContract { * Cleanup references */ private _cleanup () { - this._client = undefined - this._readClient = undefined + this.client = undefined + this.readClient = undefined this._readReplicas = [] } @@ -254,8 +232,8 @@ export class Connection extends EventEmitter implements ConnectionContract { * Creates the write connection */ private _setupWriteConnection () { - this._client = knex(this._getWriteConfig()) - patchKnex(this._client, this._writeConfigResolver.bind(this)) + this.client = knex(this._getWriteConfig()) + patchKnex(this.client, this._writeConfigResolver.bind(this)) } /** @@ -264,20 +242,21 @@ export class Connection extends EventEmitter implements ConnectionContract { */ private _setupReadConnection () { if (!this._hasReadWriteReplicas()) { - this._readClient = this._client + this.readClient = this.client return } this._logger.trace({ connection: this.name }, 'setting up read/write replicas') - this._readClient = knex(this._getReadConfig()) - patchKnex(this._readClient, this._readConfigResolver.bind(this)) + + this.readClient = knex(this._getReadConfig()) + patchKnex(this.readClient, this._readConfigResolver.bind(this)) } /** * Returns the pool instance for the given connection */ public get pool (): null | Pool { - return this._client ? this._client.client.pool : null + return this.client ? this.client.client.pool : null } /** @@ -285,7 +264,7 @@ export class Connection extends EventEmitter implements ConnectionContract { * not in use, then read/write pools are same. */ public get readPool (): null | Pool { - return this._readClient ? this._readClient.client.pool : null + return this.readClient ? this.readClient.client.pool : null } /** @@ -316,9 +295,9 @@ export class Connection extends EventEmitter implements ConnectionContract { /** * Disconnect write client */ - if (this._client) { + if (this.client) { try { - await this._client.destroy() + await this.client.destroy() } catch (error) { this.emit('disconnect:error', error, this) } @@ -328,9 +307,9 @@ export class Connection extends EventEmitter implements ConnectionContract { * Disconnect read client when it exists and both clients * aren't same */ - if (this._readClient && this._readClient !== this._client) { + if (this.readClient && this.readClient !== this.client) { try { - await this._readClient.destroy() + await this.readClient.destroy() } catch (error) { this.emit('disconnect:error', error, this) } @@ -338,88 +317,11 @@ export class Connection extends EventEmitter implements ConnectionContract { } /** - * Returns the read client - */ - public getReadClient () { - this._ensureClients() - return this._readClient! - } - - /** - * Returns the write client - */ - public getWriteClient () { - this._ensureClients() - return this._client! - } - - /** - * Truncate table - */ - public async truncate (table: string): Promise { - this._ensureClients() - await this._client!.select(table).truncate() - } - - /** - * Get information for a table columns - */ - public async columnsInfo (table: string, column?: string): Promise { - this._ensureClients() - const query = this._client!.select(table) - const result = await (column ? query.columnInfo(column) : query.columnInfo()) - return result - } - - /** - * Returns an instance of a transaction. Each transaction will - * query and hold a single connection for all queries. - */ - public async transaction (): Promise { - this._ensureClients() - const trx = await this._client!.transaction() - return new Transaction(trx, this.dialect) - } - - /** - * Returns instance of a query builder for selecting, updating - * or deleting rows - */ - public query (): DatabaseQueryBuilderContract { - this._ensureClients() - return new DatabaseQueryBuilder(this._client!.queryBuilder(), this) - } - - /** - * Returns instance of a query builder for inserting rows - */ - public insertQuery (): InsertQueryBuilderContract { - this._ensureClients() - return new InsertQueryBuilder(this._client!.queryBuilder(), this) - } - - /** - * Returns instance of raw query builder - */ - public raw (sql: any, bindings?: any): RawContract { - this._ensureClients() - return new RawQueryBuilder(this._client!.raw(sql, bindings)) - } - - /** - * Returns instance of a query builder and selects the table - */ - public from (table: any): DatabaseQueryBuilderContract { - this._ensureClients() - return this.query().from(table) - } - - /** - * Returns instance of a query builder and selects the table - * for an insert query + * Returns an instance for a query client that using this connection. Setting + * `sticky=true` will use the write connection for reads */ - public table (table: any): InsertQueryBuilderContract { + public getClient (sticky = false) { this._ensureClients() - return this.insertQuery().table(table) + return sticky ? new QueryClient(this.client!) : new QueryClient(this.client!, this.readClient!) } } diff --git a/src/QueryClient/index.ts b/src/QueryClient/index.ts new file mode 100644 index 00000000..b05bcccb --- /dev/null +++ b/src/QueryClient/index.ts @@ -0,0 +1,121 @@ +/* + * @adonisjs/lucid + * + * (c) Harminder Virk + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. +*/ + +/// + +import * as knex from 'knex' +import { + RawContract, + QueryClientContract, + TransactionClientContract, + InsertQueryBuilderContract, + DatabaseQueryBuilderContract, +} from '@ioc:Adonis/Addons/DatabaseQueryBuilder' +import { resolveClientNameWithAliases } from 'knex/lib/helpers' + +import { TransactionClient } from '../TransactionClient' +import { RawQueryBuilder } from '../QueryBuilder/Raw' +import { InsertQueryBuilder } from '../QueryBuilder/Insert' +import { DatabaseQueryBuilder } from '../QueryBuilder/Database' + +/** + * Query client exposes the API to fetch instance of different query builders + * to perform queries on a selection connection. + */ +export class QueryClient implements QueryClientContract { + /** + * Not a transaction client + */ + public isTransaction = false + + /** + * The name of the dialect in use + */ + public dialect = resolveClientNameWithAliases(this._client.client.config) + + constructor (private _client: knex, private _readClient?: knex) { + } + + /** + * Returns the read client. The readClient is optional, since we can get + * an instance of [[QueryClient]] with a sticky write client. + */ + public getReadClient () { + return this._readClient || this._client + } + + /** + * Returns the write client + */ + public getWriteClient () { + return this._client + } + + /** + * Truncate table + */ + public async truncate (table: string): Promise { + await this._client.select(table).truncate() + } + + /** + * Get information for a table columns + */ + public async columnsInfo (table: string, column?: string): Promise { + const query = this._client.select(table) + const result = await (column ? query.columnInfo(column) : query.columnInfo()) + return result + } + + /** + * Returns an instance of a transaction. Each transaction will + * query and hold a single connection for all queries. + */ + public async transaction (): Promise { + const trx = await this._client.transaction() + return new TransactionClient(trx, this.dialect) + } + + /** + * Returns instance of a query builder for selecting, updating + * or deleting rows + */ + public query (): DatabaseQueryBuilderContract { + return new DatabaseQueryBuilder(this._client.queryBuilder(), this) + } + + /** + * Returns instance of a query builder for inserting rows + */ + public insertQuery (): InsertQueryBuilderContract { + return new InsertQueryBuilder(this._client.queryBuilder(), this) + } + + /** + * Returns instance of raw query builder + */ + public raw (sql: any, bindings?: any): RawContract { + return new RawQueryBuilder(this._client.raw(sql, bindings)) + } + + /** + * Returns instance of a query builder and selects the table + */ + public from (table: any): DatabaseQueryBuilderContract { + return this.query().from(table) + } + + /** + * Returns instance of a query builder and selects the table + * for an insert query + */ + public table (table: any): InsertQueryBuilderContract { + return this.insertQuery().table(table) + } +} diff --git a/src/Transaction/index.ts b/src/TransactionClient/index.ts similarity index 95% rename from src/Transaction/index.ts rename to src/TransactionClient/index.ts index d65f0944..1ade6fef 100644 --- a/src/Transaction/index.ts +++ b/src/TransactionClient/index.ts @@ -26,7 +26,10 @@ import { DatabaseQueryBuilder } from '../QueryBuilder/Database' * Transaction uses a dedicated connection from the connection pool * and executes queries inside a given transaction. */ -export class Transaction implements TransactionClientContract { +export class TransactionClient implements TransactionClientContract { + /** + * Always true + */ public isTransaction: true = true constructor (public knexClient: knex.Transaction, public dialect: string) { @@ -91,7 +94,7 @@ export class Transaction implements TransactionClientContract { */ public async transaction (): Promise { const trx = await this.knexClient.transaction() - return new Transaction(trx, this.dialect) + return new TransactionClient(trx, this.dialect) } /** diff --git a/test-helpers/index.ts b/test-helpers/index.ts index 28b7fc50..208b60e5 100644 --- a/test-helpers/index.ts +++ b/test-helpers/index.ts @@ -20,6 +20,7 @@ import { RawContract, InsertQueryBuilderContract, DatabaseQueryBuilderContract, + QueryClientContract, } from '@ioc:Adonis/Addons/DatabaseQueryBuilder' import { RawQueryBuilder } from '../src/QueryBuilder/Raw' @@ -118,10 +119,10 @@ export async function resetTables () { /** * Returns query builder instance for a given connection */ -export function getQueryBuilder (connection: ConnectionContract) { +export function getQueryBuilder (client: QueryClientContract) { return new DatabaseQueryBuilder( - connection.getWriteClient().queryBuilder(), - connection, + client.getWriteClient().queryBuilder(), + client, ) as unknown as DatabaseQueryBuilderContract } @@ -130,7 +131,7 @@ export function getQueryBuilder (connection: ConnectionContract) { */ export function getRawQueryBuilder (connection: ConnectionContract, sql: string, bindings?: any[]) { return new RawQueryBuilder( - bindings ? connection.getWriteClient().raw(sql, bindings) : connection.getWriteClient().raw(sql), + bindings ? connection.client!.raw(sql, bindings) : connection.client!.raw(sql), ) as unknown as RawContract } @@ -138,9 +139,7 @@ export function getRawQueryBuilder (connection: ConnectionContract, sql: string, * Returns query builder instance for a given connection */ export function getInsertBuilder (connection: ConnectionContract) { - return new InsertQueryBuilder( - connection.getWriteClient().queryBuilder(), - ) as unknown as InsertQueryBuilderContract + return new InsertQueryBuilder(connection.client!.queryBuilder()) as unknown as InsertQueryBuilderContract } /** diff --git a/test/connection.spec.ts b/test/connection.spec.ts index 232ab3e5..4e252358 100644 --- a/test/connection.spec.ts +++ b/test/connection.spec.ts @@ -86,13 +86,13 @@ test.group('Connection | setup', (group) => { test('do not instantiate knex unless connect is called', (assert) => { const connection = new Connection('primary', getConfig(), getLogger()) - assert.isUndefined(connection['_client']) + assert.isUndefined(connection.client) }) test('instantiate knex when connect is invoked', async (assert, done) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.on('connect', () => { - assert.isDefined(connection.getWriteClient()) + assert.isDefined(connection.client!) assert.equal(connection.pool!.numUsed(), 0) done() }) @@ -105,7 +105,7 @@ test.group('Connection | setup', (group) => { connection.connect() await connection.disconnect() - assert.isUndefined(connection['_client']) + assert.isUndefined(connection.client) assert.isUndefined(connection['_readClient']) }) @@ -114,7 +114,7 @@ test.group('Connection | setup', (group) => { connection.connect() connection.on('disconnect', () => { - assert.isUndefined(connection['_client']) + assert.isUndefined(connection.client) done() }) @@ -143,14 +143,14 @@ if (process.env.DB === 'mysql') { const connection = new Connection('primary', config, getLogger()) connection.connect() - assert.equal(connection.getWriteClient()['_context'].client.constructor.name, 'Client_MySQL') - assert.equal(connection.getWriteClient()['_context'].client.config.connection.charset, 'utf-8') - assert.equal(connection.getWriteClient()['_context'].client.config.connection.typeCast, false) + assert.equal(connection.client!['_context'].client.constructor.name, 'Client_MySQL') + assert.equal(connection.client!['_context'].client.config.connection.charset, 'utf-8') + assert.equal(connection.client!['_context'].client.config.connection.typeCast, false) }) }) } -test.group('Connection | query', (group) => { +test.group('Connection | queryClient', (group) => { group.before(async () => { await setup() }) @@ -163,7 +163,7 @@ test.group('Connection | query', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const results = await connection.query().from('users') + const results = await connection.getClient().query().from('users') assert.isArray(results) assert.lengthOf(results, 0) @@ -174,9 +174,9 @@ test.group('Connection | query', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - await connection.insertQuery().table('users').insert({ username: 'virk' }) + await connection.getClient().insertQuery().table('users').insert({ username: 'virk' }) - const results = await connection.query().from('users') + const results = await connection.getClient().query().from('users') assert.isArray(results) assert.lengthOf(results, 1) assert.equal(results[0].username, 'virk') @@ -190,9 +190,9 @@ test.group('Connection | query', (group) => { const command = process.env.DB === 'sqlite' ? `DELETE FROM users;` : 'TRUNCATE users;' - await connection.insertQuery().table('users').insert({ username: 'virk' }) - await connection.raw(command).exec() - const results = await connection.query().from('users') + await connection.getClient().insertQuery().table('users').insert({ username: 'virk' }) + await connection.getClient().raw(command).exec() + const results = await connection.getClient().query().from('users') assert.isArray(results) assert.lengthOf(results, 0) @@ -203,11 +203,11 @@ test.group('Connection | query', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const trx = await connection.transaction() + const trx = await connection.getClient().transaction() await trx.insertQuery().table('users').insert({ username: 'virk' }) await trx.rollback() - const results = await connection.query().from('users') + const results = await connection.getClient().query().from('users') assert.isArray(results) assert.lengthOf(results, 0) diff --git a/test/insert-query-builder.spec.ts b/test/insert-query-builder.spec.ts index 1f97fe4d..b02233ef 100644 --- a/test/insert-query-builder.spec.ts +++ b/test/insert-query-builder.spec.ts @@ -30,7 +30,7 @@ test.group('Query Builder | from', (group) => { const db = getInsertBuilder(connection) const { sql, bindings } = db.table('users').insert({ username: 'virk' }).toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .insert({ username: 'virk' }) .toSQL() @@ -49,7 +49,7 @@ test.group('Query Builder | from', (group) => { .multiInsert([{ username: 'virk' }, { username: 'nikk' }]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .insert([{ username: 'virk' }, { username: 'nikk' }]) .toSQL() @@ -69,7 +69,7 @@ test.group('Query Builder | from', (group) => { .multiInsert([{ username: 'virk' }, { username: 'nikk' }]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .returning(['id', 'username']) .insert([{ username: 'virk' }, { username: 'nikk' }]) diff --git a/test/query-builder.spec.ts b/test/query-builder.spec.ts index 27b13c96..d7b161fd 100644 --- a/test/query-builder.spec.ts +++ b/test/query-builder.spec.ts @@ -28,13 +28,14 @@ if (process.env.DB !== 'sqlite') { assert.plan(1) const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() + const client = connection.getClient() + const db = getQueryBuilder(client) - connection.getReadClient = function getReadClient () { + client.getReadClient = function getReadClient () { assert.isTrue(true) return this._client } - const db = getQueryBuilder(connection) db.select('*').from('users') db['_getQueryClient']() }) @@ -43,9 +44,10 @@ if (process.env.DB !== 'sqlite') { assert.plan(1) const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() + const client = connection.getClient() + const db = getQueryBuilder(client) - const db = getQueryBuilder(connection) - connection.getWriteClient = function getWriteClient () { + client.getWriteClient = function getWriteClient () { assert.isTrue(true) return this._client } @@ -58,9 +60,10 @@ if (process.env.DB !== 'sqlite') { assert.plan(1) const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const client = connection.getClient() + const db = getQueryBuilder(client) - connection.getWriteClient = function getWriteClient () { + client.getWriteClient = function getWriteClient () { assert.isTrue(true) return this._client } @@ -84,9 +87,9 @@ test.group('Query Builder | from', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db.from('users').toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient().from('users').toSQL() + const { sql: knexSql, bindings: knexBindings } = connection.client!.from('users').toSQL() assert.equal(sql, knexSql) assert.deepEqual(bindings, knexBindings) @@ -96,9 +99,9 @@ test.group('Query Builder | from', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db.from({ u: 'users' }).toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient().from({ u: 'users' }).toSQL() + const { sql: knexSql, bindings: knexBindings } = connection.client!.from({ u: 'users' }).toSQL() assert.equal(sql, knexSql) assert.deepEqual(bindings, knexBindings) @@ -118,13 +121,13 @@ test.group('Query Builder | where', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .where('username', 'virk') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .where('username', 'virk') .toSQL() @@ -137,13 +140,13 @@ test.group('Query Builder | where', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .where({ username: 'virk', age: 22 }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .where({ username: 'virk', age: 22 }) .toSQL() @@ -156,13 +159,13 @@ test.group('Query Builder | where', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .where((builder) => builder.where('username', 'virk')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .where((builder) => builder.where('username', 'virk')) .toSQL() @@ -175,13 +178,13 @@ test.group('Query Builder | where', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .where('age', '>', 22) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .where('age', '>', 22) .toSQL() @@ -194,15 +197,15 @@ test.group('Query Builder | where', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .where('age', '>', getRawQueryBuilder(connection, 'select min_age from ages limit 1;')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .where('age', '>', connection.getWriteClient().raw('select min_age from ages limit 1;')) + .where('age', '>', connection.client!.raw('select min_age from ages limit 1;')) .toSQL() assert.equal(sql, knexSql) @@ -213,14 +216,14 @@ test.group('Query Builder | where', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .where('age', '>', 22) .orWhere('age', 18) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .where('age', '>', 22) .orWhere('age', 18) @@ -234,7 +237,7 @@ test.group('Query Builder | where', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .where('age', '>', 22) @@ -244,7 +247,7 @@ test.group('Query Builder | where', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .where('age', '>', 22) .orWhere((builder) => { @@ -270,13 +273,13 @@ test.group('Query Builder | whereNot', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNot('username', 'virk') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNot('username', 'virk') .toSQL() @@ -289,13 +292,13 @@ test.group('Query Builder | whereNot', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNot({ username: 'virk', age: 22 }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNot({ username: 'virk', age: 22 }) .toSQL() @@ -308,13 +311,13 @@ test.group('Query Builder | whereNot', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNot((builder) => builder.where('username', 'virk')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNot((builder) => builder.where('username', 'virk')) .toSQL() @@ -327,13 +330,13 @@ test.group('Query Builder | whereNot', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNot('age', '>', 22) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNot('age', '>', 22) .toSQL() @@ -346,15 +349,15 @@ test.group('Query Builder | whereNot', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNot('age', '>', getRawQueryBuilder(connection, 'select min_age from ages limit 1;')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .whereNot('age', '>', connection.getWriteClient().raw('select min_age from ages limit 1;')) + .whereNot('age', '>', connection.client!.raw('select min_age from ages limit 1;')) .toSQL() assert.equal(sql, knexSql) @@ -365,14 +368,14 @@ test.group('Query Builder | whereNot', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNot('age', '>', 22) .orWhereNot('age', 18) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNot('age', '>', 22) .orWhereNot('age', 18) @@ -386,7 +389,7 @@ test.group('Query Builder | whereNot', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .where('age', '>', 22) @@ -396,7 +399,7 @@ test.group('Query Builder | whereNot', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .where('age', '>', 22) .orWhereNot((builder) => { @@ -422,13 +425,13 @@ test.group('Query Builder | whereIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereIn('username', ['virk', 'nikk']) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereIn('username', ['virk', 'nikk']) .toSQL() @@ -441,7 +444,7 @@ test.group('Query Builder | whereIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereIn('username', (builder) => { @@ -449,7 +452,7 @@ test.group('Query Builder | whereIn', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereIn('username', (builder) => { builder.from('accounts') @@ -464,15 +467,15 @@ test.group('Query Builder | whereIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .whereIn('username', getQueryBuilder(connection).select('id').from('accounts')) + .whereIn('username', getQueryBuilder(connection.getClient()).select('id').from('accounts')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .whereIn('username', connection.getWriteClient().select('id').from('accounts')) + .whereIn('username', connection.client!.select('id').from('accounts')) .toSQL() assert.equal(sql, knexSql) @@ -483,9 +486,9 @@ test.group('Query Builder | whereIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const ref = connection.getWriteClient().ref.bind(connection.getWriteClient()) + const ref = connection.client!.ref.bind(connection.client!) - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereIn('username', [ @@ -493,10 +496,10 @@ test.group('Query Builder | whereIn', (group) => { ]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereIn('username', [ - connection.getWriteClient().raw(`select ${ref('id')} from ${ref('accounts')}`), + connection.client!.raw(`select ${ref('id')} from ${ref('accounts')}`), ]) .toSQL() @@ -508,18 +511,18 @@ test.group('Query Builder | whereIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereIn( ['username', 'email'], - getQueryBuilder(connection).select('username', 'email').from('accounts'), + getQueryBuilder(connection.getClient()).select('username', 'email').from('accounts'), ) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .whereIn(['username', 'email'], connection.getWriteClient().select('username', 'email').from('accounts')) + .whereIn(['username', 'email'], connection.client!.select('username', 'email').from('accounts')) .toSQL() assert.equal(sql, knexSql) @@ -530,13 +533,13 @@ test.group('Query Builder | whereIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereIn(['username', 'email'], [['foo', 'bar']]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereIn(['username', 'email'], [['foo', 'bar']]) .toSQL() @@ -549,14 +552,14 @@ test.group('Query Builder | whereIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereIn('username', ['virk', 'nikk']) .orWhereIn('username', ['foo']) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereIn('username', ['virk', 'nikk']) .orWhereIn('username', ['foo']) @@ -570,7 +573,7 @@ test.group('Query Builder | whereIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereIn('username', (builder) => { @@ -581,7 +584,7 @@ test.group('Query Builder | whereIn', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereIn('username', (builder) => { builder.from('accounts') @@ -609,13 +612,13 @@ test.group('Query Builder | whereNotIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNotIn('username', ['virk', 'nikk']) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNotIn('username', ['virk', 'nikk']) .toSQL() @@ -628,7 +631,7 @@ test.group('Query Builder | whereNotIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNotIn('username', (builder) => { @@ -636,7 +639,7 @@ test.group('Query Builder | whereNotIn', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNotIn('username', (builder) => { builder.from('accounts') @@ -651,15 +654,15 @@ test.group('Query Builder | whereNotIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .whereNotIn('username', getQueryBuilder(connection).select('username').from('accounts')) + .whereNotIn('username', getQueryBuilder(connection.getClient()).select('username').from('accounts')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .whereNotIn('username', connection.getWriteClient().select('username').from('accounts')) + .whereNotIn('username', connection.client!.select('username').from('accounts')) .toSQL() assert.equal(sql, knexSql) @@ -670,13 +673,13 @@ test.group('Query Builder | whereNotIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNotIn(['username', 'email'], [['foo', 'bar']]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNotIn(['username', 'email'], [['foo', 'bar']]) .toSQL() @@ -689,14 +692,14 @@ test.group('Query Builder | whereNotIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNotIn('username', ['virk', 'nikk']) .orWhereNotIn('username', ['foo']) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNotIn('username', ['virk', 'nikk']) .orWhereNotIn('username', ['foo']) @@ -710,7 +713,7 @@ test.group('Query Builder | whereNotIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNotIn('username', (builder) => { @@ -721,7 +724,7 @@ test.group('Query Builder | whereNotIn', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNotIn('username', (builder) => { builder.from('accounts') @@ -749,13 +752,13 @@ test.group('Query Builder | whereNull', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNull('deleted_at') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNull('deleted_at') .toSQL() @@ -768,14 +771,14 @@ test.group('Query Builder | whereNull', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNull('deleted_at') .orWhereNull('updated_at') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNull('deleted_at') .orWhereNull('updated_at') @@ -799,13 +802,13 @@ test.group('Query Builder | whereNotNull', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNotNull('deleted_at') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNotNull('deleted_at') .toSQL() @@ -818,14 +821,14 @@ test.group('Query Builder | whereNotNull', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNotNull('deleted_at') .orWhereNotNull('updated_at') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNotNull('deleted_at') .orWhereNotNull('updated_at') @@ -849,7 +852,7 @@ test.group('Query Builder | whereExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereExists((builder) => { @@ -857,7 +860,7 @@ test.group('Query Builder | whereExists', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereExists((builder) => { builder.from('accounts') @@ -872,15 +875,15 @@ test.group('Query Builder | whereExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .whereExists(getQueryBuilder(connection).from('accounts')) + .whereExists(getQueryBuilder(connection.getClient()).from('accounts')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .whereExists(connection.getWriteClient().from('accounts')) + .whereExists(connection.client!.from('accounts')) .toSQL() assert.equal(sql, knexSql) @@ -891,7 +894,7 @@ test.group('Query Builder | whereExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .orWhereExists((builder) => { @@ -899,7 +902,7 @@ test.group('Query Builder | whereExists', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .orWhereExists((builder) => { builder.from('accounts') @@ -914,15 +917,15 @@ test.group('Query Builder | whereExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .orWhereExists(getQueryBuilder(connection).from('accounts')) + .orWhereExists(getQueryBuilder(connection.getClient()).from('accounts')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .orWhereExists(connection.getWriteClient().from('accounts')) + .orWhereExists(connection.client!.from('accounts')) .toSQL() assert.equal(sql, knexSql) @@ -943,7 +946,7 @@ test.group('Query Builder | whereNotExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNotExists((builder) => { @@ -951,7 +954,7 @@ test.group('Query Builder | whereNotExists', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNotExists((builder) => { builder.from('accounts') @@ -966,15 +969,15 @@ test.group('Query Builder | whereNotExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .whereNotExists(getQueryBuilder(connection).from('accounts')) + .whereNotExists(getQueryBuilder(connection.getClient()).from('accounts')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .whereNotExists(connection.getWriteClient().from('accounts')) + .whereNotExists(connection.client!.from('accounts')) .toSQL() assert.equal(sql, knexSql) @@ -985,7 +988,7 @@ test.group('Query Builder | whereNotExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .orWhereNotExists((builder) => { @@ -993,7 +996,7 @@ test.group('Query Builder | whereNotExists', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .orWhereNotExists((builder) => { builder.from('accounts') @@ -1008,15 +1011,15 @@ test.group('Query Builder | whereNotExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .orWhereNotExists(getQueryBuilder(connection).from('accounts')) + .orWhereNotExists(getQueryBuilder(connection.getClient()).from('accounts')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .orWhereNotExists(connection.getWriteClient().from('accounts')) + .orWhereNotExists(connection.client!.from('accounts')) .toSQL() assert.equal(sql, knexSql) @@ -1037,13 +1040,13 @@ test.group('Query Builder | whereBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereBetween('age', [18, 20]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereBetween('age', [18, 20]) .toSQL() @@ -1056,7 +1059,7 @@ test.group('Query Builder | whereBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereBetween('age', [ @@ -1065,11 +1068,11 @@ test.group('Query Builder | whereBetween', (group) => { ]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereBetween('age', [ - connection.getWriteClient().raw('select min_age from ages;'), - connection.getWriteClient().raw('select max_age from ages;'), + connection.client!.raw('select min_age from ages;'), + connection.client!.raw('select max_age from ages;'), ]) .toSQL() @@ -1081,13 +1084,13 @@ test.group('Query Builder | whereBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .orWhereBetween('age', [18, 20]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .orWhereBetween('age', [18, 20]) .toSQL() @@ -1100,7 +1103,7 @@ test.group('Query Builder | whereBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .orWhereBetween('age', [ @@ -1109,11 +1112,11 @@ test.group('Query Builder | whereBetween', (group) => { ]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .orWhereBetween('age', [ - connection.getWriteClient().raw('select min_age from ages;'), - connection.getWriteClient().raw('select max_age from ages;'), + connection.client!.raw('select min_age from ages;'), + connection.client!.raw('select max_age from ages;'), ]) .toSQL() @@ -1135,13 +1138,13 @@ test.group('Query Builder | whereNotBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNotBetween('age', [18, 20]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNotBetween('age', [18, 20]) .toSQL() @@ -1154,7 +1157,7 @@ test.group('Query Builder | whereNotBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereNotBetween('age', [ @@ -1163,11 +1166,11 @@ test.group('Query Builder | whereNotBetween', (group) => { ]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereNotBetween('age', [ - connection.getWriteClient().raw('select min_age from ages;'), - connection.getWriteClient().raw('select max_age from ages;'), + connection.client!.raw('select min_age from ages;'), + connection.client!.raw('select max_age from ages;'), ]) .toSQL() @@ -1179,13 +1182,13 @@ test.group('Query Builder | whereNotBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .orWhereNotBetween('age', [18, 20]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .orWhereNotBetween('age', [18, 20]) .toSQL() @@ -1198,7 +1201,7 @@ test.group('Query Builder | whereNotBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .orWhereNotBetween('age', [ @@ -1207,11 +1210,11 @@ test.group('Query Builder | whereNotBetween', (group) => { ]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .orWhereNotBetween('age', [ - connection.getWriteClient().raw('select min_age from ages;'), - connection.getWriteClient().raw('select max_age from ages;'), + connection.client!.raw('select min_age from ages;'), + connection.client!.raw('select max_age from ages;'), ]) .toSQL() @@ -1233,13 +1236,13 @@ test.group('Query Builder | whereRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereRaw('id = ?', [1]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereRaw('id = ?', [1]) .toSQL() @@ -1252,13 +1255,13 @@ test.group('Query Builder | whereRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereRaw('id = 1') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereRaw('id = 1') .toSQL() @@ -1271,13 +1274,13 @@ test.group('Query Builder | whereRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereRaw('id = :id', { id: 1 }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereRaw('id = :id', { id: 1 }) .toSQL() @@ -1290,15 +1293,15 @@ test.group('Query Builder | whereRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereRaw(getRawQueryBuilder(connection, 'select id from accounts;')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .whereRaw(connection.getWriteClient().raw('select id from accounts;')) + .whereRaw(connection.client!.raw('select id from accounts;')) .toSQL() assert.equal(sql, knexSql) @@ -1309,14 +1312,14 @@ test.group('Query Builder | whereRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .whereRaw('id = ?', [1]) .orWhereRaw('id = ?', [2]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .whereRaw('id = ?', [1]) .orWhereRaw('id = ?', [2]) @@ -1340,13 +1343,13 @@ test.group('Query Builder | join', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .join('profiles', 'users.id', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .join('profiles', 'users.id', 'profiles.user_id') .toSQL() @@ -1359,13 +1362,13 @@ test.group('Query Builder | join', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .join('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .join('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() @@ -1378,7 +1381,7 @@ test.group('Query Builder | join', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .join('profiles', (builder) => { @@ -1386,7 +1389,7 @@ test.group('Query Builder | join', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .join('profiles', (builder) => { builder.on('users.id', 'profiles.user_id') @@ -1401,15 +1404,15 @@ test.group('Query Builder | join', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .join('profiles', 'profiles.type', getRawQueryBuilder(connection, '?', ['social'])) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .join('profiles', 'profiles.type', connection.getWriteClient().raw('?', ['social'])) + .join('profiles', 'profiles.type', connection.client!.raw('?', ['social'])) .toSQL() assert.equal(sql, knexSql) @@ -1430,13 +1433,13 @@ test.group('Query Builder | innerJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .innerJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .innerJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() @@ -1449,13 +1452,13 @@ test.group('Query Builder | innerJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .innerJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .innerJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() @@ -1468,7 +1471,7 @@ test.group('Query Builder | innerJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .innerJoin('profiles', (builder) => { @@ -1476,7 +1479,7 @@ test.group('Query Builder | innerJoin', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .innerJoin('profiles', (builder) => { builder.on('users.id', 'profiles.user_id') @@ -1491,15 +1494,15 @@ test.group('Query Builder | innerJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .innerJoin('profiles', 'profiles.type', getRawQueryBuilder(connection, '?', ['social'])) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .innerJoin('profiles', 'profiles.type', connection.getWriteClient().raw('?', ['social'])) + .innerJoin('profiles', 'profiles.type', connection.client!.raw('?', ['social'])) .toSQL() assert.equal(sql, knexSql) @@ -1520,13 +1523,13 @@ test.group('Query Builder | leftJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .leftJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .leftJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() @@ -1539,13 +1542,13 @@ test.group('Query Builder | leftJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .leftJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .leftJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() @@ -1558,7 +1561,7 @@ test.group('Query Builder | leftJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .leftJoin('profiles', (builder) => { @@ -1566,7 +1569,7 @@ test.group('Query Builder | leftJoin', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .leftJoin('profiles', (builder) => { builder.on('users.id', 'profiles.user_id') @@ -1581,15 +1584,15 @@ test.group('Query Builder | leftJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .leftJoin('profiles', 'profiles.type', getRawQueryBuilder(connection, '?', ['social'])) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .leftJoin('profiles', 'profiles.type', connection.getWriteClient().raw('?', ['social'])) + .leftJoin('profiles', 'profiles.type', connection.client!.raw('?', ['social'])) .toSQL() assert.equal(sql, knexSql) @@ -1610,13 +1613,13 @@ test.group('Query Builder | leftOuterJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .leftOuterJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .leftOuterJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() @@ -1629,13 +1632,13 @@ test.group('Query Builder | leftOuterJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .leftOuterJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .leftOuterJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() @@ -1648,7 +1651,7 @@ test.group('Query Builder | leftOuterJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .leftOuterJoin('profiles', (builder) => { @@ -1656,7 +1659,7 @@ test.group('Query Builder | leftOuterJoin', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .leftOuterJoin('profiles', (builder) => { builder.on('users.id', 'profiles.user_id') @@ -1671,15 +1674,15 @@ test.group('Query Builder | leftOuterJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .leftOuterJoin('profiles', 'profiles.type', getRawQueryBuilder(connection, '?', ['social'])) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .leftOuterJoin('profiles', 'profiles.type', connection.getWriteClient().raw('?', ['social'])) + .leftOuterJoin('profiles', 'profiles.type', connection.client!.raw('?', ['social'])) .toSQL() assert.equal(sql, knexSql) @@ -1700,13 +1703,13 @@ test.group('Query Builder | rightJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .rightJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .rightJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() @@ -1719,13 +1722,13 @@ test.group('Query Builder | rightJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .rightJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .rightJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() @@ -1738,7 +1741,7 @@ test.group('Query Builder | rightJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .rightJoin('profiles', (builder) => { @@ -1746,7 +1749,7 @@ test.group('Query Builder | rightJoin', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .rightJoin('profiles', (builder) => { builder.on('users.id', 'profiles.user_id') @@ -1761,15 +1764,15 @@ test.group('Query Builder | rightJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .rightJoin('profiles', 'profiles.type', getRawQueryBuilder(connection, '?', ['social'])) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .rightJoin('profiles', 'profiles.type', connection.getWriteClient().raw('?', ['social'])) + .rightJoin('profiles', 'profiles.type', connection.client!.raw('?', ['social'])) .toSQL() assert.equal(sql, knexSql) @@ -1790,13 +1793,13 @@ test.group('Query Builder | rightOuterJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .rightOuterJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .rightOuterJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() @@ -1809,13 +1812,13 @@ test.group('Query Builder | rightOuterJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .rightOuterJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .rightOuterJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() @@ -1828,7 +1831,7 @@ test.group('Query Builder | rightOuterJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .rightOuterJoin('profiles', (builder) => { @@ -1836,7 +1839,7 @@ test.group('Query Builder | rightOuterJoin', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .rightOuterJoin('profiles', (builder) => { builder.on('users.id', 'profiles.user_id') @@ -1851,15 +1854,15 @@ test.group('Query Builder | rightOuterJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .rightOuterJoin('profiles', 'profiles.type', getRawQueryBuilder(connection, '?', ['social'])) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .rightOuterJoin('profiles', 'profiles.type', connection.getWriteClient().raw('?', ['social'])) + .rightOuterJoin('profiles', 'profiles.type', connection.client!.raw('?', ['social'])) .toSQL() assert.equal(sql, knexSql) @@ -1880,13 +1883,13 @@ test.group('Query Builder | fullOuterJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .fullOuterJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .fullOuterJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() @@ -1899,13 +1902,13 @@ test.group('Query Builder | fullOuterJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .fullOuterJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .fullOuterJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() @@ -1918,7 +1921,7 @@ test.group('Query Builder | fullOuterJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .fullOuterJoin('profiles', (builder) => { @@ -1926,7 +1929,7 @@ test.group('Query Builder | fullOuterJoin', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .fullOuterJoin('profiles', (builder) => { builder.on('users.id', 'profiles.user_id') @@ -1941,15 +1944,15 @@ test.group('Query Builder | fullOuterJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .fullOuterJoin('profiles', 'profiles.type', getRawQueryBuilder(connection, '?', ['social'])) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .fullOuterJoin('profiles', 'profiles.type', connection.getWriteClient().raw('?', ['social'])) + .fullOuterJoin('profiles', 'profiles.type', connection.client!.raw('?', ['social'])) .toSQL() assert.equal(sql, knexSql) @@ -1970,13 +1973,13 @@ test.group('Query Builder | crossJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .crossJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .crossJoin('profiles', 'users.id', 'profiles.user_id') .toSQL() @@ -1989,13 +1992,13 @@ test.group('Query Builder | crossJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .crossJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .crossJoin('profiles', 'users.id', '!=', 'profiles.user_id') .toSQL() @@ -2008,7 +2011,7 @@ test.group('Query Builder | crossJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .crossJoin('profiles', (builder) => { @@ -2016,7 +2019,7 @@ test.group('Query Builder | crossJoin', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .crossJoin('profiles', (builder) => { builder.on('users.id', 'profiles.user_id') @@ -2031,15 +2034,15 @@ test.group('Query Builder | crossJoin', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .crossJoin('profiles', 'profiles.type', getRawQueryBuilder(connection, '?', ['social'])) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .crossJoin('profiles', 'profiles.type', connection.getWriteClient().raw('?', ['social'])) + .crossJoin('profiles', 'profiles.type', connection.client!.raw('?', ['social'])) .toSQL() assert.equal(sql, knexSql) @@ -2060,13 +2063,13 @@ test.group('Query Builder | joinRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .joinRaw('natural full join table1') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .joinRaw('natural full join table1') .toSQL() @@ -2079,13 +2082,13 @@ test.group('Query Builder | joinRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .joinRaw(getRawQueryBuilder(connection, 'natural full join table1')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .joinRaw('natural full join table1') .toSQL() @@ -2108,13 +2111,13 @@ test.group('Query Builder | distinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .distinct('name', 'age') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .distinct('name', 'age') .toSQL() @@ -2137,13 +2140,13 @@ test.group('Query Builder | groupBy', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .groupBy('name', 'age') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .groupBy('name', 'age') .toSQL() @@ -2166,13 +2169,13 @@ test.group('Query Builder | groupByRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .groupByRaw('select (age) from user_profiles') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .groupByRaw('select (age) from user_profiles') .toSQL() @@ -2195,13 +2198,13 @@ test.group('Query Builder | orderBy', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .orderBy('name') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .orderBy('name') .toSQL() @@ -2214,13 +2217,13 @@ test.group('Query Builder | orderBy', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .orderBy('name', 'desc') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .orderBy('name', 'desc') .toSQL() @@ -2233,13 +2236,13 @@ test.group('Query Builder | orderBy', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .orderBy([{ column: 'name', order: 'desc' }, { column: 'age', order: 'desc' }]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .orderBy([{ column: 'name', order: 'desc' }, { column: 'age', order: 'desc' }]) .toSQL() @@ -2262,13 +2265,13 @@ test.group('Query Builder | orderByRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .orderByRaw('col DESC NULLS LAST') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .orderByRaw('col DESC NULLS LAST') .toSQL() @@ -2291,13 +2294,13 @@ test.group('Query Builder | offset', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .offset(10) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .offset(10) .toSQL() @@ -2320,13 +2323,13 @@ test.group('Query Builder | limit', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .limit(10) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .limit(10) .toSQL() @@ -2349,7 +2352,7 @@ test.group('Query Builder | union', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .union((builder) => { @@ -2357,7 +2360,7 @@ test.group('Query Builder | union', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .union((builder) => { builder.select('*').from('users').whereNull('first_name') @@ -2372,15 +2375,15 @@ test.group('Query Builder | union', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .union(getQueryBuilder(connection).from('users').whereNull('first_name')) + .union(getQueryBuilder(connection.getClient()).from('users').whereNull('first_name')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .union(connection.getWriteClient().from('users').whereNull('first_name')) + .union(connection.client!.from('users').whereNull('first_name')) .toSQL() assert.equal(sql, knexSql) @@ -2391,15 +2394,15 @@ test.group('Query Builder | union', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .union(getRawQueryBuilder(connection, 'select * from users where first_name is null')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .union(connection.getWriteClient().raw('select * from users where first_name is null')) + .union(connection.client!.raw('select * from users where first_name is null')) .toSQL() assert.equal(sql, knexSql) @@ -2410,7 +2413,7 @@ test.group('Query Builder | union', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .union([(builder) => { @@ -2418,7 +2421,7 @@ test.group('Query Builder | union', (group) => { }]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .union([(builder) => { builder.select('*').from('users').whereNull('first_name') @@ -2433,15 +2436,15 @@ test.group('Query Builder | union', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .union([getQueryBuilder(connection).from('users').whereNull('first_name')]) + .union([getQueryBuilder(connection.getClient()).from('users').whereNull('first_name')]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .union([connection.getWriteClient().from('users').whereNull('first_name')]) + .union([connection.client!.from('users').whereNull('first_name')]) .toSQL() assert.equal(sql, knexSql) @@ -2452,15 +2455,15 @@ test.group('Query Builder | union', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .union([getRawQueryBuilder(connection, 'select * from users where first_name is null')]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .union([connection.getWriteClient().raw('select * from users where first_name is null')]) + .union([connection.client!.raw('select * from users where first_name is null')]) .toSQL() assert.equal(sql, knexSql) @@ -2481,7 +2484,7 @@ test.group('Query Builder | unionAll', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .unionAll((builder) => { @@ -2489,7 +2492,7 @@ test.group('Query Builder | unionAll', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .unionAll((builder) => { builder.select('*').from('users').whereNull('first_name') @@ -2504,15 +2507,15 @@ test.group('Query Builder | unionAll', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .unionAll(getQueryBuilder(connection).from('users').whereNull('first_name')) + .unionAll(getQueryBuilder(connection.getClient()).from('users').whereNull('first_name')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .unionAll(connection.getWriteClient().from('users').whereNull('first_name')) + .unionAll(connection.client!.from('users').whereNull('first_name')) .toSQL() assert.equal(sql, knexSql) @@ -2523,15 +2526,15 @@ test.group('Query Builder | unionAll', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .unionAll(getRawQueryBuilder(connection, 'select * from users where first_name is null')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .unionAll(connection.getWriteClient().raw('select * from users where first_name is null')) + .unionAll(connection.client!.raw('select * from users where first_name is null')) .toSQL() assert.equal(sql, knexSql) @@ -2542,7 +2545,7 @@ test.group('Query Builder | unionAll', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .unionAll([(builder) => { @@ -2550,7 +2553,7 @@ test.group('Query Builder | unionAll', (group) => { }]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .unionAll([(builder) => { builder.select('*').from('users').whereNull('first_name') @@ -2565,15 +2568,15 @@ test.group('Query Builder | unionAll', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .unionAll([getQueryBuilder(connection).from('users').whereNull('first_name')]) + .unionAll([getQueryBuilder(connection.getClient()).from('users').whereNull('first_name')]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .unionAll([connection.getWriteClient().from('users').whereNull('first_name')]) + .unionAll([connection.client!.from('users').whereNull('first_name')]) .toSQL() assert.equal(sql, knexSql) @@ -2584,15 +2587,15 @@ test.group('Query Builder | unionAll', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .unionAll([getRawQueryBuilder(connection, 'select * from users where first_name is null')]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .unionAll([connection.getWriteClient().raw('select * from users where first_name is null')]) + .unionAll([connection.client!.raw('select * from users where first_name is null')]) .toSQL() assert.equal(sql, knexSql) @@ -2613,13 +2616,13 @@ test.group('Query Builder | forUpdate', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .forUpdate() .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .forUpdate() .toSQL() @@ -2632,13 +2635,13 @@ test.group('Query Builder | forUpdate', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .forUpdate('profiles') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .forUpdate('profiles') .toSQL() @@ -2661,13 +2664,13 @@ test.group('Query Builder | forShare', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .forShare() .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .forShare() .toSQL() @@ -2680,13 +2683,13 @@ test.group('Query Builder | forShare', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .forShare('profiles') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .forShare('profiles') .toSQL() @@ -2710,14 +2713,14 @@ if (['pg', 'mysql'].includes(process.env.DB!)) { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .forShare() .noWait() .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .forShare() .noWait() @@ -2741,14 +2744,14 @@ if (['pg', 'mysql'].includes(process.env.DB!)) { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .forShare() .skipLocked() .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .forShare() .skipLocked() @@ -2773,13 +2776,13 @@ test.group('Query Builder | having', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .having('count', '>', 10) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .having('count', '>', 10) .toSQL() @@ -2792,7 +2795,7 @@ test.group('Query Builder | having', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .having((builder) => { @@ -2800,7 +2803,7 @@ test.group('Query Builder | having', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .having((builder) => { builder.where('id', '>', 10) @@ -2814,9 +2817,9 @@ test.group('Query Builder | having', (group) => { test('add having clause value being a raw query', (assert) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const ref = connection.getWriteClient().ref.bind(connection.getWriteClient()) + const ref = connection.client!.ref.bind(connection.client!) - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .having( @@ -2826,12 +2829,12 @@ test.group('Query Builder | having', (group) => { ) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .having( 'user_id', '=', - connection.getWriteClient().raw(`(select ${ref('user_id')} from ${ref('accounts')})`), + connection.client!.raw(`(select ${ref('user_id')} from ${ref('accounts')})`), ) .toSQL() @@ -2843,22 +2846,22 @@ test.group('Query Builder | having', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .having( 'user_id', '=', - getQueryBuilder(connection).from('accounts').select('id'), + getQueryBuilder(connection.getClient()).from('accounts').select('id'), ) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .having( 'user_id', '=', - connection.getWriteClient().select('id').from('accounts'), + connection.client!.select('id').from('accounts'), ) .toSQL() @@ -2870,15 +2873,15 @@ test.group('Query Builder | having', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingRaw(getRawQueryBuilder(connection, 'sum(likes) > ?', [200])) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .having(connection.getWriteClient().raw('sum(likes) > ?', [200])) + .having(connection.client!.raw('sum(likes) > ?', [200])) .toSQL() assert.equal(sql, knexSql) @@ -2889,14 +2892,14 @@ test.group('Query Builder | having', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .having('count', '>', 10) .orHaving('total', '>', 10) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .having('count', '>', 10) .orHaving('total', '>', 10) @@ -2920,13 +2923,13 @@ test.group('Query Builder | havingIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingIn('id', [10, 20]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingIn('id', [10, 20]) .toSQL() @@ -2939,15 +2942,15 @@ test.group('Query Builder | havingIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .havingIn('id', [getQueryBuilder(connection).select('id').from('accounts')]) + .havingIn('id', [getQueryBuilder(connection.getClient()).select('id').from('accounts')]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .havingIn('id', [connection.getWriteClient().select('id').from('accounts') as any]) + .havingIn('id', [connection.client!.select('id').from('accounts') as any]) .toSQL() assert.equal(sql, knexSql) @@ -2958,15 +2961,15 @@ test.group('Query Builder | havingIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingIn('id', [getRawQueryBuilder(connection, 'select id from accounts')]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .havingIn('id', [connection.getWriteClient().raw('select id from accounts')]) + .havingIn('id', [connection.client!.raw('select id from accounts')]) .toSQL() assert.equal(sql, knexSql) @@ -2981,13 +2984,13 @@ test.group('Query Builder | havingIn', (group) => { builder.select('id').from('accounts') } - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingIn('id', fn) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingIn('id', fn as any) .toSQL() @@ -3000,14 +3003,14 @@ test.group('Query Builder | havingIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingIn('id', [10, 20]) .orHavingIn('id', [10, 30]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingIn('id', [10, 20]) ['orHavingIn']('id', [10, 30]) @@ -3031,13 +3034,13 @@ test.group('Query Builder | havingNotIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNotIn('id', [10, 20]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') ['havingNotIn']('id', [10, 20]) .toSQL() @@ -3050,15 +3053,15 @@ test.group('Query Builder | havingNotIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .havingNotIn('id', [getQueryBuilder(connection).select('id').from('accounts')]) + .havingNotIn('id', [getQueryBuilder(connection.getClient()).select('id').from('accounts')]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - ['havingNotIn']('id', [connection.getWriteClient().select('id').from('accounts') as any]) + ['havingNotIn']('id', [connection.client!.select('id').from('accounts') as any]) .toSQL() assert.equal(sql, knexSql) @@ -3069,15 +3072,15 @@ test.group('Query Builder | havingNotIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNotIn('id', [getRawQueryBuilder(connection, 'select id from accounts')]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - ['havingNotIn']('id', [connection.getWriteClient().raw('select id from accounts')]) + ['havingNotIn']('id', [connection.client!.raw('select id from accounts')]) .toSQL() assert.equal(sql, knexSql) @@ -3092,13 +3095,13 @@ test.group('Query Builder | havingNotIn', (group) => { builder.select('id').from('accounts') } - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNotIn('id', fn) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') ['havingNotIn']('id', fn as any) .toSQL() @@ -3111,14 +3114,14 @@ test.group('Query Builder | havingNotIn', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNotIn('id', [10, 20]) .orHavingNotIn('id', [10, 30]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') ['havingNotIn']('id', [10, 20]) ['orHavingNotIn']('id', [10, 30]) @@ -3142,13 +3145,13 @@ test.group('Query Builder | havingNull', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNull('deleted_at') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') ['havingNull']('deleted_at') .toSQL() @@ -3161,14 +3164,14 @@ test.group('Query Builder | havingNull', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNull('deleted_at') .orHavingNull('updated_at') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') ['havingNull']('deleted_at') .orHavingNull('updated_at') @@ -3192,13 +3195,13 @@ test.group('Query Builder | havingNotNull', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNotNull('deleted_at') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') ['havingNotNull']('deleted_at') .toSQL() @@ -3211,14 +3214,14 @@ test.group('Query Builder | havingNotNull', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNotNull('deleted_at') .orHavingNotNull('updated_at') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') ['havingNotNull']('deleted_at') .orHavingNotNull('updated_at') @@ -3242,7 +3245,7 @@ test.group('Query Builder | havingExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingExists((builder) => { @@ -3250,7 +3253,7 @@ test.group('Query Builder | havingExists', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') ['havingExists']((builder) => { builder.select('*').from('accounts').whereRaw('users.account_id = accounts.id') @@ -3265,15 +3268,15 @@ test.group('Query Builder | havingExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .havingExists(getQueryBuilder(connection).select('*').from('accounts')) + .havingExists(getQueryBuilder(connection.getClient()).select('*').from('accounts')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - ['havingExists'](connection.getWriteClient().select('*').from('accounts')) + ['havingExists'](connection.client!.select('*').from('accounts')) .toSQL() assert.equal(sql, knexSql) @@ -3284,7 +3287,7 @@ test.group('Query Builder | havingExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingExists((builder) => { @@ -3295,7 +3298,7 @@ test.group('Query Builder | havingExists', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') ['havingExists']((builder) => { builder.select('*').from('accounts') @@ -3323,7 +3326,7 @@ test.group('Query Builder | havingNotExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNotExists((builder) => { @@ -3331,7 +3334,7 @@ test.group('Query Builder | havingNotExists', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') ['havingNotExists']((builder) => { builder.select('*').from('accounts').whereRaw('users.account_id = accounts.id') @@ -3346,15 +3349,15 @@ test.group('Query Builder | havingNotExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .havingNotExists(getQueryBuilder(connection).select('*').from('accounts')) + .havingNotExists(getQueryBuilder(connection.getClient()).select('*').from('accounts')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - ['havingNotExists'](connection.getWriteClient().select('*').from('accounts')) + ['havingNotExists'](connection.client!.select('*').from('accounts')) .toSQL() assert.equal(sql, knexSql) @@ -3365,7 +3368,7 @@ test.group('Query Builder | havingNotExists', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNotExists((builder) => { @@ -3376,7 +3379,7 @@ test.group('Query Builder | havingNotExists', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') ['havingNotExists']((builder) => { builder.select('*').from('accounts') @@ -3404,13 +3407,13 @@ test.group('Query Builder | havingBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingBetween('id', [5, 10]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingBetween('id', [5, 10]) .toSQL() @@ -3423,7 +3426,7 @@ test.group('Query Builder | havingBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingBetween('id', [ @@ -3432,11 +3435,11 @@ test.group('Query Builder | havingBetween', (group) => { ]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingBetween('id', [ - connection.getWriteClient().raw('select min(id) from users;'), - connection.getWriteClient().raw('select max(id) from users;'), + connection.client!.raw('select min(id) from users;'), + connection.client!.raw('select max(id) from users;'), ]) .toSQL() @@ -3448,20 +3451,20 @@ test.group('Query Builder | havingBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingBetween('id', [ - getQueryBuilder(connection).select('id'), - getQueryBuilder(connection).select('id'), + getQueryBuilder(connection.getClient()).select('id'), + getQueryBuilder(connection.getClient()).select('id'), ]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingBetween('id', [ - connection.getWriteClient().select('id') as any, - connection.getWriteClient().select('id') as any, + connection.client!.select('id') as any, + connection.client!.select('id') as any, ]) .toSQL() @@ -3473,14 +3476,14 @@ test.group('Query Builder | havingBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingBetween('id', [5, 10]) .orHavingBetween('id', [18, 23]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingBetween('id', [5, 10]) .orHavingBetween('id', [18, 23]) @@ -3504,13 +3507,13 @@ test.group('Query Builder | havingNotBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNotBetween('id', [5, 10]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingNotBetween('id', [5, 10]) .toSQL() @@ -3523,7 +3526,7 @@ test.group('Query Builder | havingNotBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNotBetween('id', [ @@ -3532,11 +3535,11 @@ test.group('Query Builder | havingNotBetween', (group) => { ]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingNotBetween('id', [ - connection.getWriteClient().raw('select min(id) from users;'), - connection.getWriteClient().raw('select max(id) from users;'), + connection.client!.raw('select min(id) from users;'), + connection.client!.raw('select max(id) from users;'), ]) .toSQL() @@ -3548,20 +3551,20 @@ test.group('Query Builder | havingNotBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNotBetween('id', [ - getQueryBuilder(connection).select('id'), - getQueryBuilder(connection).select('id'), + getQueryBuilder(connection.getClient()).select('id'), + getQueryBuilder(connection.getClient()).select('id'), ]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingNotBetween('id', [ - connection.getWriteClient().select('id') as any, - connection.getWriteClient().select('id') as any, + connection.client!.select('id') as any, + connection.client!.select('id') as any, ]) .toSQL() @@ -3573,14 +3576,14 @@ test.group('Query Builder | havingNotBetween', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingNotBetween('id', [5, 10]) .orHavingNotBetween('id', [18, 23]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingNotBetween('id', [5, 10]) .orHavingNotBetween('id', [18, 23]) @@ -3604,13 +3607,13 @@ test.group('Query Builder | havingRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingRaw('id = ?', [1]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingRaw('id = ?', [1]) .toSQL() @@ -3623,13 +3626,13 @@ test.group('Query Builder | havingRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingRaw('id = 1') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingRaw('id = 1') .toSQL() @@ -3642,13 +3645,13 @@ test.group('Query Builder | havingRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingRaw('id = :id', { id: 1 }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingRaw('id = :id', { id: 1 }) .toSQL() @@ -3661,15 +3664,15 @@ test.group('Query Builder | havingRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingRaw(getRawQueryBuilder(connection, 'select id from accounts;')) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .havingRaw(connection.getWriteClient().raw('select id from accounts;')) + .havingRaw(connection.client!.raw('select id from accounts;')) .toSQL() assert.equal(sql, knexSql) @@ -3680,14 +3683,14 @@ test.group('Query Builder | havingRaw', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .havingRaw('id = ?', [1]) .orHavingRaw('id = ?', [2]) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .havingRaw('id = ?', [1]) .orHavingRaw('id = ?', [2]) @@ -3711,14 +3714,14 @@ test.group('Query Builder | clearSelect', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .select('id', 'username') .clearSelect() .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .select('id', 'username') .clearSelect() @@ -3742,14 +3745,14 @@ test.group('Query Builder | clearWhere', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .where('username', 'virk') .clearWhere() .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .where('username', 'virk') .clearWhere() @@ -3773,14 +3776,14 @@ test.group('Query Builder | clearOrder', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .orderBy('id', 'desc') .clearOrder() .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .orderBy('id', 'desc') .clearOrder() @@ -3804,14 +3807,14 @@ test.group('Query Builder | clearHaving', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .having('id', '>', 10) .clearHaving() .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .having('id', '>', 10) .clearHaving() @@ -3835,13 +3838,13 @@ test.group('Query Builder | count', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .count('*', 'total') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .count('*', { as: 'total' }) .toSQL() @@ -3854,13 +3857,13 @@ test.group('Query Builder | count', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .count({ u: 'username', e: 'email' }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .count({ u: 'username', e: 'email' }) .toSQL() @@ -3873,16 +3876,16 @@ test.group('Query Builder | count', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .count(getRawQueryBuilder(connection, 'select * from profiles where is_verified = ?', [true]), 'u') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .count({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), }) .toSQL() @@ -3894,16 +3897,16 @@ test.group('Query Builder | count', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .count(getQueryBuilder(connection).where('is_verified', true).from('profiles'), 'u') + .count(getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), 'u') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .count({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), }) .toSQL() @@ -3915,7 +3918,7 @@ test.group('Query Builder | count', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .count({ @@ -3924,10 +3927,10 @@ test.group('Query Builder | count', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .count({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), e: 'email', }) .toSQL() @@ -3940,19 +3943,19 @@ test.group('Query Builder | count', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .count({ - u: getQueryBuilder(connection).where('is_verified', true).from('profiles'), + u: getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .count({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() @@ -3975,13 +3978,13 @@ test.group('Query Builder | countDistinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .countDistinct('*', 'total') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .countDistinct('*', { as: 'total' }) .toSQL() @@ -3994,13 +3997,13 @@ test.group('Query Builder | countDistinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .countDistinct({ u: 'username', e: 'email' }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .countDistinct({ u: 'username', e: 'email' }) .toSQL() @@ -4013,7 +4016,7 @@ test.group('Query Builder | countDistinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .countDistinct( @@ -4022,10 +4025,10 @@ test.group('Query Builder | countDistinct', (group) => { ) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .countDistinct({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), }) .toSQL() @@ -4037,16 +4040,16 @@ test.group('Query Builder | countDistinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .countDistinct(getQueryBuilder(connection).where('is_verified', true).from('profiles'), 'u') + .countDistinct(getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), 'u') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .countDistinct({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), }) .toSQL() @@ -4058,7 +4061,7 @@ test.group('Query Builder | countDistinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .countDistinct({ @@ -4067,10 +4070,10 @@ test.group('Query Builder | countDistinct', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .countDistinct({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), e: 'email', }) .toSQL() @@ -4083,19 +4086,19 @@ test.group('Query Builder | countDistinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .countDistinct({ - u: getQueryBuilder(connection).where('is_verified', true).from('profiles'), + u: getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .countDistinct({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() @@ -4118,13 +4121,13 @@ test.group('Query Builder | min', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .min('*', 'smallest') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .min('*', { as: 'smallest' }) .toSQL() @@ -4137,13 +4140,13 @@ test.group('Query Builder | min', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .min({ u: 'username', e: 'email' }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .min({ u: 'username', e: 'email' }) .toSQL() @@ -4156,7 +4159,7 @@ test.group('Query Builder | min', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .min( @@ -4165,10 +4168,10 @@ test.group('Query Builder | min', (group) => { ) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .min({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), }) .toSQL() @@ -4180,16 +4183,16 @@ test.group('Query Builder | min', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .min(getQueryBuilder(connection).where('is_verified', true).from('profiles'), 'u') + .min(getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), 'u') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .min({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), }) .toSQL() @@ -4201,7 +4204,7 @@ test.group('Query Builder | min', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .min({ @@ -4210,10 +4213,10 @@ test.group('Query Builder | min', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .min({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), e: 'email', }) .toSQL() @@ -4226,19 +4229,19 @@ test.group('Query Builder | min', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .min({ - u: getQueryBuilder(connection).where('is_verified', true).from('profiles'), + u: getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .min({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() @@ -4261,13 +4264,13 @@ test.group('Query Builder | max', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .max('*', 'biggest') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .max('*', { as: 'biggest' }) .toSQL() @@ -4280,13 +4283,13 @@ test.group('Query Builder | max', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .max({ u: 'username', e: 'email' }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .max({ u: 'username', e: 'email' }) .toSQL() @@ -4299,7 +4302,7 @@ test.group('Query Builder | max', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .max( @@ -4308,10 +4311,10 @@ test.group('Query Builder | max', (group) => { ) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .max({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), }) .toSQL() @@ -4323,16 +4326,16 @@ test.group('Query Builder | max', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .max(getQueryBuilder(connection).where('is_verified', true).from('profiles'), 'u') + .max(getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), 'u') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .max({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), }) .toSQL() @@ -4344,7 +4347,7 @@ test.group('Query Builder | max', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .max({ @@ -4353,10 +4356,10 @@ test.group('Query Builder | max', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .max({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), e: 'email', }) .toSQL() @@ -4369,19 +4372,19 @@ test.group('Query Builder | max', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .max({ - u: getQueryBuilder(connection).where('is_verified', true).from('profiles'), + u: getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .max({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() @@ -4404,13 +4407,13 @@ test.group('Query Builder | sum', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .sum('*', 'total') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .sum('*', { as: 'total' }) .toSQL() @@ -4423,13 +4426,13 @@ test.group('Query Builder | sum', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .sum({ u: 'username', e: 'email' }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .sum({ u: 'username', e: 'email' }) .toSQL() @@ -4442,7 +4445,7 @@ test.group('Query Builder | sum', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .sum( @@ -4451,10 +4454,10 @@ test.group('Query Builder | sum', (group) => { ) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .sum({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), }) .toSQL() @@ -4466,16 +4469,16 @@ test.group('Query Builder | sum', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .sum(getQueryBuilder(connection).where('is_verified', true).from('profiles'), 'u') + .sum(getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), 'u') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .sum({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), }) .toSQL() @@ -4487,7 +4490,7 @@ test.group('Query Builder | sum', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .sum({ @@ -4496,10 +4499,10 @@ test.group('Query Builder | sum', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .sum({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), e: 'email', }) .toSQL() @@ -4512,19 +4515,19 @@ test.group('Query Builder | sum', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .sum({ - u: getQueryBuilder(connection).where('is_verified', true).from('profiles'), + u: getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .sum({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() @@ -4547,13 +4550,13 @@ test.group('Query Builder | avg', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .avg('*', 'avg') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .avg('*', { as: 'avg' }) .toSQL() @@ -4566,13 +4569,13 @@ test.group('Query Builder | avg', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .avg({ u: 'username', e: 'email' }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .avg({ u: 'username', e: 'email' }) .toSQL() @@ -4585,7 +4588,7 @@ test.group('Query Builder | avg', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .avg( @@ -4594,10 +4597,10 @@ test.group('Query Builder | avg', (group) => { ) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .avg({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), }) .toSQL() @@ -4609,16 +4612,16 @@ test.group('Query Builder | avg', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .avg(getQueryBuilder(connection).where('is_verified', true).from('profiles'), 'u') + .avg(getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), 'u') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .avg({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), }) .toSQL() @@ -4630,7 +4633,7 @@ test.group('Query Builder | avg', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .avg({ @@ -4639,10 +4642,10 @@ test.group('Query Builder | avg', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .avg({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), e: 'email', }) .toSQL() @@ -4655,19 +4658,19 @@ test.group('Query Builder | avg', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .avg({ - u: getQueryBuilder(connection).where('is_verified', true).from('profiles'), + u: getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .avg({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() @@ -4690,13 +4693,13 @@ test.group('Query Builder | avgDistinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .avgDistinct('*', 'avgDistinct') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .avgDistinct('*', { as: 'avgDistinct' }) .toSQL() @@ -4709,13 +4712,13 @@ test.group('Query Builder | avgDistinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .avgDistinct({ u: 'username', e: 'email' }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .avgDistinct({ u: 'username', e: 'email' }) .toSQL() @@ -4728,7 +4731,7 @@ test.group('Query Builder | avgDistinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .avgDistinct( @@ -4737,10 +4740,10 @@ test.group('Query Builder | avgDistinct', (group) => { ) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .avgDistinct({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), }) .toSQL() @@ -4752,16 +4755,16 @@ test.group('Query Builder | avgDistinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') - .avgDistinct(getQueryBuilder(connection).where('is_verified', true).from('profiles'), 'u') + .avgDistinct(getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), 'u') .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .avgDistinct({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), }) .toSQL() @@ -4773,7 +4776,7 @@ test.group('Query Builder | avgDistinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .avgDistinct({ @@ -4782,10 +4785,10 @@ test.group('Query Builder | avgDistinct', (group) => { }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .avgDistinct({ - u: connection.getWriteClient().raw('select * from profiles where is_verified = ?', [true]), + u: connection.client!.raw('select * from profiles where is_verified = ?', [true]), e: 'email', }) .toSQL() @@ -4798,19 +4801,19 @@ test.group('Query Builder | avgDistinct', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = getQueryBuilder(connection) + const db = getQueryBuilder(connection.getClient()) const { sql, bindings } = db .from('users') .avgDistinct({ - u: getQueryBuilder(connection).where('is_verified', true).from('profiles'), + u: getQueryBuilder(connection.getClient()).where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() - const { sql: knexSql, bindings: knexBindings } = connection.getWriteClient() + const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') .avgDistinct({ - u: connection.getWriteClient().where('is_verified', true).from('profiles'), + u: connection.client!.where('is_verified', true).from('profiles'), e: 'email', }) .toSQL() diff --git a/test/transactions.spec.ts b/test/transactions.spec.ts index 3841a381..d617a505 100644 --- a/test/transactions.spec.ts +++ b/test/transactions.spec.ts @@ -31,7 +31,7 @@ test.group('Transaction | query', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = await connection.transaction() + const db = await connection.getClient().transaction() const results = await db.query().from('users') await db.commit() @@ -43,11 +43,11 @@ test.group('Transaction | query', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = await connection.transaction() + const db = await connection.getClient().transaction() await db.insertQuery().table('users').insert({ username: 'virk' }) await db.commit() - const results = await connection.query().from('users') + const results = await connection.getClient().query().from('users') assert.isArray(results) assert.lengthOf(results, 1) assert.equal(results[0].username, 'virk') @@ -57,11 +57,11 @@ test.group('Transaction | query', (group) => { const connection = new Connection('primary', getConfig(), getLogger()) connection.connect() - const db = await connection.transaction() + const db = await connection.getClient().transaction() await db.insertQuery().table('users').insert({ username: 'virk' }) await db.rollback() - const results = await connection.query().from('users') + const results = await connection.getClient().query().from('users') assert.isArray(results) assert.lengthOf(results, 0) }) @@ -73,7 +73,7 @@ test.group('Transaction | query', (group) => { /** * Transaction 1 */ - const db = await connection.transaction() + const db = await connection.getClient().transaction() await db.insertQuery().table('users').insert({ username: 'virk' }) /** @@ -92,7 +92,7 @@ test.group('Transaction | query', (group) => { */ await db.commit() - const results = await connection.query().from('users') + const results = await connection.getClient().query().from('users') assert.isArray(results) assert.lengthOf(results, 1) assert.equal(results[0].username, 'virk')