Skip to content

Client API reference

Prisma Client is an automatically generated database CRUD entry and is the main way for you to interact with the database.

Default Constructor (Factory)

The code type of the default constructor is as follows:

class PrismaClient {
    factory PrismaClient({
        String? datasourceUrl,
        Map<String, String>? datasources
    }) {


datasourceUrlString?Datasource URL
datasourcesMap<String, String>?Datasources


In Prisma Schema, datasource <name> is used to name a data source.

datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")

The db in the above is the name of the data source, which will be used to generate the constructor of Prisma Client.

final client = PrismaClient(datasources: {
  'db': 'sqlite://path/to/database.db',


Usually, you don't need to specify it, it will automatically read it from schema.prisma when generate. After you officially compile, the actual connected database is not the database address specified in datasource, then you When initializing Prisma Client, the URL needs to be overwritten.

Datasource URL

Programmatically override the datasource block in schema.prisma.


Database connection stringsqlite://path/to/database.dbThe database connection URL


final client = PrismaClient(
    datasourceUrl: 'sqlite://path/to/database.db'


Prisma Client will generate datamodel at compile time, which is a static property that contains all models in Prisma Schema.



This $connect is used to explicitly connect to the database.


Usually you don't need to call it manually, Prisma Client will call it automatically the first time you call it. Of course calling it manually will speed up the first query of the database.


This $disconnect is used to disconnect from the database.


This is a method that must be called previously in your application to terminate the Prisma Engine process to close the database connection. If you don't call it, the Prisma Engine process will continue to run even if your app is planted.


$raw is used to execute raw SQL statements.

final result = await client.$raw.query('SELECT * FROM User');


$raw.query is used to execute SQL query statements. For usage, please refer to Queries → Raw database access → $raw.query


$raw.execute is used to execute SQL execution statements. For usage, please refer to Queries → Raw database access → $raw.execute


$transaction is used to perform transactions.

client.$transaction((client) async {
  await client.user.create(...);

For more information about Transactions, please refer to Queries → Transactions


Prisma metrics give you detailed insights into how Prisma clients interact with your database. You can use this insight to help diagnose performance issues with your application.


Retrieve metrics in JSON format.

final metrics = await client.$metrics.json();

For more information, please refer to Prisma Official Docs → Metrics → JSON


Retrieve metrics in Prometheus format.

final metrics = await client.$metrics.prometheus();

For more information, please refer to Prisma Official Docs → Metrics → Prometheus

<model> properties

Prisma Client owns all models and views defined using model/view blocks in schema.prisma and generates <Model>Delegate proxies for them.

final users = await client.user.findMany();

For Reference about Model Delegate, please refer to Reference → Model Delegate

Released under the BSD-3-Clause License