mirror of
https://github.com/supabase/supabase.git
synced 2026-05-23 01:39:34 +08:00
* Update * Clean up + fix UI * Add data values to tab * Add comment * Format sql query in query details * Clean uo * Deprecate old files * Address comments * chore: update styles (#22591) * Add feature flag, reinstate old UI for feature flag * Update apps/studio/components/interfaces/QueryPerformanceV2/QueryPerformance.tsx Co-authored-by: Alaister Young <alaister@users.noreply.github.com> * Update apps/studio/components/interfaces/QueryPerformance/QueryPerformance.tsx Co-authored-by: Alaister Young <alaister@users.noreply.github.com> * Address feedback --------- Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com> Co-authored-by: Alaister Young <alaister@users.noreply.github.com>
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { useMutation, UseMutationOptions } from '@tanstack/react-query'
|
|
import { post } from 'lib/common/fetch'
|
|
import { API_URL } from 'lib/constants'
|
|
|
|
export type FormatQueryVariables = {
|
|
projectRef: string
|
|
sql: string
|
|
connectionString?: string
|
|
}
|
|
|
|
export async function formatQuery(
|
|
{ projectRef, connectionString, sql }: FormatQueryVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
let headers = new Headers()
|
|
|
|
if (connectionString) headers.set('x-connection-encrypted', connectionString)
|
|
|
|
const response = await post(
|
|
`${API_URL}/pg-meta/${projectRef}/query/format`,
|
|
{ query: sql },
|
|
{ headers: Object.fromEntries(headers), signal }
|
|
)
|
|
if (response.error) throw response.error
|
|
return { result: response }
|
|
}
|
|
|
|
type FormatQueryData = Awaited<ReturnType<typeof formatQuery>>
|
|
|
|
export const useFormatQueryMutation = ({
|
|
onSuccess,
|
|
...options
|
|
}: Omit<UseMutationOptions<FormatQueryData, unknown, FormatQueryVariables>, 'mutationFn'> = {}) => {
|
|
return useMutation<FormatQueryData, unknown, FormatQueryVariables>((args) => formatQuery(args), {
|
|
async onSuccess(data, variables, context) {
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
...options,
|
|
})
|
|
}
|