sql-lint: Postgres' CREATE TYPE not supported

I’d like to use sql-lint on my queries, but upon first try I ran into this problem.

$ node_modules/.bin/sql-lint --query "CREATE TYPE my_type AS ENUM('typeA', 'typeb');"
Can't open file /home/gene/.config/sql-lint/config.json. Does it exist?
query:1 [sql-lint: invalid-create-option] Option 'type' is not a valid option, must be one of '["algorithm","database","definer","event","function","index","or","procedure","server","table","tablespace","temporary","trigger","user","unique","view"]'.

Then I wondered if specifying a --driver would help, guessing maybe that the default is mysql? But that didn’t seem to have any effect:

$ node_modules/.bin/sql-lint --driver postgres --host localhost --user postgres --password password --query "CREATE TYPE my_type AS ENUM('typeA', 'typeb');"
Can't open file /home/gene/.config/sql-lint/config.json. Does it exist?
query:1 [sql-lint: invalid-create-option] Option 'type' is not a valid option, must be one of '["algorithm","database","definer","event","function","index","or","procedure","server","table","tablespace","temporary","trigger","user","unique","view"]'.

(Note that I do have a postgres instance running on localhost:5432, with username/password postgres/password.)

But, I wasn’t even sure if that made any sense. What is the “driver” used for? Does sql-lint connect to the running DB to validate the query?

Is it within scope for sql-lint to support this syntax? If so, what would it take to make that happen? I would consider creating a PR to do it, but I would need some advice on the application architecture and how this could/should be implemented.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

The only thing you should need to do is specify the driver as postgres i.e.

sql-lint --driver postgres some-file.sql

Then it will know to perform the postgres checks instead of the MySQL ones.

No worries either, I fell upon a lot of spare time recently

Hey all,

This should now be resolved. Driver support is uch improved, just head to the releases page and check it out https://github.com/joereynolds/sql-lint/releases

npm install --legacy-peer-deps fixed it for me. Thank you 👍🏻