@malloydata/db-duckdb 0.0.131-dev240312174126 → 0.0.131-dev240314002549

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -91,14 +91,6 @@ const unwrapArrow = (value) => {
91
91
  else if (Array.isArray(value)) {
92
92
  return value.map(exports.unwrapArrow);
93
93
  }
94
- else if (obj['microseconds'] && obj['timezone'] === null) {
95
- // Convert epoch µs to ms
96
- return Number(obj['microseconds']) / 1000;
97
- }
98
- else if (obj['days']) {
99
- // Convert epoch day to Date
100
- return new Date(obj['days'] * 8.64e7);
101
- }
102
94
  else {
103
95
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
96
  const result = {};
@@ -49,6 +49,60 @@ exports.DuckDBWASMConnection = void 0;
49
49
  const duckdb = __importStar(require("@duckdb/duckdb-wasm"));
50
50
  const duckdb_wasm_connection_1 = require("./duckdb_wasm_connection");
51
51
  const wasm_client_1 = require("@motherduck/wasm-client");
52
+ function unwrapMotherDuck(value) {
53
+ let result = null;
54
+ if (value !== null && typeof value === 'object') {
55
+ if (value instanceof wasm_client_1.DuckDBDate) {
56
+ result = new Date(value.days * 8.64e7);
57
+ }
58
+ else if (value instanceof wasm_client_1.DuckDBDecimal) {
59
+ result = Number(value.scaledValue) / Math.pow(10, value.scale);
60
+ }
61
+ else if (value instanceof wasm_client_1.DuckDBTime) {
62
+ result = new Date(Number(value.microseconds) / 1000);
63
+ }
64
+ else if (value instanceof wasm_client_1.DuckDBTimestampMicroseconds) {
65
+ result = new Date(Number(value.microseconds) / 1000);
66
+ }
67
+ else if (value instanceof wasm_client_1.DuckDBTimestampMilliseconds) {
68
+ result = new Date(Number(value.milliseconds));
69
+ }
70
+ else if (value instanceof wasm_client_1.DuckDBTimestampNanoseconds) {
71
+ result = new Date(Number(value.nanoseconds) / 1000 / 1000);
72
+ }
73
+ else if (value instanceof wasm_client_1.DuckDBTimestampSeconds) {
74
+ result = new Date(Number(value.seconds) * 1000);
75
+ }
76
+ else if (value instanceof wasm_client_1.DuckDBStruct) {
77
+ const struct = {};
78
+ for (const structEntry of value.entries) {
79
+ struct[structEntry.key] = unwrapMotherDuck(structEntry.value);
80
+ }
81
+ result = struct;
82
+ }
83
+ else if (value instanceof wasm_client_1.DuckDBList) {
84
+ result = value.values.map(unwrapMotherDuck);
85
+ }
86
+ else {
87
+ result = value.toString();
88
+ }
89
+ }
90
+ else if (typeof value === 'bigint') {
91
+ result = Number(value);
92
+ }
93
+ else {
94
+ result = value;
95
+ }
96
+ return result;
97
+ }
98
+ function unwrapMotherDuckRow(row) {
99
+ const result = {};
100
+ for (const entry of Object.entries(row)) {
101
+ const [key, value] = entry;
102
+ result[key] = unwrapMotherDuck(value);
103
+ }
104
+ return result;
105
+ }
52
106
  class DuckDBWASMConnection extends duckdb_wasm_connection_1.DuckDBWASMConnection {
53
107
  constructor() {
54
108
  super(...arguments);
@@ -112,7 +166,9 @@ class DuckDBWASMConnection extends duckdb_wasm_connection_1.DuckDBWASMConnection
112
166
  if (queryId) {
113
167
  const result = await connection.evaluateQueuedQuery(queryId);
114
168
  if (result === null || result === void 0 ? void 0 : result.data) {
115
- const rows = (0, duckdb_wasm_connection_1.unwrapArrow)(result.data.toRows());
169
+ const rows = result.data
170
+ .toRows()
171
+ .map(row => unwrapMotherDuckRow(row));
116
172
  const totalRows = result.data.rowCount;
117
173
  return {
118
174
  rows,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-duckdb",
3
- "version": "0.0.131-dev240312174126",
3
+ "version": "0.0.131-dev240314002549",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@duckdb/duckdb-wasm": "1.28.1-dev106.0",
44
- "@malloydata/malloy": "^0.0.131-dev240312174126",
44
+ "@malloydata/malloy": "^0.0.131-dev240314002549",
45
45
  "@motherduck/wasm-client": "^0.4.0",
46
46
  "apache-arrow": "^14.0.0",
47
47
  "duckdb": "0.9.2",