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

Added new option: includePositions #14

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mliezun
Copy link
Contributor

@mliezun mliezun commented Feb 28, 2025

Hi @VeryCrazyDog I'm coming here with a feature proposal.

To add a new option includePositions: bool to the split function.

When includePositions = true return start and end positions from the original source of text from which the statement was parsed.

This is helpful to compare what was the original query and the resulting query that is going to be executed after parsing.

What was done:

  • Correctly track and return positions for parsed statements.
  • Added test to check that it works correctly.

Thanks again for your work and for this package 👍

When includePositions = true return start and end positions from the original source of text from which the statement was parsed.
Added test to check that it works correctly.
Copy link
Owner

@VeryCrazyDog VeryCrazyDog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially reviewed the code, please expect more comments may be added after PR revised.

src/index.ts Outdated
}

interface SplitExecutionContext extends Required<SplitOptions> {
unread: string
position: number
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word position is too generic, and not align with the existing source code naming of using index. Consider either one of the below:

  1. Rename it to unreadIndex and add JSDoc to document that it is the index in source SQL string.
  2. Rename it to unreadSourceFileIndex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to unreadSourceFileIndex

src/index.ts Outdated

export type SqlStatementResult = string | { stmt: string, start: number, end: number };

export function split (sql: string, options?: SplitOptions): SqlStatementResult[] {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am open for including support of includePositions options, but not in a way that introduce breaking changes. Instead of altering existing split function, add a new function instead.

function splitIncludeSourceMap (sql: string, options?: SplitOptions): Array<{ stmt: string, start: number, end: number }>;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created new function splitIncludeSourceMap

src/index.ts Outdated

export type SqlStatementResult = string | { stmt: string, start: number, end: number };

export function split (sql: string, options?: SplitOptions): SqlStatementResult[] {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid unnecessary reordering of functions in feature or bugfix PRs. These changes can complicate code reviews, as the diffs become harder to follow.

It would be better to keep the code in its original position and create a separate PR for any rearrangements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

src/index.ts Outdated
Comment on lines 234 to 235
// MySQL client will return `DELIMITER cannot contain a backslash character` if backslash is used
// Shall we reject backslash as well?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this comment is removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought maybe it was not needed because nothing was done about it. Put the comment back in place ✅

Co-authored-by: VCD <verycrazydog@gmail.com>
@mliezun mliezun requested a review from VeryCrazyDog March 1, 2025 09:22
@mliezun
Copy link
Contributor Author

mliezun commented Mar 1, 2025

Addressed all your comments. Think it looks a lot more streamlined now and the changes are easier to follow.

Thanks for your review!!

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