Skip to content

feat: add no-escape mode for MySQL #861

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

Closed
canalun opened this issue Apr 29, 2023 · 6 comments
Closed

feat: add no-escape mode for MySQL #861

canalun opened this issue Apr 29, 2023 · 6 comments

Comments

@canalun
Copy link
Contributor

canalun commented Apr 29, 2023

Hi, thank you for developing this amazing parser...!
I use it for building a MySQL formatter and it help me so much😊

I'm not 100% sure if the idea I write below is good one, but I would like to share it for discussion.

idea

The implementation of no-escape mode.
It means that the info of escape (=backslashes) is kept through parsing and restoring queries.

current situation and details of idea

Currently, this library works as below. In short, backslashes disappear.

-- before parse
INSERT INTO `table` ('id', 'text') VALUES (1, 'they say \"Hello\".');
INSERT INTO `table` ('id', 'text') VALUES (1, 'new\nline');

-- after parse and conversion into query
INSERT INTO `table` ('id', 'text') VALUES (1, 'they say "Hello".');
INSERT INTO `table` ('id', 'text') VALUES (1, 'new
line');

That can be a bit problematic when using this library for developing other tools,
because some tools (e.g. formatter) are expected not to add any change to the queries.

So what about the idea that users can choose if they keep backslashes or not?

prototype

Actually, I created a small patch to realize the above feature in my forked repo.
And, just for clarification, I opened a draft of PR: #862

NOTE: I'm pretty sure the patch is not for implementation for this library. It is just an emergency patch for my formatter :)

Thank you for reading!😊

@canalun canalun changed the title feat: no-escape mode for MySQL feat: add no-escape mode for MySQL Apr 29, 2023
@canalun
Copy link
Contributor Author

canalun commented Apr 30, 2023

if it's worth implementing, i'd like to work on it😊

@alamb
Copy link
Contributor

alamb commented May 2, 2023

I can see the rationale for trying to keep the original escaping (as opposed to processing the escapes).

What do you think about maybe trying to add this feature as some sort of Dialect (which is the current way we have to control parsing changes)?

@canalun
Copy link
Contributor Author

canalun commented May 4, 2023

thanks, i think that's a really good way!
i'll work on it🚀

@canalun
Copy link
Contributor Author

canalun commented May 8, 2023

I'm working on #870 , and let me notice when the pr get ready.
(please keep the branch of #862 until this PR is merge, because my format tool uses the branch of #862...!)

@canalun
Copy link
Contributor Author

canalun commented May 9, 2023

#870 is ready for review. Thank you for waiting!

@alamb
Copy link
Contributor

alamb commented Aug 22, 2023

I believe we released this in 0.36.0 - so closing. Please reopen if I got that wrong

@alamb alamb closed this as completed Aug 22, 2023
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