From 6ecf90049a7e08a3fe9ff2f99c53ab032d91ff05 Mon Sep 17 00:00:00 2001 From: David Worms Date: Thu, 7 Nov 2024 18:47:37 +0100 Subject: [PATCH] feat(csv-issues-esm): issue 441 --- demo/issues-esm/lib/441.js | 19 +++++++++++++++++++ demo/issues-esm/package.json | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 demo/issues-esm/lib/441.js diff --git a/demo/issues-esm/lib/441.js b/demo/issues-esm/lib/441.js new file mode 100644 index 00000000..a6506b26 --- /dev/null +++ b/demo/issues-esm/lib/441.js @@ -0,0 +1,19 @@ +import assert from "node:assert"; +import { Database } from "duckdb-async"; +import { stringify } from "csv-stringify/sync"; + +const db = await Database.create(":memory:"); +const t = await db.all("SELECT DATE '2022-01-01' as dt"); + +// Validate that duckdb returns as an instance of JS date +assert(t[0].dt instanceof Date); +// Validate that date objects are handled by `cast.date` +assert.equal(stringify(t, { cast: { date: () => "ok" } }).trim(), "ok"); + +// First assertion raised in the issue +assert.equal(stringify(t), 1640995200000); +// Second assertion raised in the issue +assert.equal( + stringify(t, { cast: { date: (x) => x.getTime().toString() } }).trim(), + 1640995200000, +); diff --git a/demo/issues-esm/package.json b/demo/issues-esm/package.json index 85525e07..dfd6834f 100644 --- a/demo/issues-esm/package.json +++ b/demo/issues-esm/package.json @@ -37,6 +37,7 @@ "csv-parse": "^5.5.6", "csv-stringify": "^6.5.1", "dedent": "^1.5.3", - "desm": "^1.3.1" + "desm": "^1.3.1", + "duckdb-async": "^1.1.1" } }