mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## Context Just some clean up as I was going through stuff - `useExecuteSqlQuery` is deprecated and not used at all - As such `execute-sql-query` is technically irrelevant, the more relevant file is `execute-sql-mutation` - Hence opting to consolidate `execute-sql-query` into `execute-sql-mutation` - Also removing `ExecuteSqlError` since its just re-exporting the `ResponseError` type There's a lot of file changes but its essentially just updating the importing statements across the files
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { buildDefaultPrivilegesSql } from '@supabase/pg-meta'
|
|
import { useMutation } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import type { ConnectionVars } from '@/data/common.types'
|
|
import { executeSql } from '@/data/sql/execute-sql-mutation'
|
|
import type { UseCustomMutationOptions } from '@/types'
|
|
|
|
export type UpdateDefaultPrivilegesVariables = ConnectionVars & {
|
|
granted: boolean
|
|
}
|
|
|
|
export async function updateDefaultPrivileges({
|
|
projectRef,
|
|
connectionString,
|
|
granted,
|
|
}: UpdateDefaultPrivilegesVariables): Promise<void> {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const sql = buildDefaultPrivilegesSql(granted ? 'grant' : 'revoke')
|
|
|
|
await executeSql({
|
|
projectRef,
|
|
connectionString,
|
|
sql,
|
|
queryKey: ['update-default-privileges'],
|
|
})
|
|
}
|
|
|
|
type UpdateDefaultPrivilegesData = Awaited<ReturnType<typeof updateDefaultPrivileges>>
|
|
|
|
export const useUpdateDefaultPrivilegesMutation = ({
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<UpdateDefaultPrivilegesData, Error, UpdateDefaultPrivilegesVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
return useMutation<UpdateDefaultPrivilegesData, Error, UpdateDefaultPrivilegesVariables>({
|
|
mutationFn: (vars: UpdateDefaultPrivilegesVariables) => updateDefaultPrivileges(vars),
|
|
onError(error: Error) {
|
|
toast.error(`Failed to update default privileges: ${error.message}`)
|
|
},
|
|
...(onError ? { onError } : {}),
|
|
...options,
|
|
})
|
|
}
|