Skip to content

Commit 4b8ce8a

Browse files
committed
feat(postgresql): add support for multiple insert in one query using createAll() of connector
BREAKING CHANGE: This drops explicit, documented support for Node.js v10, v11, v12, v13, v15, v17 Signed-off-by: Samarpan Bhattacharya <[email protected]>
1 parent fc5cf8b commit 4b8ce8a

File tree

5 files changed

+135
-53
lines changed

5 files changed

+135
-53
lines changed

lib/postgresql.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ PostgreSQL.prototype.getDefaultSchemaName = function() {
116116
return 'public';
117117
};
118118

119+
PostgreSQL.prototype.multiInsertSupported = true;
120+
119121
/**
120122
* Connect to PostgreSQL
121123
* @callback {Function} [callback] The callback after the connection is established
@@ -591,6 +593,15 @@ PostgreSQL.prototype.getInsertedId = function(model, info) {
591593
return idValue;
592594
};
593595

596+
PostgreSQL.prototype.getInsertedIds = function(model, info) {
597+
const idColName = this.idColumn(model);
598+
let idValues;
599+
if (info && Array.isArray(info)) {
600+
idValues = info.map((data) => data[idColName]);
601+
}
602+
return idValues;
603+
};
604+
594605
/**
595606
* Build the SQL WHERE clause for the where object
596607
* @param {string} model Model name

package-lock.json

Lines changed: 76 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"author": "IBM Corp.",
1414
"repository": "github:loopbackio/loopback-connector-postgresql",
1515
"engines": {
16-
"node": ">=10"
16+
"node": "14 || 16 || 18"
1717
},
1818
"scripts": {
1919
"pretest": "node pretest.js",
@@ -33,7 +33,7 @@
3333
"bluebird": "^3.4.6",
3434
"chalk": "^4.0.0",
3535
"debug": "^4.1.1",
36-
"loopback-connector": "^5.0.0",
36+
"loopback-connector": "^5.1.1",
3737
"pg": "^8.0.2",
3838
"strong-globalize": "^6.0.0",
3939
"uuid": "^9.0.0"
@@ -46,7 +46,7 @@
4646
"juggler-v3": "file:./deps/juggler-v3",
4747
"juggler-v4": "file:./deps/juggler-v4",
4848
"lodash": "^4.17.4",
49-
"loopback-datasource-juggler": "^3.0.0 || ^4.0.0",
49+
"loopback-datasource-juggler": "^4.28.0",
5050
"mocha": "^10.0.0",
5151
"rc": "^1.0.0",
5252
"should": "^13.2.3",

pretest.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ process.env.PGPASSWORD = process.env.TEST_POSTGRESQL_PASSWORD ||
2323
process.env.POSTGRESQL_PASSWORD || process.env.PGPASSWORD || 'test';
2424

2525
console.log('seeding DB with test db...');
26-
const psql = cp.spawn('psql', {stdio: stdio});
26+
const args = process.env.POSTGRESQL_DATABASE ?
27+
['-U', process.env.PGUSER, process.env.POSTGRESQL_DATABASE] :
28+
['-U', process.env.PGUSER];
29+
const psql = cp.spawn('psql', args, {stdio: stdio});
2730
sql.pipe(psql.stdin);
2831
psql.on('exit', function(code) {
2932
console.log('done seeding DB');

0 commit comments

Comments
 (0)