-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix queryContext function defintion #3562
Fix queryContext function defintion #3562
Conversation
According to the docs, calling `queryContext` with no arguments returns the context object. Add the relevant overload to the function definition for that use case.
Thanks! Could you also update https://github.com/knex/knex/blob/master/types/test.ts? |
@@ -1330,6 +1330,7 @@ declare namespace Knex { | |||
wrap<TResult2 = TResult>(before: string, after: string): Raw<TResult>; | |||
toSQL(): Sql; | |||
queryContext(context: any): Raw<TResult>; | |||
queryContext(): any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be better defined as Record<string, any>?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, would that be for the return type?
From what I can tell it returns exactly what was put in when called with an argument, so I figured it would be best to just have those types match
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, fair :). does it work correctly if user passes e. g. string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this is the underlying implementation:
Lines 79 to 85 in 988fb24
Target.prototype.queryContext = function(context) { | |
if (isUndefined(context)) { | |
return this._queryContext; | |
} | |
this._queryContext = context; | |
return this; | |
}; |
And the docs say the queryContext is shallowly cloned when a query builder is cloned:
Line 93 in f87b28c
cloned._queryContext = clone(this._queryContext); |
which uses
lodash.clone
and should work on any value passed in
Can do |
thanks! |
Released in 0.20.4 |
According to the docs, calling
queryContext
with no arguments returns the context object. (ref: https://knexjs.org/#Builder-queryContext)This PR adds the relevant overload to the function definition for that use case.