Add Database.tokenize() wrapper and re-export ScriptTokens/TokenType#52
Open
Montana wants to merge 1 commit into
Open
Add Database.tokenize() wrapper and re-export ScriptTokens/TokenType#52Montana wants to merge 1 commit into
Montana wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
Database.tokenize()wrapper and re-exportScriptTokens/TokenTypeSummary
The underlying
duckdbNode API exposesDatabase.tokenize(text): ScriptTokens(added upstream in duckdb/duckdb-node for SQL syntax highlighting / editor tooling), butduckdb-asyncdoesn't wrap it, so users of this package can't reach it without dropping down to the raw API.This PR:
tokenize(text: string): duckdb.ScriptTokensmethod to theDatabasewrapper. It's a synchronous delegation following the exact pattern of the existinginterrupt()method (including the uninitialized-database guard).ScriptTokensandTokenTypetypes/enum fromduckdb, so callers can type the return value and compare token types without importingduckdbdirectly.tokenizetest (select 1;→ offsets[0, 7, 8], types[KEYWORD, NUMERIC_CONSTANT, OPERATOR]).Notes
While auditing the API surface,
Database.get()is the only other method in duckdb's type definitions not wrapped here, but it's intentionally unimplemented upstream (it throws"get() is not implemented because it's evil"), so it's deliberately excluded from this PR. With this change, the wrapper covers every implemented method onduckdb.Database.