The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
add fetchData for relational stores
Bobbie Soedirgof3e152fd2661
diff --git a/studio/stores/pgmeta/ForeignTableStore.ts b/studio/stores/pgmeta/ForeignTableStore.tsindex 70282372e01..b216e7131b1 100644--- a/studio/stores/pgmeta/ForeignTableStore.ts+++ b/studio/stores/pgmeta/ForeignTableStore.ts@@ -1,4 +1,4 @@-import type { PostgresTable } from '@supabase/postgres-meta'+import type { PostgresColumn, PostgresTable } from '@supabase/postgres-meta'import { get } from 'lib/common/fetch'import { ResponseError } from 'types'import PostgresMetaInterface, { IPostgresMetaInterface } from '../common/PostgresMetaInterface'@@ -20,6 +20,33 @@ export default class ForeignTableStore extends PostgresMetaInterface<Partial<Possuper(rootStore, dataUrl, headers, options)}+ // Customize ForeignTableStore fetchData method to improve request performance+ async fetchData() {+ const headers = { 'Content-Type': 'application/json', ...this.headers }+ // load all foreign tables w/o columns info+ const _url = new URL(this.url)+ _url.searchParams.set('include_columns', 'false')+ const url = `${_url}`+ // load all columns+ const urlColumns = this.url.replace('/foreign-tables', '/columns')+ const [foreignTablesResponse, columnsResponse] = await Promise.all([+ get(url, { headers }),+ get(urlColumns, { headers }),+ ])+ if (foreignTablesResponse.error) throw foreignTablesResponse.error+ if (columnsResponse.error) throw columnsResponse.error++ // merge 2 response to create the final array+ const foreignTables: PostgresTable[] = []+ foreignTablesResponse.forEach((foreignTable: PostgresTable) => {+ const columns = columnsResponse.filter((x: PostgresColumn) => x.table_id === foreignTable.id)+ foreignTables.push({ ...foreignTable, columns })+ })++ this.setDataArray(foreignTables)+ return foreignTables as any+ }+// loadBySchema is not supported in this storeasync loadBySchema(schema: string) {return []diff --git a/studio/stores/pgmeta/MaterializedViewStore.ts b/studio/stores/pgmeta/MaterializedViewStore.tsindex 96d81b3ceb4..9b2d0ed77c2 100644--- a/studio/stores/pgmeta/MaterializedViewStore.ts+++ b/studio/stores/pgmeta/MaterializedViewStore.ts@@ -1,4 +1,4 @@-import { PostgresMaterializedView } from '@supabase/postgres-meta'+import { PostgresColumn, PostgresMaterializedView } from '@supabase/postgres-meta'import { ResponseError } from 'types'import PostgresMetaInterface, { IPostgresMetaInterface } from '../common/PostgresMetaInterface'import { IRootStore } from '../RootStore'@@ -22,6 +22,33 @@ export default class MaterializedViewStore extends PostgresMetaInterface<Postgresuper(rootStore, dataUrl, headers, options)}+ // Customize MaterializedViewStore fetchData method to improve request performance+ async fetchData() {+ const headers = { 'Content-Type': 'application/json', ...this.headers }+ // load all materialized views w/o columns info+ const _url = new URL(this.url)+ _url.searchParams.set('include_columns', 'false')+ const url = `${_url}`+ // load all columns+ const urlColumns = this.url.replace('/materialized-views', '/columns')+ const [materializedViewsResponse, columnsResponse] = await Promise.all([+ get(url, { headers }),+ get(urlColumns, { headers }),+ ])+ if (materializedViewsResponse.error) throw materializedViewsResponse.error+ if (columnsResponse.error) throw columnsResponse.error++ // merge 2 response to create the final array+ const materializedViews: PostgresMaterializedView[] = []+ materializedViewsResponse.forEach((materializedView: PostgresMaterializedView) => {+ const columns = columnsResponse.filter((x: PostgresColumn) => x.table_id === materializedView.id)+ materializedViews.push({ ...materializedView, columns })+ })++ this.setDataArray(materializedViews)+ return materializedViews as any+ }+async loadById(id: number | string) {try {const url = `${this.url}?id=${id}`diff --git a/studio/stores/pgmeta/TableStore.ts b/studio/stores/pgmeta/TableStore.tsindex dec9b66cc9d..7571e848bd7 100644--- a/studio/stores/pgmeta/TableStore.ts+++ b/studio/stores/pgmeta/TableStore.ts@@ -45,7 +45,7 @@ export default class TableStore extends PostgresMetaInterface<PostgresTable> {const tables: PostgresTable[] = []tablesResponse.forEach((table: PostgresTable) => {const tableId = table.id- const columns = columnsResponse.find((x: PostgresColumn) => x.table_id === tableId)+ const columns = columnsResponse.filter((x: PostgresColumn) => x.table_id === tableId)tables.push({ ...table, columns })})diff --git a/studio/stores/pgmeta/ViewStore.ts b/studio/stores/pgmeta/ViewStore.tsindex 56067240562..ae83f4482c4 100644--- a/studio/stores/pgmeta/ViewStore.ts+++ b/studio/stores/pgmeta/ViewStore.ts@@ -2,6 +2,7 @@ import { ResponseError, SchemaView } from 'types'import PostgresMetaInterface, { IPostgresMetaInterface } from '../common/PostgresMetaInterface'import { IRootStore } from '../RootStore'import { get } from 'lib/common/fetch'+import { PostgresColumn, PostgresView } from '@supabase/postgres-meta'export interface IViewStore extends IPostgresMetaInterface<SchemaView> {loadById: (id: number | string) => Promise<Partial<SchemaView> | { error: ResponseError }>@@ -19,6 +20,33 @@ export default class ViewStore extends PostgresMetaInterface<SchemaView> {super(rootStore, dataUrl, headers, options)}+ // Customize ViewStore fetchData method to improve request performance+ async fetchData() {+ const headers = { 'Content-Type': 'application/json', ...this.headers }+ // load all views w/o columns info+ const _url = new URL(this.url)+ _url.searchParams.set('include_columns', 'false')+ const url = `${_url}`+ // load all columns+ const urlColumns = this.url.replace('/views', '/columns')+ const [viewsResponse, columnsResponse] = await Promise.all([+ get(url, { headers }),+ get(urlColumns, { headers }),+ ])+ if (viewsResponse.error) throw viewsResponse.error+ if (columnsResponse.error) throw columnsResponse.error++ // merge 2 response to create the final array+ const views: PostgresView[] = []+ viewsResponse.forEach((view: PostgresView) => {+ const columns = columnsResponse.filter((x: PostgresColumn) => x.table_id === view.id)+ views.push({ ...view, columns })+ })++ this.setDataArray(views as any)+ return views as any+ }+async loadById(id: number | string) {try {const url = `${this.url}?id=${id}`