Giter VIP home page Giter VIP logo

format-sql's Introduction

SQL Formatter

An AutoHokey/NodeJS script to automatically format SQL code upon a hotkey press.
The JavaScript side of this is also doable just fine in AHK, but I was just into testing out new stuff in js when I made this, so yeah.
I will probably push a future commit at one point to just remove the whole NodeJS side of this.

This works by making a web request to dpdriver's online SQL formatter. I was looking for an SQL formatter to use, and out of everything I found, I really liked theirs best. So I had to make something to use is to format my SQL on the fly.
Downside is of course latency/privacy. It'll take a bit to get a response from their server, but I'm fine this.

image

Installing

AutoHotkey is Windows only!

  • Install AutoHotkey
  • Install NodeJS
  • Clone this repository
    git clone https://github.com/0x464e/format-sql
  • Install the required Node packages from package.json by running npm install

Configuration

Hotkey restriction

I have set the used hotkey to only work when SQL Server Management Studio is the active window, because that's where I'm writing my SQL.
To change this, you'll want to change this part in the AHK code:

#IfWinActive, ahk_exe Ssms.exe
...
#IfWinActive

I'm matching a window that's running from Ssms.exe process.
If you want to match a different window, consult the AHK documentation here and make the necessary changes, or remove this part altogether so the hotkey works anywhere.

Hotkey configuration

I have set the hotkey to Ctrl+p (who needs a print hotkey?) with ^p.
To change this, consult the AHK documentation page here for how the hotkey syntax works in AHK.

Formatting options

Dpdriver's online SQL formatter is configurable with a number of different options, you can test the options in their site here and then change the options however you see fit in the index.js file.
The options are visible in the XML request.

System tray icon

Uncomment line 2 in FormatSQL.ahk to not have an AHK tray icon when the script is running.

Usage

Launch the AHK script by just double clicking your .ahk file.
(If the AHK installation would've somehow failed to associate .ahk files with the AHK interpreter, you can manually run .ahk files by just passing in the file to the interpreter, which is found in your AHK installation directory (usually C:\Program Files\AutoHotkey\AutoHotkey.exe))
Highlight your desired SQL code and press your Hotkey.
The formatted SQL will automatically be pasted on top of your old SQL.

format-sql's People

Contributors

0x464e avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

shahhimtest

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.