From ef4858e91d4c58f015d239024f90c7d0fbedbb59 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Fri, 3 Dec 2021 20:06:55 +0100 Subject: [PATCH 1/2] Don't throw an error if empty array is passed to `createMany` If empty array is provided to `createMany`, `knex` doesn't mind executing the query (even though it does nothing), but `res.map(validateAndFilter)` fails since returned result is an object, rather than array of created rows. --- src/db/util/raw-model.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/db/util/raw-model.ts b/src/db/util/raw-model.ts index f3ec36b9..aba268c5 100644 --- a/src/db/util/raw-model.ts +++ b/src/db/util/raw-model.ts @@ -119,6 +119,10 @@ export const defineRawModel = }; const createMany: CreateManyFn = async (data, opts) => { + if (!data.length) { + return []; + } + const builder = opts?.trx ? tbl().transacting(opts.trx) : tbl(); const res = await builder.insert(data).returning('*'); return res.map(validateAndFilter); From c4e0fa078ca2e88e57adfff52ca46fe1b96dfea4 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Fri, 3 Dec 2021 20:10:07 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=96=20Bump=20version=20to=20`v1.1.?= =?UTF-8?q?2`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c971aabd..d4670767 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@unocha/hpc-api-core", - "version": "1.1.1", + "version": "1.1.2", "description": "Core libraries supporting HPC.Tools API Backend", "license": "Apache-2.0", "private": false,