Skip to content

Instantly share code, notes, and snippets.

@andialbrecht
Created April 15, 2015 15:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andialbrecht/8112ac0e354354b4aaff to your computer and use it in GitHub Desktop.
Save andialbrecht/8112ac0e354354b4aaff to your computer and use it in GitHub Desktop.
Minimal SQL Format Example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>SQLFormat API Example</title>
<!-- Include JQuery library -->
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
</head>
<body>
<!-- A very minimal UI -->
<p>This example shows how to call the sqlformat.org API using jQuery.</p>
<textarea id="sql">select * from foo</textarea><br />
<button id="format">Format statement (JSON)</button>
<hr />
<strong>The result:</strong><br />
<pre id="result"></pre>
<!-- This has to come at the bottom, otherwise #format and all other -->
<!-- aren't defined. -->
<script type="text/javascript">
// Callback function for the AJAX requests below.
// This updates the result in the UI.
function onSuccess(data) { $('#result').text(data['result']); }
// Call the formatter API.
$('#format').click(function() {
$.ajax({
url: 'http://sqlformat.org/api/v1/format',
type: 'POST',
dataType: 'json',
crossDomain: true,
data: {sql: $('#sql').val(), reindent: 1},
success: onSuccess,
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment