mirror of
https://github.com/supabase/supabase.git
synced 2026-06-20 21:16:00 +08:00
* 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.
18 lines
467 B
TypeScript
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
|
|
}
|
|
}
|