Skip to content

Commit

Permalink
Merge pull request #69 from UN-OCHA/fix-empty-create-many
Browse files Browse the repository at this point in the history
Don't throw an error if empty array is passed to `createMany`
  • Loading branch information
s0 authored Dec 6, 2021
2 parents a5c4936 + c4e0fa0 commit 5b27e21
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/db/util/raw-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ export const defineRawModel =
};

const createMany: CreateManyFn<F> = 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);
Expand Down

0 comments on commit 5b27e21

Please sign in to comment.