Files
supabase/apps/studio/data/ai/sql-debug-mutation.ts
T
Ivan Vasilov 436bdb10ae 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.
2023-11-15 12:38:55 +01:00

44 lines
1.1 KiB
TypeScript

import { useMutation, UseMutationOptions } from '@tanstack/react-query'
import { isResponseOk, post } from 'lib/common/fetch'
import { BASE_PATH } from 'lib/constants'
import { ResponseError } from 'types'
export type SqlDebugResponse = {
solution: string
sql: string
}
export type SqlDebugVariables = {
errorMessage: string
sql: string
entityDefinitions?: string[]
}
export async function debugSql({ errorMessage, sql, entityDefinitions }: SqlDebugVariables) {
const response = await post<SqlDebugResponse>(BASE_PATH + '/api/ai/sql/debug', {
errorMessage,
sql,
entityDefinitions,
})
if (!isResponseOk(response)) {
throw response.error
}
return response
}
type SqlDebugData = Awaited<ReturnType<typeof debugSql>>
export const useSqlDebugMutation = ({
onSuccess,
...options
}: Omit<UseMutationOptions<SqlDebugData, ResponseError, SqlDebugVariables>, 'mutationFn'> = {}) => {
return useMutation<SqlDebugData, ResponseError, SqlDebugVariables>((vars) => debugSql(vars), {
async onSuccess(data, variables, context) {
await onSuccess?.(data, variables, context)
},
...options,
})
}