MCPcopy
hub / github.com/prisma/prisma / constructor

Method constructor

packages/client/src/runtime/getPrismaClient.ts:334–496  ·  view source on GitHub ↗
(optionsArg: PrismaClientOptions)

Source from the content-addressed store, hash-verified

332 _createPrismaPromise = createPrismaPromiseFactory()
333
334 constructor(optionsArg: PrismaClientOptions) {
335 if (!optionsArg) {
336 throw new PrismaClientInitializationError(
337 `\
338\`PrismaClient\` needs to be constructed with a non-empty, valid \`PrismaClientOptions\`:
339
340\`\`\`
341new PrismaClient({
342 ...
343})
344\`\`\`
345
346or
347
348\`\`\`
349constructor() {
350 super({ ... });
351}
352\`\`\`
353 `,
354 clientVersion,
355 )
356 }
357 config = optionsArg.__internal?.configOverride?.(config) ?? config
358 validatePrismaClientOptions(optionsArg, config)
359
360 // prevents unhandled error events when users do not explicitly listen to them
361 const logEmitter = new EventEmitter().on('error', () => {}) as LogEmitter
362
363 this._extensions = MergedExtensionsList.empty()
364 this._previewFeatures = config.previewFeatures
365 this._clientVersion = config.clientVersion ?? clientVersion
366 this._activeProvider = config.activeProvider
367 this._globalOmit = optionsArg?.omit
368 this._tracingHelper = getTracingHelper()
369
370 /**
371 * Initialise and validate the Driver Adapter, if provided.
372 */
373
374 let adapter: SqlDriverAdapterFactory | undefined
375 if (optionsArg.adapter) {
376 adapter = optionsArg.adapter
377
378 // Note:
379 // - `getConfig(..).datasources[0].provider` can be `postgresql`, `postgres`, `mysql`, or other known providers
380 // - `getConfig(..).datasources[0].activeProvider`, stored in `config.activeProvider`, can be `postgresql`, `mysql`, or other known providers
381 // - `adapter.provider` can be `postgres`, `mysql`, or `sqlite`, and changing this requires changes to Rust as well,
382 // see https://github.com/prisma/prisma-engines/blob/d116c37d7d27aee74fdd840fc85ab2b45407e5ce/query-engine/driver-adapters/src/types.rs#L22-L23.
383 //
384 // TODO: Normalize these provider names once and for all in Prisma 6.
385 const expectedDriverAdapterProvider =
386 config.activeProvider === 'postgresql'
387 ? 'postgres'
388 : // CockroachDB is only accessible through Postgres driver adapters
389 config.activeProvider === 'cockroachdb'
390 ? 'postgres'
391 : config.activeProvider

Callers

nothing calls this directly

Calls 12

$onMethod · 0.95
getTracingHelperFunction · 0.90
getLogLevelFunction · 0.90
getEngineInstanceFunction · 0.90
debugFunction · 0.85
emptyMethod · 0.80
enableMethod · 0.80
logMethod · 0.80
onMethod · 0.65
createMethod · 0.45

Tested by

no test coverage detected