Giter Site home page Giter Site logo

sql-formatter-cli's Introduction

Console util for formatting SQL using lib sql-formatter. Zero dependencies


Not maintained

This package is not maintained anymore because sql-formatter contains command line client too now. Install sql-formatter and refer to it's manual how to use it.

SYNOPSIS

$ sql-formatter-cli -h
SQL formatter

Options:
  -i, --file  Load a file. "-" - stdin                                                                       [default: "-"]
  -s, --sql   Sql dialect: "sql" Standard SQL, "n1ql" Couchbase N1QL, "db2" IBM DB2, "pl/sql" Oracle PL/SQL  [default: "sql"]
  -o, --out   Output file name. "-" - stdout                                                                 [default: "-"]

$ echo "SELECT * FROM databases WHERE category='NoSQL'" | sql-formatter-cli
SELECT
  *
FROM
  databases
WHERE
  category = 'NoSQL'

INSTALL

This tool require Node.js to be installed. After you can install using npm:

npm i -g sql-formatter-cli

THANKS

Many thanks to authors of sql-formatter lib. I spent few hours for searching SQL query prettifier but most of them was awful or require JAVA/ruby (I failed to add "comma last" for anbt-sql-formatter).

The reason why I don't create PR for adding cli for sql-formatter lib is that sql-formatter use lodash dependency while I want to have minified version without any dependencies what is done by rollup :)

EMACS SNIPPET

Here you can find more, but below is config that I use for formatting selected region.

  (defun sql-beautify-region (beg end)
    "Beautify SQL in region between beg and END.
Dependency:
npm i -g sql-formatter-cli"
    (interactive "r")
    (save-excursion
      (shell-command-on-region beg end "sql-formatter-cli" nil t)))
  (defun sql-beautify-buffer ()
    "Beautify SQL in buffer."
    (interactive)
    (sql-beautify-region (point-min) (point-max)))
  (add-hook 'sql-mode-hook '(lambda ()
                              ;; beautify region or buffer
                              (local-set-key (kbd "C-c t") 'sql-beautify-region)))

TODO

  • Add version option support
  • Add integrity tests
  • Use yarn instead of npm

sql-formatter-cli's People

Contributors

dependabot[bot] avatar osv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sql-formatter-cli's Issues

There is wrong link to the github url for project on NPM Site

As I was going through this amazing utility, I wanted to extend the functionality a bit but was ard time finding the GitHub repository link on npmjs.com.

There seems to be some wrong url in the repository link for this project.

Can you please update that @osv

Thanks

Output is empty

Hello,

I use this script : find database-schema -name *.sql -exec sql-formatter-cli -i {} -o {} \;
I run the script in a git precommit step.
Randomly , the output file is empty. Have you ideas why the output could be empty file and how to prevent it ?

Thanks

Handling of comments seems broken.

Given the following SQL:

-- This is the first statement
select * from foo where color = "purple";

-- This is the second statement
select * from foo join bar on foo.id = bar.foo_id where bar.count > 100;

sql-formatter-cli produces the following output:

-- This is the first statement
select
  *
from
  foo
where
  color = "purple";-- This is the second statement
select
  *
from
  foo
  join bar on foo.id = bar.foo_id
where
  bar.count > 100;

Note how the second comment has been appended to the final line of the
previous SQL statement. That seems erroneous. If there were an option
to preserve whitespace (such as the blank line separating the second
comment from the previous statement), this would probably be correct.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.