From: Justin Wind Date: Tue, 20 May 2025 18:31:10 +0000 (-0700) Subject: handle empty result in table init X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=d5203636294766748ba6d7b5743056470c76d53b;p=squeep-db-helper handle empty result in table init --- 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');