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

add tokenize to node client api #11

Merged

Conversation

jraymakers
Copy link
Contributor

[This PR was previously submitted to the main duckdb repo.]

Add plumbing to expose the Tokenize method through the Node client API.

The signature of this method follows the corresponding method from duckdb-wasm. It returns an object containing two arrays of numbers, instead of an array of objects, each with two number properties (as the underlying C++ API does), presumably to reduce the number of JS objects that need to be created.

I opted to call the Tokenize method synchronously, since it's lightweight and doesn't require any database resources; it's a static method of the parser. If there's a reason to move the call to the worker thread, let me know.

In addition to exposing the method itself, the TokenType enum is also exposed. This requires some code on the C++ side in order to add the runtime enum object to the NodeDuckDB Addon, in addition to the type definition on the TypeScript side.

A basic unit test suite is included.

@Mause Mause requested review from hannes and Mytherin October 27, 2023 05:29
@Mytherin Mytherin merged commit f226d18 into duckdb:main Oct 30, 2023
4 checks passed
@Mytherin
Copy link
Contributor

Thanks! LGTM

@jraymakers jraymakers deleted the jray/add-tokenize-to-node-client-api branch January 8, 2024 16:56
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

Successfully merging this pull request may close these issues.

2 participants