mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
## 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
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { replicationLagSql } from '@supabase/pg-meta'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { replicaKeys } from './keys'
|
|
import { executeSql } from '@/data/sql/execute-sql-mutation'
|
|
import { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type ReplicationLagVariables = {
|
|
id: string
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getReplicationLag(
|
|
{ projectRef, connectionString, id }: ReplicationLagVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const sql = replicationLagSql()
|
|
|
|
const { result } = await executeSql(
|
|
{ projectRef, connectionString, sql, queryKey: ['replica-lag', id] },
|
|
signal
|
|
)
|
|
|
|
return Number((result[0] ?? null)?.physical_replica_lag_second ?? 0)
|
|
}
|
|
|
|
export type ReplicationLagData = Awaited<ReturnType<typeof getReplicationLag>>
|
|
export type ReplicationLagError = ResponseError
|
|
|
|
export const useReplicationLagQuery = <TData = ReplicationLagData>(
|
|
{ projectRef, connectionString, id }: ReplicationLagVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<ReplicationLagData, ReplicationLagError, TData> = {}
|
|
) =>
|
|
useQuery<ReplicationLagData, ReplicationLagError, TData>({
|
|
queryKey: replicaKeys.replicaLag(projectRef, id),
|
|
queryFn: ({ signal }) => getReplicationLag({ projectRef, connectionString, id }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined' && typeof id !== 'undefined',
|
|
...options,
|
|
})
|