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 capability for insert multiple rows in single query #228
Conversation
Pull Request Test Coverage Report for Build 3005309761
💛 - Coveralls |
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.
@samarpanB, thanks for contribution. The PR generally LGTM. I have a minor comment what to do with the case where multi-insert is not supported.
*/ | ||
SQLConnector.prototype.buildInsertAll = function(model, data, options) { | ||
if (!this.multiInsertSupported) { | ||
debug('multiple value insert SQL dialect is not supported by this connector'); |
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 wonder if we want to throw an error in this case.
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.
Actually, this flag will be checked at juggler level and rejected from there itself. I'll be raising that PR soon. I have added this to ensure backwards compatibility in connector code too. Let me know if you still feel we should throw error.
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.
sounds good to me.
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. Would like to get at least one more approval before merging. Thanks.
lib/sql.js
Outdated
*/ | ||
SQLConnector.prototype.buildFieldsFromArray = function(model, data, excludeIds) { | ||
const fields = []; | ||
if (data.length > 0) { |
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 would prefer to use Array.isArray(data) && data.length > 0
. For example, if data is string, data.length exists too.
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.
Done. 👍
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.
Other than @raymondfeng's comment, everything else LGTM 👍
I'll fix that. Also, I am in process of raising the next PR for this feature in loopback-juggler. Will share that too. |
ddaaeea
to
a8b2601
Compare
Signed-off-by: Samarpan Bhattacharya <this.is.samy@gmail.com>
Signed-off-by: Samarpan Bhattacharya <this.is.samy@gmail.com>
d9cd324
to
4edc6ae
Compare
Got @raymondfeng's approval per #228 (review). Merged the PR. |
Signed-off-by: Samarpan Bhattacharya this.is.samy@gmail.com
createAll
method to support insert multiple rows in single querymultiInsertSupported
to allow derived connectors to disable this feature if this SQL dialect is not supported. By default, it is false for backwards compatibility.Fixes #227
See also loopbackio/loopback-next#3357
Checklist
npm test
passes on your machine