From 8ff447490c3b460ef8b2b501e003584aa0b122f4 Mon Sep 17 00:00:00 2001 From: Matt Harcourt Date: Wed, 13 Oct 2021 14:40:56 -0700 Subject: [PATCH] identify internal Knex objects by properties other than constructor name --- lib/utils/knexUtils.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/utils/knexUtils.js b/lib/utils/knexUtils.js index b4f681ec3..06d914fe7 100644 --- a/lib/utils/knexUtils.js +++ b/lib/utils/knexUtils.js @@ -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 = {