The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
detect if wrappers are enabled
Alaister Youngf35e21b190f8
diff --git a/studio/components/interfaces/Database/Wrappers/Wrappers.tsx b/studio/components/interfaces/Database/Wrappers/Wrappers.tsxindex ea66fcea2f4..79a975b6a13 100644--- a/studio/components/interfaces/Database/Wrappers/Wrappers.tsx+++ b/studio/components/interfaces/Database/Wrappers/Wrappers.tsx@@ -1,9 +1,23 @@+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'+import { useFDWsQuery } from 'data/fdw/fdws-query'import { wrappers } from './data'import WrapperCard from './WrapperCard'const Wrappers = () => {- const enabledWrappers: any[] = []- const disabledWrappers = wrappers+ const { project } = useProjectContext()+ const { data, isLoading } = useFDWsQuery({+ projectRef: project?.ref,+ connectionString: project?.connectionString,+ })++ const enabledWrapperNamesSet = new Set(data?.result.map((fdw) => fdw.name))++ const enabledWrappers = wrappers.filter((wrapper) =>+ enabledWrapperNamesSet.has(wrapper.server.name)+ )+ const disabledWrappers = wrappers.filter(+ (wrapper) => !enabledWrapperNamesSet.has(wrapper.server.name)+ )return (<>diff --git a/studio/data/fdw/fdw-create-mutation.ts b/studio/data/fdw/fdw-create-mutation.tsindex 3772f446b9b..65fb878e20c 100644--- a/studio/data/fdw/fdw-create-mutation.ts+++ b/studio/data/fdw/fdw-create-mutation.ts@@ -1,6 +1,7 @@import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'import { AvailableColumn, Wrapper } from 'components/interfaces/Database/Wrappers/types'import { executeSql } from 'data/sql/execute-sql-query'+import { sqlKeys } from 'data/sql/keys'export type FDWCreateVariables = {projectRef?: string@@ -137,7 +138,7 @@ export const useFDWCreateMutation = ({return useMutation<FDWCreateData, unknown, FDWCreateVariables>((vars) => createFDW(vars), {async onSuccess(data, variables, context) {- // await queryClient.invalidateQueries(sqlKeys.query(projectRef, [table.schema, table.name]))+ await queryClient.invalidateQueries(sqlKeys.query(variables.projectRef, ['fdws']))await onSuccess?.(data, variables, context)},diff --git a/studio/data/fdw/fdws-query.ts b/studio/data/fdw/fdws-query.tsnew file mode 100644index 00000000000..f5b95f2904c--- /dev/null+++ b/studio/data/fdw/fdws-query.ts@@ -0,0 +1,53 @@+import { UseQueryOptions } from '@tanstack/react-query'+import { ExecuteSqlData, useExecuteSqlPrefetch, useExecuteSqlQuery } from '../sql/execute-sql-query'++export const getFDWsSql = () => {+ const sql = /* SQL */ `+ select+ oid as id,+ srvname as name+ from pg_catalog.pg_foreign_server;+ `++ return sql+}++export type FDW = {+ id: string+ name: string+}++export type FDWsResponse = {+ result: FDW[]+}++export type FDWsVariables = {+ projectRef?: string+ connectionString?: string+}++export type FDWsData = FDWsResponse+export type FDWsError = unknown++export const useFDWsQuery = <TData extends FDWsData = FDWsData>(+ { projectRef, connectionString }: FDWsVariables,+ options: UseQueryOptions<ExecuteSqlData, FDWsError, TData> = {}+) =>+ useExecuteSqlQuery(+ {+ projectRef,+ connectionString,+ sql: getFDWsSql(),+ queryKey: ['fdws'],+ },+ options+ )++export const useFDWsPrefetch = ({ projectRef, connectionString }: FDWsVariables) => {+ return useExecuteSqlPrefetch({+ projectRef,+ connectionString,+ sql: getFDWsSql(),+ queryKey: ['fdws'],+ })+}