Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: support non-SQL styles of ds.execute #1855

Merged
merged 1 commit into from Jul 28, 2020
Merged

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Jul 27, 2020

Add new overloads for DataSource.execute method to support non-SQL connectors like MongoDB.

See loopbackio/loopback-next#3342 for background and https://loopback.io/doc/en/lb3/Executing-native-SQL.html for the existing documentation for db.execute API.

Checklist

馃憠 Read and sign the CLA (Contributor License Agreement) 馃憟

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Commit messages are following our guidelines

@bajtos bajtos added the feature label Jul 27, 2020
@bajtos bajtos self-assigned this Jul 27, 2020
@bajtos bajtos force-pushed the types/execute-nosql branch 2 times, most recently from 289fa67 to 4622e36 Compare July 27, 2020 08:12
@bajtos bajtos requested a review from raymondfeng July 27, 2020 08:12
@bajtos bajtos changed the title types: support no-SQL styles of ds.execute types: support non-SQL styles of ds.execute Jul 27, 2020
Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general 馃憤 a minor comment.

execute(
collectionName: string,
command: string,
...parameters: any[],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: the execute function in mongodb seems doesn't have a 3rd parameter, see
https://github.com/strongloop/loopback-connector-mongodb/blob/master/lib/mongodb.js#L467

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate your attention to details! 馃憤

MongoDB connector's execute function does not describe additional parameters in the function signature, but uses arguments.slice to access them:

https://github.com/strongloop/loopback-connector-mongodb/blob/c58e9fbe2b4161230751baf0385cb4c4f6958519/lib/mongodb.js#L469-L470

  // Get the parameters for the given command
  const args = [].slice.call(arguments, 2);

This code was written before rest parameters were introduced to the language, therefore it was not possible to encode ...parameters in the function signature.

Signed-off-by: Miroslav Bajto拧 <mbajtoss@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants