MCPcopy
hub / github.com/prisma/prisma / credentialsToUri

Function credentialsToUri

packages/internals/src/convertCredentials.ts:10–78  ·  view source on GitHub ↗
(credentials: DatabaseCredentials)

Source from the content-addressed store, hash-verified

8// opposite of uriToCredentials
9// only used for internal tests
10export function credentialsToUri(credentials: DatabaseCredentials): string {
11 const type = databaseTypeToProtocol(credentials.type)
12 if (credentials.type === 'sqlite') {
13 // if `file:../parent-dev.db` return as it is
14 return credentials.uri!
15 }
16
17 // construct URL object with protocol
18 const url = new NodeURL.URL(type + '//')
19
20 if (credentials.host) {
21 url.hostname = credentials.host
22 }
23
24 if (credentials.type === 'postgresql') {
25 if (credentials.database) {
26 url.pathname = '/' + credentials.database
27 }
28
29 if (credentials.schema) {
30 url.searchParams.set('schema', credentials.schema)
31 }
32
33 if (credentials.socket) {
34 url.host = credentials.socket
35 }
36 } else if (credentials.type === 'mysql') {
37 // why `credentials.schema` in mysql here? doesn't exist for mysql
38 // try removing it and see how the tests react
39 url.pathname = '/' + (credentials.database || credentials.schema || '')
40 if (credentials.socket) {
41 url.searchParams.set('socket', credentials.socket)
42 }
43 } else if (credentials.type === 'mongodb') {
44 url.pathname = '/' + credentials.database
45 }
46
47 if (credentials.ssl) {
48 // don't understand why hardcoding prefer? we should put the value here?
49 url.searchParams.set('sslmode', 'prefer')
50 }
51
52 if (credentials.user) {
53 url.username = credentials.user
54 }
55
56 if (credentials.password) {
57 url.password = credentials.password
58 }
59
60 if (credentials.port) {
61 url.port = String(credentials.port)
62 }
63
64 url.host = `${url.hostname}${url.port ? `:${url.port}` : ''}`
65
66 if (credentials.extraFields) {
67 for (const [key, value] of Object.entries(credentials.extraFields)) {

Callers 5

tearDownPostgresFunction · 0.90
tearDownCockroachFunction · 0.90
tearDownPostgresFunction · 0.90

Calls 4

databaseTypeToProtocolFunction · 0.85
setMethod · 0.80
entriesMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected