From cbd3c9758b999abee129233e241d99dff7ffec71 Mon Sep 17 00:00:00 2001 From: KernelFreeze Date: Thu, 24 Nov 2022 19:43:14 -0500 Subject: [PATCH] Fix "Cannot convert undefined to a BigInt" (#8) * Fix "Cannot convert undefined to a BigInt" * Return original variable if conversion to BigInt is not possible * Only return `undefined` on `null` or `undefined` Co-authored-by: Aiden <12055114+aidenwallis@users.noreply.github.com> --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index f843de8..1944a43 100644 --- a/src/index.ts +++ b/src/index.ts @@ -107,7 +107,7 @@ class D1Connection implements DatabaseConnection { } return { - insertId: results.lastRowId !== null ? BigInt(results.lastRowId) : undefined, + insertId: results.lastRowId === undefined || results.lastRowId === null ? undefined : BigInt(results.lastRowId), rows: (results?.results as O[]) || [], numUpdatedOrDeletedRows: results.changes > 0 ? BigInt(results.changes) : undefined, };