* Parses arguments passed to this command, and starts Studio * * @param argv Array of all arguments * @param config The loaded Prisma config
(argv: string[], config: PrismaConfigInternal)
| 251 | * @param config The loaded Prisma config |
| 252 | */ |
| 253 | async parse(argv: string[], config: PrismaConfigInternal): Promise<string | Error> { |
| 254 | const args = arg(argv, { |
| 255 | '--help': Boolean, |
| 256 | '-h': '--help', |
| 257 | '--config': String, |
| 258 | '--port': Number, |
| 259 | '-p': '--port', |
| 260 | '--browser': String, |
| 261 | '-b': '--browser', |
| 262 | '--url': String, |
| 263 | }) |
| 264 | |
| 265 | if (isError(args)) { |
| 266 | return this.help(args.message) |
| 267 | } |
| 268 | |
| 269 | if (args['--help']) { |
| 270 | return this.help() |
| 271 | } |
| 272 | |
| 273 | const connectionString = args['--url'] || config.datasource?.url |
| 274 | |
| 275 | if (!connectionString) { |
| 276 | return new UserFacingError( |
| 277 | 'No database URL found. Provide it via the `--url <url>` argument or define it in your Prisma config file as `datasource.url`.', |
| 278 | ) |
| 279 | } |
| 280 | |
| 281 | if (!URL.canParse(connectionString)) { |
| 282 | return new UserFacingError('The provided database URL is not valid.') |
| 283 | } |
| 284 | |
| 285 | const protocol = new URL(connectionString).protocol.replace(':', '') |
| 286 | |
| 287 | if (isAccelerateProtocol(protocol)) { |
| 288 | return new UserFacingError(ACCELERATE_UNSUPPORTED_MESSAGE) |
| 289 | } |
| 290 | |
| 291 | const studioStuff = CONNECTION_STRING_PROTOCOL_TO_STUDIO_STUFF[protocol] |
| 292 | |
| 293 | if (!studioStuff) { |
| 294 | return new UserFacingError(`Prisma Studio is not supported for the "${protocol}" protocol.`) |
| 295 | } |
| 296 | |
| 297 | const executor = await studioStuff.createExecutor( |
| 298 | connectionString, |
| 299 | getUrlBasePath(args['--url'], config.loadedFromFile), |
| 300 | ) |
| 301 | const version = packageJson.dependencies['@prisma/studio-core'] |
| 302 | const ppgDbInfo = await getPpgInfo(connectionString) |
| 303 | const handler = createStudioRequestHandler({ |
| 304 | adapter: studioStuff.adapter, |
| 305 | executor, |
| 306 | ppgDbInfo, |
| 307 | protocol, |
| 308 | version, |
| 309 | }) |
| 310 |
nothing calls this directly
no test coverage detected