Under the hood

This page gives an overview of the Prisma internals and how it works "under the hood".

Note that this page does not contain any practical information that is relevant for using Prisma. It rather aims at providing a mental model for what the Prisma toolkit actually is and how the different tools that are available to developers are structured.

If you're new to Prisma, be sure to check out the Quickstart and Introduction pages first.

Prisma engines

At the core of each module, there typically is a Prisma engine that implements the core set of functionality. Engines are implemented in Rust and expose a low-level API that is used by the higher-level interfaces.

A Prisma engine is the direct interface to the database, any higher-level interfaces always communicate with the database through the engine-layer.

As an example, Prisma Client connects to the query engine in order to read and write data in a database:

Prisma engine

Using custom engine binaries

By default, all binaries are automatically downloaded into the node_modules/prisma folder when you install or update prisma. You might want to use a custom binary file if:

  • Automated download of binaries is not possible.
  • You have created your own engine binary (for testing, or for an OS that is not officially supported).

Use the following environment variables to specify custom locations for your binaries:

  • PRISMA_QUERY_ENGINE_BINARY (Query engine)
  • PRISMA_MIGRATION_ENGINE_BINARY (Migration engine)
  • PRISMA_INTROSPECTION_ENGINE_BINARY (Introspection engine)
  • PRISMA_FMT_BINARY (for npx prisma format)

The prisma/.env file

To set an environment variable in the prisma/.env file:

  1. Add the environment variable to the prisma/.env file:

    Unix, MacOS
    Windows
    PRISMA_QUERY_ENGINE_BINARY=custom/path/my-query-engine-binary
  2. Run the following command to output the paths to all binaries:

    $npx prisma -v

    The output shows that the query engine path comes from the PRISMA_QUERY_ENGINE_BINARY environment variable:

    Unix, macOS
    Windows
    Current platform : darwin
    Query Engine : query-engine 854c8ba7f0dce66f115af36af24e66989a8c02a1 (at node_modules\@prisma\engines\query-engine-windows.exe)
    Migration Engine : migration-engine-cli 854c8ba7f0dce66f115af36af24e66989a8c02a1 (at node_modules\@prisma\engines\migration-engine-windows.exe)
    Introspection Engine : introspection-core 854c8ba7f0dce66f115af36af24e66989a8c02a1 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
    Format Binary : prisma-fmt 854c8ba7f0dce66f115af36af24e66989a8c02a1 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)

Note: It is possible to use an .env file in a location outside the prisma folder.

Global environment variable

To set the an environment variable globally (in this example, PRISMA_QUERY_ENGINE_BINARY):

  1. Run the following command to set the environment variable:

    Unix, macOS
    Windows
    $export PRISMA_QUERY_ENGINE_BINARY=/custom/my-query-engine-unix
  2. Run the following command to output the paths to all binaries:

    $npx prisma -v

    The output shows that the query engine path comes from the PRISMA_QUERY_ENGINE_BINARY environment variable:

    Unix, MacOS
    Windows
    Current platform : darwin
    Query Engine : query-engine d6ff7119649922b84e413b3b69660e2f49e2ddf3 (at /custom/my-query-engine-windows)
    Migration Engine : migration-engine-cli d6ff7119649922b84e413b3b69660e2f49e2ddf3 (at /myproject/node_modules/@prisma/engines/migration-engine-windows)
    Introspection Engine : introspection-core d6ff7119649922b84e413b3b69660e2f49e2ddf3 (at /myproject/node_modules/@prisma/engines/introspection-engine-windows)
    Format Binary : prisma-fmt d6ff7119649922b84e413b3b69660e2f49e2ddf3 (at /myproject/node_modules/@prisma/engines/prisma-fmt-windows)
Edit this page on GitHub