`<!DOCTYPE html>
Offline SQL Formatter body { font-family: sans-serif; margin: 20px; } textarea { width: 100%; height: 200px; margin-bottom: 10px; font-family: monospace; } button { padding: 10px 20px; font-size: 16px; }
Offline SQL Formatter
Format SQL
// Minimal inlined version of sql-formatter (supports basic SQL formatting)
const sqlFormatter = {
format: function(query) {
if (!query) return "";
// Replace multiple spaces and line breaks
query = query.replace(/\s+/g, " ");
// Add newlines before keywords
const keywords = ["SELECT","FROM","WHERE","GROUP BY","ORDER BY","INSERT INTO","VALUES","UPDATE","SET","DELETE"];
keywords.forEach(k => {
const re = new RegExp("\b" + k + "\b","gi");
query = query.replace(re, "\n" + k);
});
// Clean up extra newlines
query = query.replace(/\n\s+/g,"\n").trim();
return query;
}
};
document.getElementById("formatBtn").addEventListener("click", () => {
const sql = document.getElementById("input").value;
const formatted = sqlFormatter.format(sql);
document.getElementById("output").value = formatted;
});
`
Top comments (0)