Skip to content

Instantly share code, notes, and snippets.

@chrismo
Last active December 12, 2022 02:13
Show Gist options
  • Save chrismo/ff00f2e6409b22e73ef7 to your computer and use it in GitHub Desktop.
Save chrismo/ff00f2e6409b22e73ef7 to your computer and use it in GitHub Desktop.
Sequel Pro Format Sql Bundle
ruby formatsql.rb "$(cat)"
# put this in ~/Library/Application Support/Sequel Pro/Bundles/Format SQL.spBundle
require 'net/http'
require 'json'
uri = URI('http://www.gudusoft.com/format.php')
opts = {"capitalization"=>{"keywords"=>{"fmt100_case_keyword"=>"lower"}, "tableName"=>{"fmt105_case_table_name"=>"lower"}}}
# API details: https://github.com/sqlparser/sql-pretty-printer/wiki/SQL-FaaS-API-manual
res = Net::HTTP.post_form(uri, 'rqst_input_sql' => ARGV[0], 'rspn_db_vendor' => 'mysql', 'rqst_formatOptions' => opts.to_json)
puts JSON.parse(res.body)['rspn_formatted_sql']
@gvaughn
Copy link

gvaughn commented Jan 5, 2015

and where does the formatsql.rb file live?

@chrismo
Copy link
Author

chrismo commented Jan 5, 2015

Ah, I put that in the original location of the bundle files, which is ... ~/Library/Application Support/Sequel Pro/Bundles/Format SQL.spBundle

@gvaughn
Copy link

gvaughn commented Jan 5, 2015

In the Bundles folder, right? That .spBundle file is a file.

@chrismo
Copy link
Author

chrismo commented Jan 12, 2015

On my box it's a dir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment