MCPcopy
hub / github.com/prisma/prisma / canConnectToDatabase

Function canConnectToDatabase

packages/internals/src/schemaEngineCommands.ts:68–105  ·  view source on GitHub ↗
(
  connectionString: string,
  cwd = process.cwd(),
  schemaEnginePath?: string,
)

Source from the content-addressed store, hash-verified

66
67// could be refactored with engines using JSON RPC instead and just passing the schema
68export async function canConnectToDatabase(
69 connectionString: string,
70 cwd = process.cwd(),
71 schemaEnginePath?: string,
72): Promise<ConnectionResult> {
73 if (!connectionString) {
74 throw new Error('Connection url is empty. See https://pris.ly/d/config-url')
75 }
76
77 try {
78 await execaCommand({
79 connectionString,
80 cwd,
81 schemaEnginePath: schemaEnginePath,
82 engineCommandName: 'can-connect-to-database',
83 })
84 } catch (_e) {
85 const e = _e as ExecaError
86
87 if (e.stderr) {
88 const logs = parseJsonFromStderr(e.stderr)
89 const error = logs.find((it) => it.level === 'ERROR' && it.target === 'schema_engine::logger')
90
91 if (error && error.fields.error_code && error.fields.message) {
92 return {
93 code: error.fields.error_code as DatabaseErrorCodes,
94 message: error.fields.message,
95 }
96 } else {
97 throw new Error(`Schema engine error:\n${logs.map((log) => log.fields.message).join('\n')}`)
98 }
99 } else {
100 throw new Error(`Schema engine exited. ${_e}`)
101 }
102 }
103
104 return true
105}
106
107// could be refactored with engines using JSON RPC instead and just passing the schema
108export async function createDatabase(connectionString: string, cwd = process.cwd(), schemaEnginePath?: string) {

Callers 6

ensureDatabaseExistsFunction · 0.90
mainFunction · 0.90
parseMethod · 0.90
createDatabaseFunction · 0.85

Calls 2

execaCommandFunction · 0.85
parseJsonFromStderrFunction · 0.85

Tested by

no test coverage detected