-
Notifications
You must be signed in to change notification settings - Fork 420
Feature Request: Inline mode #360
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
Comments
Seems like a pretty sensible request. Though it probably makes more sense for use in an editor plugin, e.g. to format a selected line. It would actually be not that hard to implement. We already have some-sort of inline mode inside the formatter to format short parenthesized blocks. We'd need to extend this to also apply for other parts of SQL which currently trigger line breaks. Perhaps another value for the @inferrinizzard what do you think of this? |
Yes, definitely a use case for many SQL devs - this is along the lines of what the |
I saw it ware removed in changelog of |
+1 It could be a very useful feature |
This would be a cool feature to have. I have come across two different situations when I wished for this feature recently. I found a neat trick to get quite close:
Setting the expressionWidth to a really big value solves the issue with extra space instead of parenthesis, which looks weird on one line. Though I am not 100% sure if this works in all situations since it is kind of a hack. Having it as an official feature would give extra confidence about the reliability. |
@nene Any update on this? |
No real plans to implement this in SQL Formatter. You might instead consider prettier-plugin-sql-cst, which does this dynamically. That is, if the query is one single line in the original source code and it's short enough to fit within line-length limit, it'll keep it on one line. This doesn't yet work for all the different SQL statements, but for the basic SELECT, INSERT, UPDATE, DELETE it should work. In SQL Formatter I wouldn't be able to achieve such a dynamic implementation...
Also, supporting different formatting styles adds quite a bit of overhead when maintaining this library. Currently I'd say it doesn't even do a good job of supporting a single style. |
Hi @nene, The new lib lacks the customisations which this lib provides. So we're not able to move on. |
@adityatoshniwal If you would say which specific customization options are important to you, then I could say whether these are among the planned features or not. |
Except tab size and use spaces, all is taken care by sql formatter. We're using it in pgAdmin4 ![]() |
So..
I think what's more relevant for pgAdmin is the following:
|
Hi @nene, Thank you for your work. Looking forward for PostgreSQL support. I do agree with you that some of the configs can/should be removed for greater good. Most people care about is casing. I am a JS developer, so if you need any help then I can contribute. |
Well, the main bottleneck for PostgreSQL support is implementation of the parser. You can track the progress here: nene/sql-parser-cst#40 I expect it to take years before it's 100% complete, this SQL dialect is just so big. A better question might be, when it's complete enough to be useful. For example it supports most of the usual SELECT/INSERT/UPDATE/DELETE syntax plus CREATE/DROP/ALTER TABLE. But if you wonder off the common path, you'll find that e.g. cursors-related syntax is not supported, or that custom operators aren't supported, or that the special syntax of some JSON- and XML-functions isn't supported. |
This might help - https://supabase.com/blog/postgres-language-server-implementing-parser#implementing-a-parser-for-postgres |
Thanks. That's an interesting read, but I'm not really looking for a new approach to implement a parser. I already have a parser which works well. I just need to make it support all of PostgreSQL syntax. |
Or to put it another way. I spent lots of time looking for a suitable parser, but found none as pretty much all the SQL parsers output just the AST, which excludes lots of information that I need for formatting. Like whether an expression is surrounded by parenthesis or not. So I opted to implement my own. Switching to a different parser now would mean throwing away almost everything and starting from scratch. Or writing some sort of adapter, which would likely be almost the same amount of work as writing the parser in the first place. |
Got it. Are you also planning to include pl/pgsql? |
Planning, but not before I get the plain PostgreSQL more fully supported. |
Describe the Feature
Sometimes I need inline mode. For example, 'select * from tbl' to 'SELECT * FROM tbl;'.
Why do you want this feature?
Inline mode is a frequent scene for simple SQL statement in docs.
The text was updated successfully, but these errors were encountered: