mirror of
https://github.com/supabase/supabase.git
synced 2026-06-08 02:25:04 +08:00
chore: Move the studio app to apps/studio (#18915)
* Move all studio files from /studio to /apps/studio. * Move studio specific prettier ignores. * Fix the ui references from studio. * Fix the css imports. * Fix all package.json issues. * Fix the prettier setup for the studio app. * Add .turbo folder to prettierignore. * Fix the github workflows.
This commit is contained in:
45
apps/studio/data/sql/format-sql-query.ts
Normal file
45
apps/studio/data/sql/format-sql-query.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
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,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user