mirror of
https://github.com/supabase/supabase.git
synced 2026-10-16 06:39:09 +03:00
* chore(studio): move Query to pgMeta add tests - Move the Query builder from studio to pgMeta - Add e2e tests over the generated sql to ensure syntax and runtime result over pg database - fix bug with orde by for table with undefined column * chore: fix query import path * chore: set ES target for lint * chore: add github action for pg-meta test package * chore: add tsconfig to sparse checkout
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { Query } from '@supabase/pg-meta/src/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,
|
|
}
|
|
)
|