mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
group columns ahead of time
This commit is contained in:
1 parent
f3e152fd26
commit
fdb5fb57ce
4 files changed
+28
-5
No files matched your search
@@ -37,9 +37,15 @@ export default class ForeignTableStore extends PostgresMetaInterface<Partial<Pos
|
||||
if (columnsResponse.error) throw columnsResponse.error
|
||||
|
||||
// merge 2 response to create the final array
|
||||
const columnsByTableId = (columnsResponse as PostgresColumn[])
|
||||
.reduce((acc, curr) => {
|
||||
acc[curr.table_id] ??= []
|
||||
acc[curr.table_id].push(curr)
|
||||
return acc
|
||||
}, {} as Record<string, PostgresColumn[]>)
|
||||
const foreignTables: PostgresTable[] = []
|
||||
foreignTablesResponse.forEach((foreignTable: PostgresTable) => {
|
||||
const columns = columnsResponse.filter((x: PostgresColumn) => x.table_id === foreignTable.id)
|
||||
const columns = columnsByTableId[foreignTable.id]
|
||||
foreignTables.push({ ...foreignTable, columns })
|
||||
})
|
||||
|
||||
|
||||
@@ -39,9 +39,15 @@ export default class MaterializedViewStore extends PostgresMetaInterface<Postgre
|
||||
if (columnsResponse.error) throw columnsResponse.error
|
||||
|
||||
// merge 2 response to create the final array
|
||||
const columnsByTableId = (columnsResponse as PostgresColumn[])
|
||||
.reduce((acc, curr) => {
|
||||
acc[curr.table_id] ??= []
|
||||
acc[curr.table_id].push(curr)
|
||||
return acc
|
||||
}, {} as Record<string, PostgresColumn[]>)
|
||||
const materializedViews: PostgresMaterializedView[] = []
|
||||
materializedViewsResponse.forEach((materializedView: PostgresMaterializedView) => {
|
||||
const columns = columnsResponse.filter((x: PostgresColumn) => x.table_id === materializedView.id)
|
||||
const columns = columnsByTableId[materializedView.id]
|
||||
materializedViews.push({ ...materializedView, columns })
|
||||
})
|
||||
|
||||
|
||||
@@ -42,10 +42,15 @@ export default class TableStore extends PostgresMetaInterface<PostgresTable> {
|
||||
if (columnsResponse.error) throw columnsResponse.error
|
||||
|
||||
// merge 2 response to create the final array
|
||||
const columnsByTableId = (columnsResponse as PostgresColumn[])
|
||||
.reduce((acc, curr) => {
|
||||
acc[curr.table_id] ??= []
|
||||
acc[curr.table_id].push(curr)
|
||||
return acc
|
||||
}, {} as Record<string, PostgresColumn[]>)
|
||||
const tables: PostgresTable[] = []
|
||||
tablesResponse.forEach((table: PostgresTable) => {
|
||||
const tableId = table.id
|
||||
const columns = columnsResponse.filter((x: PostgresColumn) => x.table_id === tableId)
|
||||
const columns = columnsByTableId[table.id]
|
||||
tables.push({ ...table, columns })
|
||||
})
|
||||
|
||||
|
||||
@@ -37,9 +37,15 @@ export default class ViewStore extends PostgresMetaInterface<SchemaView> {
|
||||
if (columnsResponse.error) throw columnsResponse.error
|
||||
|
||||
// merge 2 response to create the final array
|
||||
const columnsByTableId = (columnsResponse as PostgresColumn[])
|
||||
.reduce((acc, curr) => {
|
||||
acc[curr.table_id] ??= []
|
||||
acc[curr.table_id].push(curr)
|
||||
return acc
|
||||
}, {} as Record<string, PostgresColumn[]>)
|
||||
const views: PostgresView[] = []
|
||||
viewsResponse.forEach((view: PostgresView) => {
|
||||
const columns = columnsResponse.filter((x: PostgresColumn) => x.table_id === view.id)
|
||||
const columns = columnsByTableId[view.id]
|
||||
views.push({ ...view, columns })
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user