Created
April 15, 2015 15:44
-
-
Save andialbrecht/8112ac0e354354b4aaff to your computer and use it in GitHub Desktop.
Minimal SQL Format Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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