duckdb-node icon indicating copy to clipboard operation
duckdb-node copied to clipboard

NodeJs bigint cannot be used for querying

Open noctarius opened this issue 1 year ago • 2 comments

What happens?

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

To Reproduce

Reproducer code:

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<QueryResult> => {
    return new Promise((resolve, reject) => {
        const callback: Callback<TableData> = (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:

$ 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

noctarius avatar Apr 29 '24 17:04 noctarius

Hi @noctarius, thanks for reporting this. The Node.js DuckDB client is now maintained in a separate repository. I moved the issue there.

szarnyasg avatar Apr 30 '24 11:04 szarnyasg

Ah thanks. Sorry for the wrong repo.

noctarius avatar Apr 30 '24 12:04 noctarius