-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
feat: add ability for escaping for Raw() find operator #6850
feat: add ability for escaping for Raw() find operator #6850
Conversation
This functionality is useful in the case when it is necessary to pass user input in a raw query. Also you can create custom operators via For example, operator
|
Aha! This is very nice! :) I've actually seen a few people asking about this BUT for the life of me I can't find the issues where that was. I'll try to get to reviewing this over the next few days as I'm sure it would make a lotta people happy. As I understand it - this is backwards compatible, as well? With the previous functionality? Looks to be the case there from the source. |
I think this Closes #2475 |
I added the ability to specify parameters using an object literal parameters for Example:
|
yes, all changes are backward compatible. |
src/find-options/operator/Raw.ts
Outdated
@@ -1,9 +1,47 @@ | |||
import {FindOperator} from "../FindOperator"; | |||
import {ObjectLiteral} from "../../common/ObjectLiteral"; | |||
|
|||
/** | |||
* Find Options Operator. | |||
* Example: { someField: Raw([...]) } |
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 think example is incorrect here
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 think example is incorrect here
fixed
src/find-options/operator/Raw.ts
Outdated
/** | ||
* Find Options Operator. | ||
* For escaping parameters use next syntax: | ||
* Example: { someField: Raw((columnAlias, parameters) => `${columnAlias} = ${parameters[0]}`, [5]) } |
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 can't understand why do we need this syntax. Isn't it redundant?
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 can't understand why do we need this syntax. Isn't it redundant?
Do you suggest leaving only parameters via ObjectLiteral and remove via array? I can do it.
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.
Yes, it's just seems redundant. It's better to left only one syntax if they both do same and there are no technical issues.
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.
Yes, it's just seems redundant. It's better to left only one syntax if they both do same and there are no technical issues.
Done. Waiting for the tests to complete.
Thank you a lot! |
Having parameters with the Raw operator is a very welcome feature for us, thanks. I did however encounter a little catch: what happens when you use the same Now, I'm not saying that it shouldn't be allowed to share parameters between Raw instances, but |
Unfortunately, there's only support in query builders (& thus find operators) for query-builder-global variable scopes. We don't allow for local parameter scopes at this time - and making that change would be a breaking one but we're definitely accepting pull requests that want to explore that. This is documented here |
I cannot use this change when installing using yarn add typeorm. |
* feat: add ability for escaping for Raw() find operator * fix: update Raw() find operator * fix: fix tests for Raw() find operator * feat: add ability for escaping with object literal parameters for Raw() find operator * docs: correct the example comment of Raw() find operator * fix: delete redundant functional
Currently, find operator
Raw()
not supported escaping.I have updated the code so that it is now possible to use an escaping.
The updated syntax is as follows:
The tests for the new functionality have been written. The old functionality works unchanged.