-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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:
- Rename it to
unreadIndex
and add JSDoc to document that it is the index in source SQL string. - Rename it to
unreadSourceFileIndex
.
There was a problem hiding this comment.
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[] { |
There was a problem hiding this comment.
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 }>;
There was a problem hiding this comment.
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[] { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
// MySQL client will return `DELIMITER cannot contain a backslash character` if backslash is used | ||
// Shall we reject backslash as well? |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
Addressed all your comments. Think it looks a lot more streamlined now and the changes are easier to follow. Thanks for your review!! |
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:
Thanks again for your work and for this package 👍