mirror of
https://github.com/supabase/supabase.git
synced 2026-07-11 01:23:19 -04:00
1baaded0bb
## 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
49 lines
1.4 KiB
TypeScript
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,
|
|
})
|