mirror of
https://github.com/supabase/supabase.git
synced 2026-10-16 14:49:10 +03:00
* foreign-key-constraints * update entity-types stale time * schemas query * deprecate useExecuteSqlQuery * users count query * database size query * indexes query * keywords query * migrations query * table columns * database functions * database roles query * fdws query * replication lag query * ongoing queries query * vault secrets query * remove unneeded staleTime: 0 * max connections query * fix entity types key in tests * Some fixes --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { Query } from 'components/grid/query/Query'
|
|
import type { VaultSecret } from 'types'
|
|
import { executeSql, ExecuteSqlError } from '../sql/execute-sql-query'
|
|
import { vaultSecretsKeys } from './keys'
|
|
|
|
export const getVaultSecretsSql = () => {
|
|
const sql = new Query()
|
|
.from('secrets', 'vault')
|
|
.select('id,name,description,secret,key_id,created_at,updated_at')
|
|
.toSql()
|
|
|
|
return sql
|
|
}
|
|
|
|
export type VaultSecretsVariables = {
|
|
projectRef?: string
|
|
connectionString?: string
|
|
}
|
|
|
|
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 = ExecuteSqlError
|
|
|
|
export const useVaultSecretsQuery = <TData = VaultSecretsData>(
|
|
{ projectRef, connectionString }: VaultSecretsVariables,
|
|
{ enabled = true, ...options }: UseQueryOptions<VaultSecretsData, VaultSecretsError, TData> = {}
|
|
) =>
|
|
useQuery<VaultSecretsData, VaultSecretsError, TData>(
|
|
vaultSecretsKeys.list(projectRef),
|
|
({ signal }) => getVaultSecrets({ projectRef, connectionString }, signal),
|
|
{
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|