mirror of
https://github.com/supabase/supabase.git
synced 2026-07-03 22:54:19 +08:00
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import { UseQueryOptions } from '@tanstack/react-query'
|
|
import { ExecuteSqlData, useExecuteSqlQuery } from '../sql/execute-sql-query'
|
|
|
|
export type DatabaseKeyword = { word: string }
|
|
|
|
export const getKeywordsQuery = () => {
|
|
const sql = /* SQL */ `
|
|
SELECT word FROM pg_get_keywords();
|
|
`.trim()
|
|
|
|
return sql
|
|
}
|
|
|
|
export type KeywordsVariables = {
|
|
projectRef?: string
|
|
connectionString?: string
|
|
}
|
|
|
|
export type KeywordsData = { result: string[] }
|
|
export type KeywordsError = unknown
|
|
|
|
export const useKeywordsQuery = <TData extends KeywordsData = KeywordsData>(
|
|
{ projectRef, connectionString }: KeywordsVariables,
|
|
options: UseQueryOptions<ExecuteSqlData, KeywordsError, TData> = {}
|
|
) => {
|
|
return useExecuteSqlQuery(
|
|
{
|
|
projectRef,
|
|
connectionString,
|
|
sql: getKeywordsQuery(),
|
|
queryKey: ['keywords'],
|
|
},
|
|
{
|
|
select: (data) => {
|
|
return {
|
|
result: data.result.map((x: DatabaseKeyword) => x.word.toLocaleLowerCase()),
|
|
} as any
|
|
},
|
|
...options,
|
|
}
|
|
)
|
|
}
|