Files
supabase/apps/studio/lib/formatSql.ts
Ivan Vasilov 98ca85156a chore: Use sql-formatter for formatting all SQL in the studio (#33071)
* Bump the sql-formatter dependency.

* Add a function formatQuery which is a wrapper around sql-formatter.

* Replace all formatSQL features to use the new function formatSql.

* Remove unneeded RQ for formatting.

* Small fix.
2025-01-27 13:04:31 +01:00

18 lines
467 B
TypeScript

import { format } from 'sql-formatter'
/**
* Util function for formatting SQL. It wraps the `sql-formatter` library with a preset format options so that the
* formatting is consistent across the app. It also has a try/catch block which returns the original SQL in case of
* an error.
*/
export const formatSql = (sql: string) => {
try {
return format(sql, {
language: 'postgresql',
keywordCase: 'lower',
})
} catch {
return sql
}
}