Skip to content

Commit

Permalink
Merge pull request #15 from leapfrogtechnology/support-trx
Browse files Browse the repository at this point in the history
Support knex transactions in synchronize
  • Loading branch information
kabirbaidhya authored Aug 28, 2019
2 parents 0c823e2 + b206822 commit f9fa6cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Connection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Knex from 'knex';

import ConnectionConfig from './domain/ConnectionConfig';
import DbConnectionInstance from './domain/DbConnectionInstance';
import RawBindingParams, { ValueMap } from './domain/RawBingingParams';

/**
Expand Down Expand Up @@ -29,7 +30,7 @@ class Connection {
* @param {any} obj
* @returns {boolean}
*/
public static isKnexInstance(obj: any): obj is Knex {
public static isKnexInstance(obj: any): obj is DbConnectionInstance {
return !!(obj.prototype && obj.prototype.constructor && obj.prototype.constructor.name === 'knex');
}

Expand Down
8 changes: 8 additions & 0 deletions src/domain/DbConnectionInstance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as Knex from 'knex';

/**
* Database connection instances.
*/
type DbConnectionInstance = Knex | Knex.Transaction;

export default DbConnectionInstance;
7 changes: 3 additions & 4 deletions src/migrator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as Knex from 'knex';

import Connection from './Connection';
import { log, dbLogger } from './logger';
import * as sqlRunner from './sqlRunner';
import SyncParams from './domain/SyncParams';
import SyncConfig from './domain/SyncConfig';
import ConnectionConfig from './domain/ConnectionConfig';
import DbConnectionInstance from './domain/DbConnectionInstance';

/**
* Migrate SQL on a database.
Expand Down Expand Up @@ -79,12 +78,12 @@ export function teardown(config: SyncConfig): (connection: Connection) => Promis
* Synchronize database.
*
* @param {SyncConfig} config
* @param {ConnectionConfig[] | Knex[] | ConnectionConfig | Knex} connections
* @param {ConnectionConfig[] | DbConnectionInstance[] | ConnectionConfig | DbConnectionInstance} conn
* @param {SyncParams} params
*/
export async function synchronize(
config: SyncConfig,
conn: ConnectionConfig[] | Knex[] | ConnectionConfig | Knex,
conn: ConnectionConfig[] | DbConnectionInstance[] | ConnectionConfig | DbConnectionInstance,
params?: SyncParams
) {
log('Starting to synchronize.');
Expand Down

0 comments on commit f9fa6cf

Please sign in to comment.