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. |
| * @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.
@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.
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.
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: 'alice@example.com',
}
};
// ...
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: 'alice@example.com'},
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.
|
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.executedirectly, 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.executethat will have to upgrade their code./cc @koalabi
Related issues
Checklist
guide