un-ts / prettier

:package: Opinionated but Incredible Prettier plugins.
https://prettier.vercel.app
MIT License
261 stars 23 forks source link

[prettier-plugin-sql] Does this support PostgreSQL meta-commands? #279

Closed takecchi closed 8 months ago

takecchi commented 11 months ago

It seems to produce an error when using PostgreSQL commands like \c or \connect.

test-docker/test-db/init/01_init.sql

-- create db
CREATE DATABASE test_db;

-- connect test_db
\c test_db

-- create schema
CREATE SCHEMA test;

traceback:

test-docker/test-db/init/01_init.sql
[error] test-docker/test-db/init/01_init.sql: Error: Parse error: Unexpected "\c test" at line 5 column 1
[error]     at TokenizerEngine.createParseError (file:///Users/takecchi/PhpstormProjects/test-db/node_modules/sql-formatter/lib/lexer/TokenizerEngine.js:53:12)
[error]     at TokenizerEngine.tokenize (file:///Users/takecchi/PhpstormProjects/test-db/node_modules/sql-formatter/lib/lexer/TokenizerEngine.js:35:22)
[error]     at Tokenizer.tokenize (file:///Users/takecchi/PhpstormProjects/test-db/node_modules/sql-formatter/lib/lexer/Tokenizer.js:16:47)
[error]     at LexerAdapter.tokenize (file:///Users/takecchi/PhpstormProjects/test-db/node_modules/sql-formatter/lib/parser/createParser.js:16:76)
[error]     at LexerAdapter.reset (file:///Users/takecchi/PhpstormProjects/test-db/node_modules/sql-formatter/lib/parser/LexerAdapter.js:17:24)
[error]     at Parser.feed (/Users/takecchi/PhpstormProjects/test-db/node_modules/nearley/lib/nearley.js:281:15)
[error]     at Object.parse (file:///Users/takecchi/PhpstormProjects/test-db/node_modules/sql-formatter/lib/parser/createParser.js:26:18)
[error]     at Formatter.parse (file:///Users/takecchi/PhpstormProjects/test-db/node_modules/sql-formatter/lib/formatter/Formatter.js:32:49)
[error]     at Formatter.format (file:///Users/takecchi/PhpstormProjects/test-db/node_modules/sql-formatter/lib/formatter/Formatter.js:25:22)
[error]     at formatDialect (file:///Users/takecchi/PhpstormProjects/test-db/node_modules/sql-formatter/lib/sqlFormatter.js:77:57)

Do you have any workaround or plans to support it?

JounQin commented 8 months ago

This should be reported to https://github.com/sql-formatter-org/sql-formatter instead.

cc @nene


https://github.com/un-ts/prettier/blob/a8a0ff495b4984928e69f317616196fc21808f2f/packages/sql/package.json#L48

And it seems we are outdated now, sql-formatter v13 has been released, PR welcome to upgrade it and test your failing case.

nene commented 8 months ago

Such meta-commands aren't supported for any SQL dialect by SQL Formatter. Currently there's also no plan to support them either.

Though one could again work around this limitation by using the paramTypes workaround. at least for the simple stuff like \connect. No luck for something like changing the delimiter character.

takecchi commented 8 months ago

I understand that meta-commands are not supported. Thank you for suggesting a workaround! It seems like it will work well.

JounQin commented 8 months ago

https://github.com/un-ts/prettier/issues/233#issuecomment-1803331128

paramTypes will be supported soon.