sql-format Format SQL queries
Flags
--dialect select: sql | mysql | postgresql | mariadb | bigquery | sqlite | transactsql | plsql default: sql
Examples
Format a SQL query with proper indentation
Usage
"SELECT u.name, u.email FROM users u JOIN orders o ON u.id = ..." | sql-format Clean up a messy query from a support ticket
Usage
"select * from customers where status='active' and plan in ('..." | sql-format Format a SQL insert statement for documentation
Usage
"INSERT INTO events (name, date, location) VALUES ('Launch Pa..." | sql-format View source
async (input, opts = {})=>{
try {
const { format } = await import('sql-formatter').then(async (m)=>{
await m.__tla;
return m;
});
return format(input, {
language: opts.dialect || "sql"
});
} catch (e) {
return `Error: ${e.message}`;
}
}