mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 23:19:23 +08:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? - Move storage tests to run in parallel - Updated utils to use env <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Improved test reliability by shifting storage bucket setup and cleanup from UI-based to API-backed operations. * Enhanced test isolation with streamlined prerequisite navigation steps. * **Chores** * Updated environment configuration to support dynamic API URL and service role key settings. * Refactored internal storage management utilities for improved maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
31 lines
976 B
TypeScript
31 lines
976 B
TypeScript
import { env } from "../../env.config.js"
|
|
|
|
/**
|
|
* Execute a SQL query against the local Supabase database via pg-meta.
|
|
*
|
|
* Uses the local Supabase API gateway to route to pg-meta, which executes
|
|
* the query against PostgreSQL using the default local connection.
|
|
*
|
|
* @param sql - The SQL query to execute
|
|
* @param params - Optional array of parameters for parameterized queries
|
|
* @returns Array of result rows
|
|
* @throws Error if the query fails
|
|
*/
|
|
export async function query<T>(sql: string, params?: Array<unknown>): Promise<Array<T>> {
|
|
const response = await fetch(`${env.API_URL}/pg/query`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
apikey: env.SERVICE_ROLE_KEY,
|
|
},
|
|
body: JSON.stringify({ query: sql, parameters: params }),
|
|
})
|
|
|
|
if (!response.ok) {
|
|
const error = await response.json()
|
|
throw new Error(`Database query failed: ${error.message || JSON.stringify(error)}`)
|
|
}
|
|
|
|
return response.json()
|
|
}
|