mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 22:29:11 +03:00
* fix(studio): early fail query when x-connection-encrypted is invalid * fix(studio): uniformize readDatabase and projectDetails connString handling * chore: update api types * chore: add connectionString null option * fix: only enforce x-connection-encrypted on platform * chore: refactor connString check in a single point * chore: fix guard logic * chore: fix pgMetaGuard * chore: fix types
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { executeSql } from 'data/sql/execute-sql-query'
|
|
import { ResponseError } from 'types'
|
|
import { databaseCronJobsKeys } from './keys'
|
|
|
|
export type DatabaseCronJobsVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getDatabaseCronTimezone({
|
|
projectRef,
|
|
connectionString,
|
|
}: DatabaseCronJobsVariables) {
|
|
if (!projectRef) throw new Error('Project ref is required')
|
|
|
|
const { result } = await executeSql({
|
|
projectRef,
|
|
connectionString,
|
|
sql: `select setting from pg_settings where name = 'cron.timezone';`,
|
|
})
|
|
return result[0].setting
|
|
}
|
|
|
|
export type DatabaseCronJobError = ResponseError
|
|
|
|
export const useCronTimezoneQuery = <TData = string>(
|
|
{ projectRef, connectionString }: DatabaseCronJobsVariables,
|
|
{ enabled = true, ...options }: UseQueryOptions<string, DatabaseCronJobError, TData> = {}
|
|
) =>
|
|
useQuery<string, DatabaseCronJobError, TData>(
|
|
databaseCronJobsKeys.timezone(projectRef),
|
|
() => getDatabaseCronTimezone({ projectRef, connectionString }),
|
|
{
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|