Files
supabase/apps/studio/data/database/indexes-query.ts
T
Ivan Vasilov 436bdb10ae chore: Move the studio app to apps/studio (#18915)
* Move all studio files from /studio to /apps/studio.

* Move studio specific prettier ignores.

* Fix the ui references from studio.

* Fix the css imports.

* Fix all package.json issues.

* Fix the prettier setup for the studio app.

* Add .turbo folder to prettierignore.

* Fix the github workflows.
2023-11-15 12:38:55 +01:00

54 lines
1.2 KiB
TypeScript

import { UseQueryOptions } from '@tanstack/react-query'
import { ExecuteSqlData, useExecuteSqlQuery } from '../sql/execute-sql-query'
import { ResponseError } from 'types'
// [Joshen] Future refactor to move to pg-meta once available
export type DatabaseIndex = {
name: string
schema: string
table: string
definition: string
enabled: boolean
}
export const getIndexesQuery = ({ schema }: { schema: string }) => {
const sql = /* SQL */ `
SELECT schemaname as "schema",
tablename as "table",
indexname as "name",
indexdef as "definition"
FROM pg_indexes
WHERE schemaname = '${schema}';
`.trim()
return sql
}
type getIndexesDefinition = {
schema: string
}
export type IndexesVariables = getIndexesDefinition & {
projectRef?: string
connectionString?: string
}
export type IndexesData = { result: DatabaseIndex[] }
export type IndexesError = unknown
export const useIndexesQuery = <TData extends IndexesData = IndexesData>(
{ schema, projectRef, connectionString }: IndexesVariables,
options: UseQueryOptions<ExecuteSqlData, IndexesError, TData> = {}
) => {
return useExecuteSqlQuery(
{
projectRef,
connectionString,
sql: getIndexesQuery({ schema }),
queryKey: ['indexes', schema],
},
options
)
}