Skip to content

Commit

Permalink
identify internal Knex objects by properties other than constructor name
Browse files Browse the repository at this point in the history
  • Loading branch information
mattharcourt authored and koskimas committed Nov 19, 2021
1 parent f5ad7b9 commit 8ff4474
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/utils/knexUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,29 @@ function isMsSql(knex) {
}

function isKnexQueryBuilder(value) {
return hasConstructor(value, 'Builder') && 'client' in value;
return (
hasConstructor(value) &&
isFunction(value.select) &&
isFunction(value.column) &&
value.select === value.column &&
'client' in value
);
}

function isKnexJoinBuilder(value) {
return hasConstructor(value, 'JoinClause') && 'joinType' in value;
return hasConstructor(value) && value.grouping === 'join' && 'joinType' in value;
}

function isKnexRaw(value) {
return hasConstructor(value, 'Raw') && 'client' in value;
return hasConstructor(value) && value.isRawInstance && 'client' in value;
}

function isKnexTransaction(knex) {
return !!getDialect(knex) && isFunction(knex.commit) && isFunction(knex.rollback);
}

function hasConstructor(value, constructorName) {
return (
isObject(value) && isFunction(value.constructor) && value.constructor.name === constructorName
);
function hasConstructor(value) {
return isObject(value) && isFunction(value.constructor);
}

module.exports = {
Expand Down

0 comments on commit 8ff4474

Please sign in to comment.