Skip to content

Commit a3b354b

Browse files
Samarpan  Bhattacharyaraymondfeng
Samarpan Bhattacharya
authored andcommitted
feat: add support for multiple insert in one query
BREAKING CHANGE drop nodejs v12 support and juggler v3 support Signed-off-by: Samarpan Bhattacharya <[email protected]>
1 parent 0d54635 commit a3b354b

File tree

10 files changed

+295
-967
lines changed

10 files changed

+295
-967
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ jobs:
1515
strategy:
1616
matrix:
1717
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
18-
node-version: [12, 14, 16]
18+
node-version: [14, 16]
1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v3
2121
- name: Use Node.js ${{ matrix.node-version }}
22-
uses: actions/setup-node@v2
22+
uses: actions/setup-node@v3
2323
with:
2424
node-version: ${{ matrix.node-version }}
2525
- uses: ankane/setup-mysql@v1

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ coverage
44
*.xml
55
.loopbackrc
66
.idea
7-
7+
.vscode

deps/juggler-v3/package.json

-8
This file was deleted.

deps/juggler-v3/test.js

-31
This file was deleted.

deps/juggler-v4/package.json

-8
This file was deleted.

deps/juggler-v4/test.js

-32
This file was deleted.

lib/mysql.js

+16
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ function MySQL(settings) {
7474

7575
require('util').inherits(MySQL, SqlConnector);
7676

77+
MySQL.prototype.multiInsertSupported = true;
78+
7779
MySQL.prototype.connect = function(callback) {
7880
const self = this;
7981
const options = generateOptions(this.settings);
@@ -324,6 +326,20 @@ MySQL.prototype.getInsertedId = function(model, info) {
324326
return insertedId;
325327
};
326328

329+
MySQL.prototype.getInsertedIds = function(model, info) {
330+
let insertedIds = [];
331+
const idProp = this.getDataSource(model).idProperty(model);
332+
if (info && info.affectedRows > 0) {
333+
insertedIds = new Array(info.affectedRows);
334+
for (let i = 0; i < info.affectedRows; i++) {
335+
insertedIds[i] = idProp.generated && typeof idProp.type() === 'number' &&
336+
typeof info.insertId === 'number' && info.insertId > 0 ?
337+
info.insertId + i : undefined;
338+
}
339+
}
340+
return insertedIds;
341+
};
342+
327343
/*!
328344
* Convert property name/value to an escaped DB column value
329345
* @param {Object} prop Property descriptor

0 commit comments

Comments
 (0)