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

Feature Request: Inline mode #360

Open
ericyangpan opened this issue Jul 29, 2022 · 5 comments
Open

Feature Request: Inline mode #360

ericyangpan opened this issue Jul 29, 2022 · 5 comments
Labels

Comments

@ericyangpan
Copy link

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.

@nene
Copy link
Collaborator

nene commented Jul 29, 2022

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 indentStyle option, like indentStyle: 'inline' or indentStyle: 'none'.

@inferrinizzard what do you think of this?

@inferrinizzard
Copy link
Collaborator

Yes, definitely a use case for many SQL devs - this is along the lines of what the keywordNewline config was trying to achieve but now is easier with a parser structure

@ericyangpan
Copy link
Author

Yes, definitely a use case for many SQL devs - this is along the lines of what the keywordNewline config was trying to achieve but now is easier with a parser structure

I saw it ware removed in changelog of keywordNewline

@borgogelli
Copy link

+1 It could be a very useful feature

@patdx
Copy link

patdx commented Dec 12, 2022

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:

import { format } from "sql-formatter";

console.log(
  format(
    `insert into my_table ( a, b, c, d ) values ( 1, "this is a very long value that wraps", "this is a very long value that wraps", "this is a very long value that wraps" )`,
    {
      language: "sqlite",
      tabWidth: 0,
      expressionWidth: 100000,
      keywordCase: "upper",
    }
  ).replace(/\n+/g, " ")
);

// Output:
// INSERT INTO my_table (a, b, c, d) VALUES (1, "this is a very long value that wraps", "this is a very long value that wraps", "this is a very long value that wraps")

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants