Overview

This page describes the Prisma Client constructor parameters.

datasources

Use the datasources constructor parameter to programatically override the URL of a datasource - for example, as part of an integration test. To override a datasource:

  1. Define a datasource in the schema.prisma file. In the following example, there is a single datasource named my_database:

    1datasource my_database {
    2 provider = "sqlite"
    3 url = env("DATABASE_URL")
    4}

    The DATABASE_URL environment variable defines the following value:

    1DATABASE_URL="file:./dev.db"

    Note: You must re-generate the Prisma Client each time you add or rename a datasource. Datasource names are included in the generated client.

  2. Instantiate a client and override the connection string of the my_database datasource:

    1import { PrismaClient } from '@prisma/client'
    2
    3const prisma = new PrismaClient({
    4 datasources: {
    5 my_database: {
    6 url: 'file:./dev_qa.db'
    7 }
    8 },
    9})

Note: If you define multiple datasources in schema.prisma, Prisma defaults to the first entry.

See Datasources for more information.

log

Use the log constructor parameter to determine the type and level of logging. The following configuration raises an event each time the Prisma Client queries the database:

1const prisma = new PrismaClient({
2 log: [{ emit: 'event', level: 'query' }],
3})

See Logging for more information.

errorFormat

Use the errorFormat constructor parameter to determine the level and formatting of errors returned by Prisma. The following configuration outputs raw error messages without formatting or extended information about the error:

1const prisma = new PrismaClient({
2 errorFormat: 'minimal', // Defaults to 'colorless'
3})

See Error formatting for more information.

Edit this page on Github