Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeJs bigint cannot be used for querying #82

Open
2 tasks done
noctarius opened this issue Apr 29, 2024 · 2 comments
Open
2 tasks done

NodeJs bigint cannot be used for querying #82

noctarius opened this issue Apr 29, 2024 · 2 comments

Comments

@noctarius
Copy link

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?

  • Yes, I have

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

  • Yes, I have
@szarnyasg szarnyasg transferred this issue from duckdb/duckdb Apr 30, 2024
@szarnyasg
Copy link
Contributor

szarnyasg commented Apr 30, 2024

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

@noctarius
Copy link
Author

Ah thanks. Sorry for the wrong repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants