LoginSignup
3
0

More than 5 years have passed since last update.

CLI上で汚いSQLクエリを一撃整形して読みやすくする

Posted at

準備

要node.js環境

環境構築方法は色々あるので、お好みの方法で導入してください。
以下はnodebrewを使う例

Linux
curl -L git.io/nodebrew | perl - setup
Mac
brew install nodebrew
共通
echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
nodebrew install latest
nodebrew use latest

SQLフォーマットツールを導入

Poor Man's T-SQL Formatter - node command-line formatter

導入
npm install --global poor-mans-t-sql-formatter-cli
確認
$ which sqlformat
~/.nodebrew/current/bin/sqlformat

これで準備OK

整形してみる

整形したいSQL文字列を標準入力に流し込めばOK

sqlformat < ugly.sql

整形ルールはオプションで調整可。詳細は以下を参照してください。
Poor Man's T-SQL Formatter - node command-line formatter

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0