From d5203636294766748ba6d7b5743056470c76d53b Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Tue, 20 May 2025 11:31:10 -0700 Subject: [PATCH] handle empty result in table init --- lib/postgres-creator.js | 6 ++++-- test/lib/postgres-creator.js | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/postgres-creator.js b/lib/postgres-creator.js index dc0ee93..d2e5ca9 100644 --- a/lib/postgres-creator.js +++ b/lib/postgres-creator.js @@ -78,8 +78,10 @@ const PostgresCreator = (Abstract) => { * @returns {object[]} scrubbed results */ static _multiResultLog(results) { - for (const result of results) { - delete result._types; + if (results) { + for (const result of results) { + delete result._types; + } } return results; } diff --git a/test/lib/postgres-creator.js b/test/lib/postgres-creator.js index ecc6025..b8a820c 100644 --- a/test/lib/postgres-creator.js +++ b/test/lib/postgres-creator.js @@ -128,6 +128,17 @@ describe('Postgres Creator', function () { }); // receive }); // pgpInitOptions + describe('_multiResultLog', function () { + it('strips verbosity', function () { + const result = DatabasePostgres._multiResultLog(multiResultResponse); + assert(!('_types' in result[0])); + }); + it('covers empty', function () { + const result = DatabasePostgres._multiResultLog(undefined); + assert.strictEqual(result, undefined); + }); + }); // _multiResultLog + describe('_tableExists', function () { beforeEach(function () { sinon.stub(db.db, 'oneOrNone'); -- 2.49.0