nene / prettier-plugin-sql-cst

Prettier SQL plugin that uses sql-parser-cst
https://nene.github.io/prettier-sql-playground/
GNU General Public License v3.0
132 stars 7 forks source link

How to enable embedded formatting #33

Closed steida closed 1 month ago

steida commented 1 month ago

Maybe I'm blind or dumb, but I cannot enable embedded formatting. I just discovered prettier-plugin-sql, set it up, and it works. And then I found prettier-plugin-sql-cst, and I'm unable to run it for embedded SQL.

Is there some magic setting, or it just doesn't run in monorepo? I don't know; hence, I'm opening issue.

Thank you very much for your work.

nene commented 1 month ago

See the FAQ: https://github.com/nene/prettier-plugin-sql-cst?tab=readme-ov-file#how-can-i-format-sql-strings-inside-javascript-files

On Fri, Sep 6, 2024, 21:35 Daniel Steigerwald @.***> wrote:

Maybe I'm blind or dumb, but I cannot enable embedded formatting. I just discovered prettier-plugin-sql, set it up, and it works. And then I found prettier-plugin-sql-cst, and I'm unable to run it for embedded SQL.

Is there some magic setting, or it just doesn't run in monorepo? I don't know; hence, I'm opening issue.

Thank you very much for your work.

— Reply to this email directly, view it on GitHub https://github.com/nene/prettier-plugin-sql-cst/issues/33, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA43OK4WHA3X55XTFVQMCLZVHYYDAVCNFSM6AAAAABNZC6WMGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGUYTAOJZGQ2TMMQ . You are receiving this because you are subscribed to this thread.Message ID: @.> [ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": " https://github.com/nene/prettier-plugin-sql-cst/issues/33", "url": " https://github.com/nene/prettier-plugin-sql-cst/issues/33", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.***": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

steida commented 1 month ago

Of course I read that.

Use prettier-plugin-embed together with prettier-plugin-sql-cst.

I did. It does not work. Sorry if it's obvious.

yield* sqlite.exec(sql`
    alter table evolu_owner
    drop column merkleTree
  `);

This SQL wasn't formatted.

nene commented 1 month ago

Can't say much with so little information. Most likely there's something in how you have configured the embed plugin or the sql-cst plugin. But without seeing the configuration, there's not much I can do.

On Fri, Sep 6, 2024, 23:58 Daniel Steigerwald @.***> wrote:

Of course I read that.

Use prettier-plugin-embed https://github.com/Sec-ant/prettier-plugin-embed together with prettier-plugin-sql-cst.

I did. It does not work. Sorry if it's obvious.

yield* sqlite.exec(sqlalter table evolu_owner drop column merkleTree);

This SQL wasn't formatted.

— Reply to this email directly, view it on GitHub https://github.com/nene/prettier-plugin-sql-cst/issues/33#issuecomment-2334799484, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA43OLIKPVXRBKNZNPTNTDZVIJNLAVCNFSM6AAAAABNZC6WMGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZUG44TSNBYGQ . You are receiving this because you commented.Message ID: @.> [ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": " https://github.com/nene/prettier-plugin-sql-cst/issues/33#issuecomment-2334799484", "url": " https://github.com/nene/prettier-plugin-sql-cst/issues/33#issuecomment-2334799484", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.***": "Organization", "name": "GitHub", "url": " https://github.com" } } ]

steida commented 1 month ago

@nene Can you please make a working example? I don't know what to set; it's not written in readme.

nene commented 1 month ago

I think for the embedded SQL use-case you really only need to add configuration for the embed plugin. Just read the embed plugin docs. Your prettier config file should contain something like this:

{
  "plugins": ["prettier-plugin-embed", "prettier-plugin-sql"],
  "embeddedSqlTags: ["sql"],
  "embeddedSqlPlugin": "prettier-plugin-sql-cst",
  "embeddedSqlParser": "sqlite"
}
steida commented 1 month ago

OK, it was this:

"embeddedSqlPlugin": "prettier-plugin-sql-cst",

Thank you