Skip to content

Instantly share code, notes, and snippets.

@chrismo
Last active December 12, 2022 02:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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']
@chrismo
Copy link
Author

chrismo commented Jan 5, 2015

The 'bundle editor.sh' file is the contents to put into the Command text box of the Bundle Editor. It removes the code that warns this data is being sent in the clear over the internets, so if you still care about that you'll have to dig that out of the original shell Command. here

The gudusoft.com is the current endpoint for the prior dpriver.com functionality.

@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