Files
supabase/apps/studio/data/database-queues/database-queues-query.ts
Ivan Vasilov 54d11a6a7f feat: Queues v0 (#30300)
* Make the title prop on ProjectIntegrationLayout mandatory. Fix the title on some of the integration pages. Fix wrong layout on wrappers/new.

* Add code for the initial page.

* Make the FilterPopover more type-safe.

* Add a page to list message in a single queue.

* Add feature flag for queues.

* Handle the case where pgmq is not available on the database.

* Minor fixes.

* Some minor fixes.

* Fix the query when fetching only archived messages.

* Fix the filters when there's no choices selected.

* Add a comment for local dev.

* Add a max size to the queue name input.
2024-11-08 13:06:05 +01:00

46 lines
1.3 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { executeSql } from 'data/sql/execute-sql-query'
import { ResponseError } from 'types'
import { databaseQueuesKeys } from './keys'
export type DatabaseQueuesVariables = {
projectRef?: string
connectionString?: string
}
export type PostgresQueue = {
queue_name: string
is_partitioned: boolean
is_unlogged: boolean
created_at: string
}
const queueSqlQuery = `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 }: UseQueryOptions<DatabaseQueueData, DatabaseQueueError, TData> = {}
) =>
useQuery<DatabaseQueueData, DatabaseQueueError, TData>(
databaseQueuesKeys.list(projectRef),
() => getDatabaseQueues({ projectRef, connectionString }),
{
enabled: enabled && typeof projectRef !== 'undefined',
...options,
}
)