MCPcopy
hub / github.com/prisma/prisma / PrismaClientClass

Class PrismaClientClass

packages/client-generator-js/src/TSClient/PrismaClient.ts:383–683  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

381}
382
383export class PrismaClientClass implements Generable {
384 constructor(
385 protected readonly context: GenerateContext,
386 protected readonly internalDatasources: DataSource[],
387 protected readonly outputDir: string,
388 protected readonly runtimeName: TSClientOptions['runtimeName'],
389 protected readonly browser?: boolean,
390 ) {}
391 private get jsDoc(): string {
392 const { dmmf } = this.context
393
394 let example: DMMF.ModelMapping
395
396 if (dmmf.mappings.modelOperations.length) {
397 example = dmmf.mappings.modelOperations[0]
398 } else {
399 // because generator models is empty we need to create a fake example
400 example = {
401 model: 'User',
402 plural: 'users',
403 }
404 }
405
406 return `/**
407 * ## Prisma Client ʲˢ
408 *
409 * Type-safe database client for TypeScript & Node.js
410 * @example
411 * \`\`\`
412 * const prisma = new PrismaClient({
413 * adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL })
414 * })
415 * // Fetch zero or more ${capitalize(example.plural)}
416 * const ${uncapitalize(example.plural)} = await prisma.${uncapitalize(example.model)}.findMany()
417 * \`\`\`
418 *
419 *
420 * Read more in our [docs](https://pris.ly/d/client).
421 */`
422 }
423 public toTSWithoutNamespace(): string {
424 const { dmmf } = this.context
425
426 return `${this.jsDoc}
427export class PrismaClient<
428 ClientOptions extends Prisma.PrismaClientOptions = Prisma.PrismaClientOptions,
429 const U = 'log' extends keyof ClientOptions ? ClientOptions['log'] extends Array<Prisma.LogLevel | Prisma.LogDefinition> ? Prisma.GetEvents<ClientOptions['log']> : never : never,
430 ExtArgs extends $Extensions.InternalArgs = $Extensions.DefaultArgs
431> {
432 [K: symbol]: { types: Prisma.TypeMap<ExtArgs>['other'] }
433
434 ${indent(this.jsDoc, TAB_SIZE)}
435
436 constructor(optionsArg ?: Prisma.Subset<ClientOptions, Prisma.PrismaClientOptions>);
437 $on<V extends U>(eventType: V, callback: (event: V extends 'query' ? Prisma.QueryEvent : Prisma.LogEvent) => void): PrismaClient;
438
439 /**
440 * Connect with the database

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected