MCPcopy
hub / github.com/prisma/prisma / createDevConnection

Function createDevConnection

packages/cli/src/postgres/link/management-api.ts:31–60  ·  view source on GitHub ↗
(client: ManagementApiClient, databaseId: string)

Source from the content-addressed store, hash-verified

29}
30
31export async function createDevConnection(client: ManagementApiClient, databaseId: string): Promise<ConnectionResult> {
32 const { data, error } = await client.POST('/v1/databases/{databaseId}/connections', {
33 params: { path: { databaseId } },
34 body: { name: getConnectionName() },
35 })
36
37 if (error) {
38 const code = error.error?.code
39 const msg = typeof error.error?.message === 'string' ? error.error.message : 'Failed to create connection'
40
41 if (code === 'unauthorized' || code === 'authentication-failed') {
42 throw new LinkApiError('Invalid credentials — check your API key or re-authenticate via browser.', 401)
43 }
44 if (code === 'not_found') {
45 throw new LinkApiError(`Database "${databaseId}" not found — check the database ID in your console.`, 404)
46 }
47
48 throw new LinkApiError(msg)
49 }
50
51 const endpoints = data?.data?.endpoints
52 const connectionString =
53 endpoints?.direct?.connectionString ?? endpoints?.pooled?.connectionString ?? data?.data?.connectionString
54
55 if (!connectionString) {
56 throw new LinkApiError('No connection string found in API response')
57 }
58
59 return { connectionString }
60}
61
62export async function listProjects(client: ManagementApiClient) {
63 const { data, error } = await client.GET('/v1/projects')

Callers 2

executeLinkFlowMethod · 0.90

Calls 1

getConnectionNameFunction · 0.85

Tested by

no test coverage detected