-
Notifications
You must be signed in to change notification settings - Fork 362
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: dataSource.execute(cmd, args, opts) #1671
Conversation
A related question on StackOverflow: How to execute arbitrary SQL query |
Added a new commit to remove callback style and keep Promise style only. |
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.
@bajtos Mostly LGTM 👏 , I left a concern about the command's type.
For the types in the callback flavour, I am ok to remove them.
* @param [options] Object Additional options, e.g. the transaction to use. | ||
* @returns Promise A promise of the result | ||
*/ | ||
DataSource.prototype.execute = function(command, args = [], options = {}) { |
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.
@bajtos I found the command type here a bit confusing: the function types defined at the bottom of this PR only takes string
type as command. Any particular reason to allow an object?
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.
the function types defined at the bottom of this PR only takes string type as command.
I forgot to update typedefs, they were describing a callback variant too. I'll fix that.
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.
Any particular reason to allow an object?
Some community connectors are using object value for the comman and I want to preserve support for those connectors.
See e.g. https://www.npmjs.com/package/loopback-connector-neo4j-graph
var cypher = {
query: "MATCH (u:User {email: {email}}) RETURN u",
params: {
email: '[email protected]',
}
};
// ...
ModelClass.dataSource.connector.execute(
cypher,
[],
options,
callback
);
I think the connector authors misunderstood how command & args are meant to be used together. I think the following would be a better usage:
ModelClass.dataSource.connector.execute(
`MATCH (u:User {email: {email}}) RETURN u`,
{email: '[email protected]'},
options,
callback);
Based on this analysis, I am going to change the type of args
from array to object. (Note that arrays are objects too.)
I have addressed the review comments and made the following extra changes:
@jannyHou LGTY now? |
Implement a new helper API for calling connector's "execute" method in a promise-friendly way.
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.
LGTM
Is this supported for mongodb connector? |
@jannyHou Do you know if there are any usage examples? |
Implement a new helper API for calling connector's "execute" method
in a promise-friendly way.
Example usage:
While it's possible to call
MyModel.dataSource.execute
directly, this new API adds promise support to existing callback-based connectors. When we upgrade connector API to use promises under the hood, consumers of this new API won't be affected by that change, as opposed to consumers ofconnector.execute
that will have to upgrade their code./cc @koalabi
Related issues
Checklist
guide