mirror of
https://github.com/supabase/supabase.git
synced 2026-09-07 02:20:52 +08: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
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { getKeywordsSql } from '@supabase/pg-meta'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { databaseKeys } from './keys'
|
|
import { executeSql } from '@/data/sql/execute-sql-mutation'
|
|
import { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type KeywordsVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getKeywords(
|
|
{ projectRef, connectionString }: KeywordsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const sql = getKeywordsSql()
|
|
|
|
const { result } = await executeSql(
|
|
{ projectRef, connectionString, sql, queryKey: ['keywords'] },
|
|
signal
|
|
)
|
|
|
|
return result.map((x: { word: string }) => x.word.toLocaleLowerCase()) as string[]
|
|
}
|
|
|
|
export type KeywordsData = Awaited<ReturnType<typeof getKeywords>>
|
|
export type KeywordsError = ResponseError
|
|
|
|
export const useKeywordsQuery = <TData = KeywordsData>(
|
|
{ projectRef, connectionString }: KeywordsVariables,
|
|
{ enabled = true, ...options }: UseCustomQueryOptions<KeywordsData, KeywordsError, TData> = {}
|
|
) =>
|
|
useQuery<KeywordsData, KeywordsError, TData>({
|
|
queryKey: databaseKeys.keywords(projectRef),
|
|
queryFn: ({ signal }) => getKeywords({ projectRef, connectionString }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|