Skip to content

Commit 6ecf900

Browse files
committed
feat(csv-issues-esm): issue 441
1 parent 4819511 commit 6ecf900

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

demo/issues-esm/lib/441.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import assert from "node:assert";
2+
import { Database } from "duckdb-async";
3+
import { stringify } from "csv-stringify/sync";
4+
5+
const db = await Database.create(":memory:");
6+
const t = await db.all("SELECT DATE '2022-01-01' as dt");
7+
8+
// Validate that duckdb returns as an instance of JS date
9+
assert(t[0].dt instanceof Date);
10+
// Validate that date objects are handled by `cast.date`
11+
assert.equal(stringify(t, { cast: { date: () => "ok" } }).trim(), "ok");
12+
13+
// First assertion raised in the issue
14+
assert.equal(stringify(t), 1640995200000);
15+
// Second assertion raised in the issue
16+
assert.equal(
17+
stringify(t, { cast: { date: (x) => x.getTime().toString() } }).trim(),
18+
1640995200000,
19+
);

demo/issues-esm/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"csv-parse": "^5.5.6",
3838
"csv-stringify": "^6.5.1",
3939
"dedent": "^1.5.3",
40-
"desm": "^1.3.1"
40+
"desm": "^1.3.1",
41+
"duckdb-async": "^1.1.1"
4142
}
4243
}

0 commit comments

Comments
 (0)