mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35: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
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { safeSql } from '@supabase/pg-meta'
|
|
import { Query } from '@supabase/pg-meta/src/query'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { vaultSecretsKeys } from './keys'
|
|
import { executeSql } from '@/data/sql/execute-sql-mutation'
|
|
import type { ResponseError, UseCustomQueryOptions, VaultSecret } from '@/types'
|
|
|
|
export const getVaultSecretsSql = () => {
|
|
const sql = new Query()
|
|
.from('secrets', 'vault')
|
|
.select(safeSql`id,name,description,secret,created_at,updated_at`)
|
|
.toSql()
|
|
|
|
return sql
|
|
}
|
|
|
|
export type VaultSecretsVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getVaultSecrets(
|
|
{ projectRef, connectionString }: VaultSecretsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const sql = getVaultSecretsSql()
|
|
|
|
const { result } = await executeSql(
|
|
{ projectRef, connectionString, sql, queryKey: ['vault-secrets'] },
|
|
signal
|
|
)
|
|
|
|
return result as VaultSecret[]
|
|
}
|
|
|
|
export type VaultSecretsData = Awaited<ReturnType<typeof getVaultSecrets>>
|
|
export type VaultSecretsError = ResponseError
|
|
|
|
export const useVaultSecretsQuery = <TData = VaultSecretsData>(
|
|
{ projectRef, connectionString }: VaultSecretsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<VaultSecretsData, VaultSecretsError, TData> = {}
|
|
) =>
|
|
useQuery<VaultSecretsData, VaultSecretsError, TData>({
|
|
queryKey: vaultSecretsKeys.list(projectRef),
|
|
queryFn: ({ signal }) => getVaultSecrets({ projectRef, connectionString }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|