iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📌

Prisma 7 is Neither No Rust Nor Rust Free

に公開

About Generation Options in Prisma

To provide context for the discussion that follows, I will first explain the generation options.

  • provider = "prisma-client"
    Used when generating PrismaClient code in TypeScript to be built as part of your own code.

  • provider = "prisma-client-js"
    The traditional feature that generates PrismaClient code in JavaScript and utilizes it as a separate package via node_modules.

What Prisma@7 is promoting right now is provider = "prisma-client".

Examining Files Generated by Prisma@7

To create a state referred to as "Rust Free," let's generate TypeScript code for PrismaClient with the following settings. We will assume PostgreSQL as the target database.

  • schema.prisma
generator client {
  provider = "prisma-client"
  engineType = "client"
  output = "../app/generated/prisma"
}

I will check the generated files to see how the QueryCompiler is invoked.

  • Extracting the relevant section from prisma/internal/class.ts
async function decodeBase64AsWasm(
  wasmBase64: string
): Promise<WebAssembly.Module> {
  const { Buffer } = await import("node:buffer");
  const wasmArray = Buffer.from(wasmBase64, "base64");
  return new WebAssembly.Module(wasmArray);
}

config.compilerWasm = {
  getRuntime: async () =>
    await import("@prisma/client/runtime/query_compiler_bg.postgresql.mjs"),

  getQueryCompilerWasmModule: async () => {
    const { wasm } = await import(
      "@prisma/client/runtime/query_compiler_bg.postgresql.wasm-base64.mjs"
    );
    return await decodeBase64AsWasm(wasm);
  },
};

What this part does is extract the base64-encoded QueryCompiler WASM, decode it into binary, and inject it as WebAssembly. This query_compiler_bg.postgresql.wasm-base64.mjs file is 2,410KB, and even when ZIP compressed, it remains around 940KB. This WASM is essential to run Prisma.

As for how the QueryCompiler is built, the corresponding code is here:

https://github.com/prisma/prisma-engines/tree/main/query-compiler

Yes, it is Rust.

What Does Prisma Mean by "Rust Free"?

If you look at the article from 2025/04/30, it is barely mentioned.

https://www.prisma.io/blog/try-the-new-rust-free-version-of-prisma-orm-early-access

Prisma ORM's core engine has undergone a major shift from the Rust based query engine to a leaner TypeScript/WASM core (the Query Compiler).

It seems that the shift is from a Rust-based query engine (likely referring to the native binary) to a Query Compiler (a combination of TypeScript and WASM), but that WASM is made with Rust.

The claim that the bundle size is 90% smaller means that the 14MB size when using native binaries has become 1.6MB due to the switch to WASM. The transition from QueryEngine to QueryCompiler does not mean WASM is no longer needed.

Currently, Prisma continues to use terms like "Rust Free" and "No Rust," creating confusion. The reality is that it just means "No native libraries."

Prisma@7 Is Neither "No Rust" Nor "Rust Free"

The official blog post for Prisma@7 is as follows.

https://www.prisma.io/blog/announcing-prisma-orm-7-0-0

It no longer even states what the bundle size was reduced by 90% from. Furthermore, it implies that changing provider = "prisma-client-js" to provider = "prisma-client" would make things "rust-free," but the latter only generates TypeScript code, and the fundamental operation remains unchanged. The generated TypeScript code reads the WASM from a base64-encoded state, which actually increases the bundle size. As of now, there is no benefit.

Why Is the WASM Base64-Encoded?

This is a workaround for module bundlers. If there is code that reads the WASM file directly, it must support all environments. How a WASM file is handled depends on the module bundler's settings, and a "hell of compatibility" awaits for every environment. An easy way to solve this is to embed the WASM binary within the JavaScript and inject it as WebAssembly at runtime.

In environments like Cloudflare that require direct loading of WASM module files, you must avoid loading from base64 via runtime configuration. By the way, if you specify something like runtime = "workerd", the following code is generated:

config.compilerWasm = {
  getRuntime: async () => await import("./query_compiler_bg.js"),

  getQueryCompilerWasmModule: async () => {
    const { default: module } = await import("./query_compiler_bg.wasm?module");
    return module;
  },
};

The ?module part is an instruction for a specific module bundler. Cloudflare has no such specification method. In other words, it will throw an error and fail to run. Code output by specifying provider = "prisma-client" will not work unless you manually delete the relevant section yourself.

Summary

Prisma Is Terrible, and So Are the Articles Out There

The official blog bears a great responsibility for being misleading, but articles are popping up everywhere that misunderstand "Rust Free" and "No Rust" as meaning that WASM is no longer used.

By the way, one way to use Prisma as "No Rust" is to use Prisma Accelerate, a paid service dedicated to Prisma. This method executes the Prisma engine (the Rust part) externally via a remote connection. There is a service called Prisma Postgres that includes this functionality. This service existed before Prisma started marketing "No Rust," but there are even mistaken articles claiming that Prisma became "No Rust" by using it. And those are being referenced to reproduce further incorrect articles.

You Need to Doubt All Information

Technical articles, including mine, are full of mistakes. Articles by famous people are also quite often wrong. And official information is not necessarily correct either. I have even seen wrong articles being reproduced by referencing other wrong articles. Do not assume anything is correct until you have verified it yourself at the very least.

GitHubで編集を提案

Discussion