Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: fetching single self-hosted views

Alaister Young9cdc37309d84
diff --git a/studio/pages/api/pg-meta/[ref]/materialized-views.ts b/studio/pages/api/pg-meta/[ref]/materialized-views.ts
index 5bd5550dbfa..ed47215e36f 100644
--- a/studio/pages/api/pg-meta/[ref]/materialized-views.ts
+++ b/studio/pages/api/pg-meta/[ref]/materialized-views.ts
@@ -13,6 +13,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
switch (method) {
case 'GET':
+ if (req.query.id) return handleGetOne(req, res)
return handleGetAll(req, res)
default:
res.setHeader('Allow', ['GET'])
@@ -30,3 +31,14 @@ const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {
}
return res.status(200).json(response)
}
+
+const handleGetOne = async (req: NextApiRequest, res: NextApiResponse) => {
+ const headers = constructHeaders(req.headers)
+ let response = await get(`${PG_META_URL}/materialized-views/${req.query.id}`, {
+ headers,
+ })
+ if (response.error) {
+ return res.status(400).json({ error: response.error })
+ }
+ return res.status(200).json(response)
+}
diff --git a/studio/pages/api/pg-meta/[ref]/views.ts b/studio/pages/api/pg-meta/[ref]/views.ts
index aa205be3019..3efbe270ff2 100644
--- a/studio/pages/api/pg-meta/[ref]/views.ts
+++ b/studio/pages/api/pg-meta/[ref]/views.ts
@@ -13,6 +13,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
switch (method) {
case 'GET':
+ if (req.query.id) return handleGetOne(req, res)
return handleGetAll(req, res)
default:
res.setHeader('Allow', ['GET'])
@@ -30,3 +31,14 @@ const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {
}
return res.status(200).json(response)
}
+
+const handleGetOne = async (req: NextApiRequest, res: NextApiResponse) => {
+ const headers = constructHeaders(req.headers)
+ let response = await get(`${PG_META_URL}/views/${req.query.id}`, {
+ headers,
+ })
+ if (response.error) {
+ return res.status(400).json({ error: response.error })
+ }
+ return res.status(200).json(response)
+}