Files
supabase/apps/studio/data/database-queues/database-queues-query.ts
Joshen Lim 1baaded0bb Consolidate execute-sql-query into execute-sql-mutation (#46944)
## 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
2026-06-16 00:07:16 +08:00

49 lines
1.4 KiB
TypeScript

import { safeSql } from '@supabase/pg-meta/src/pg-format'
import { useQuery } from '@tanstack/react-query'
import { databaseQueuesKeys } from './keys'
import { executeSql } from '@/data/sql/execute-sql-mutation'
import type { ResponseError, UseCustomQueryOptions } from '@/types'
export type DatabaseQueuesVariables = {
projectRef?: string
connectionString?: string | null
}
export type PostgresQueue = {
queue_name: string
is_partitioned: boolean
is_unlogged: boolean
created_at: string
}
const queueSqlQuery = safeSql`select * from pgmq.list_queues();`
export async function getDatabaseQueues({ projectRef, connectionString }: DatabaseQueuesVariables) {
if (!projectRef) throw new Error('Project ref is required')
const { result } = await executeSql({
projectRef,
connectionString,
sql: queueSqlQuery,
})
return result
}
export type DatabaseQueueData = PostgresQueue[]
export type DatabaseQueueError = ResponseError
export const useQueuesQuery = <TData = DatabaseQueueData>(
{ projectRef, connectionString }: DatabaseQueuesVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<DatabaseQueueData, DatabaseQueueError, TData> = {}
) =>
useQuery<DatabaseQueueData, DatabaseQueueError, TData>({
queryKey: databaseQueuesKeys.list(projectRef),
queryFn: () => getDatabaseQueues({ projectRef, connectionString }),
enabled: enabled && typeof projectRef !== 'undefined',
...options,
})