mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 10:25:06 +03:00
## Context Related to Dashboard Scalability, specifically having Postgres team as CODEOWNERS for dashboard queries This is just a clean up as we're currently piling manual queries into one folder under `data/sql/queries`, whereas I reckon it'll be better for each query to sit within their RQ folder for better context. Am opting the naming format for files housing queries to be `*.sql.ts`, and also updating CODEOWNERS to reflect as such Next step will also be to shift all the dashboard queries within pg-meta into studio itself as requested by the pg-meta team <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Consolidated and reorganized internal module structure for the data layer to improve maintainability and reduce redundancy. * Streamlined import paths across components to align with new consolidated module organization. * **Chores** * Updated code ownership patterns to reflect reorganized file structure. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Ali Waseem <waseema393@gmail.com>
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { UseCustomQueryOptions } from 'types'
|
|
|
|
import { executeSql, ExecuteSqlError } from '../sql/execute-sql-query'
|
|
import { getDatabaseExtensionDefaultSchemaSQL } from './database-extensions.sql'
|
|
import { databaseExtensionsKeys } from './keys'
|
|
|
|
type DatabaseExtensionDefaultSchemaVariables = {
|
|
extension?: string
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
async function getDatabaseExtensionDefaultSchema(
|
|
{ extension, projectRef, connectionString }: DatabaseExtensionDefaultSchemaVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!extension) {
|
|
throw new Error('extension is required')
|
|
}
|
|
|
|
const sql = getDatabaseExtensionDefaultSchemaSQL({ extension })
|
|
|
|
const { result } = await executeSql(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql,
|
|
queryKey: ['database-extension-default-schema', extension],
|
|
},
|
|
signal
|
|
)
|
|
|
|
return result[0] as { name: string; version: string; schema: string | null }
|
|
}
|
|
|
|
type DatabaseExtensionDefaultSchemaData = Awaited<
|
|
ReturnType<typeof getDatabaseExtensionDefaultSchema>
|
|
>
|
|
type DatabaseExtensionDefaultSchemaError = ExecuteSqlError
|
|
|
|
export const useDatabaseExtensionDefaultSchemaQuery = <TData = DatabaseExtensionDefaultSchemaData>(
|
|
{ projectRef, connectionString, extension }: DatabaseExtensionDefaultSchemaVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<
|
|
DatabaseExtensionDefaultSchemaData,
|
|
DatabaseExtensionDefaultSchemaError,
|
|
TData
|
|
> = {}
|
|
) =>
|
|
useQuery<DatabaseExtensionDefaultSchemaData, DatabaseExtensionDefaultSchemaError, TData>({
|
|
queryKey: databaseExtensionsKeys.defaultSchema(projectRef, extension),
|
|
queryFn: ({ signal }) =>
|
|
getDatabaseExtensionDefaultSchema({ projectRef, connectionString, extension }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined' && typeof extension !== 'undefined',
|
|
...options,
|
|
})
|