duckdb / duckdb/duckdb-node

NodeJs bigint cannot be used for querying

Open
#82 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
91
Forks
36
PR merge metrics
No merged PRs in 30d

Description

### What happens?

Querying with a bigint value from the nodejs binding fails to match a bigint value in the database.

### To Reproduce

Reproducer code:
```typescript
import {Callback, Database, DuckDbError, TableData} from "duckdb";
import {QueryResult} from "./storage/storage";
import {Conversation} from "./model/conversation";

const database = new Database("./test.db");
const connection = database.connect();

const all = (sql: string, ...args: any[]): Promise => {
return new Promise((resolve, reject) => {
const callback: Callback = (err: DuckDbError | null, res: TableData): void => {
if (err) return reject(err);
return resolve(res);
}
return connection.all(sql, ...args, callback);
});
}

(async () => {
const exitHandler = async () => {
process.exit(0);
}

process.on('SIGINT', exitHandler);
process.on('SIGTERM', exitHandler);

console.log("- Create test data:");
const res = await all(`
CREATE SEQUENCE test_seq;
CREATE TABLE test (
id BIGINT PRIMARY KEY DEFAULT nextval('test_seq'),
value TEXT
);
INSERT INTO test (value) VALUES ('test') RETURNING id;`
);
console.log(res[0]["id"], " => ", typeof res[0]["id"]);

console.log("- Query with number:");
const res2 = await all(`
SELECT id, value FROM test WHERE id = ?::BIGINT`,
1 // <-- number
);
console.log(res2[0]["id"], " => ", typeof res2[0]["id"]);

console.log("- Query with bigint:");
const res3 = await all(`
SELECT id, value FROM test WHERE id = ?::BIGINT`,
1n // <-- bigint
);
console.log(res3[0]["id"], " => ", typeof res3[0]["id"]);
})();

process.stdin.resume();
```

Result:
```plain
$ node build/test.js
- Create test data:
1n => bigint
- Query with number:
1n => bigint
- Query with bigint:
/Users/noctarius/WebstormProjects/untitled/build/test.js:40
console.log(res3[0]["id"], " => ", typeof res3[0]["id"]);
^

TypeError: Cannot read properties of undefined (reading 'id')
at /Users/noctarius/WebstormProjects/untitled/build/test.js:40:24

Node.js v22.0.0
```

### OS:

MacOS 14.4.1

### DuckDB Version:

v0.10.2

### DuckDB Client:

NodeJS

### Full Name:

Chris Engelbert

### Affiliation:

simplyblock

### What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a stable release

### Did you include all relevant data sets for reproducing the issue?

Yes

### Did you include all code required to reproduce the issue?

- [X] Yes, I have

### Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

- [X] Yes, I have

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.