Skip to content

Instantly share code, notes, and snippets.

@rickcnagy
Created March 11, 2014 20:25
Show Gist options
  • Select an option

  • Save rickcnagy/9494236 to your computer and use it in GitHub Desktop.

Select an option

Save rickcnagy/9494236 to your computer and use it in GitHub Desktop.
Format SQL text in TextMate via sqlformat.org
#!/usr/bin/env ruby
require 'uri'
require 'net/http'
require 'json'
uri = URI("http://sqlformat.org/api/v1/format")
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = false
body = URI.encode_www_form({:sql => "#{ENV['TM_SELECTED_TEXT']}", :reindent => 1})
response = https.post(uri.path, body)
puts JSON.parse(response.body)["result"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment