Prisma

P

Prisma

The official Discord server of Prisma! Find us online at prisma.io

Join

Prisma Query Performance Question

I have a nextjs application built with trpc endpoints and Prisma (also using Prisma Postgres - here is my schema). Most of my queries are pretty quick and dont give me any concern about performance, but one of my queries is noticeably slow (get all). This request is made from a trpc endpoint. I think it is fair to assume that this query could be slower than others given it is loading more data, but it is incredibly slow (initial load sometimes taking 3+ seconds and I only have 24 recipes in the db) relative to the rest of my queries. What is even more interesting is this query is shared between pages, and it seems to only be slow on one page. I know there are a handful of variables at play here, but looking at my schema and query, are there any obvious issues I have/improvements to be made (schema index’s, etc). To test this out live here are the 2 deployed pages on my site:...

DB Error?

introspect, 22:14:23 Error SQL Query select "ns"."nspname" as "schema", "cls"."relname" as "name", (select coalesce(json_agg(agg), '[]') from (select "att"."attname" as "name", "typ"."typname" as "datatype", "tns"."nspname" as "datatype_schema", "fk_ns"."nspname" as "foreign_key_schema", "fk_cls"."relname" as "foreign_key_table", "fk_att"."attname" as "foreign_key_column", "pk_con"."conkey" is not null as "pk", "att"."attgenerated" != '' as "computed", "att"."attnotnull" != true as "nullable", coalesce((select json_agg("enm"."enumlabel") as "o" from "pg_catalog"."pg_enum" as "enm" where "enm"."enumtypid" = "typ"."oid"), '[]') as "options" from "pg_catalog"."pg_attribute" as "att" inner join "pg_catalog"."pg_type" as "typ" on "typ"."oid" = "att"."atttypid" inner join "pg_catalog"."pg_namespace" as "tns" on "tns"."oid" = "typ"."typnamespace" left join "pg_catalog"."pg_constraint" as "pk_con" on "pk_con"."contype" = 'p' and "pk_con"."conrelid" = "cls"."oid" and "att"."attnum" = any("pk_con"."conkey") left join "pg_catalog"."pg_constraint" as "fk_con" on "fk_con"."contype" = 'f' and "fk_con"."conrelid" = "cls"."oid" and "att"."attnum" = any("fk_con"."conkey") left join "pg_catalog"."pg_class" as "fk_cls" on "fk_cls"."oid" = "fk_con"."confrelid" left join "pg_catalog"."pg_namespace" as "fk_ns" on "fk_ns"."oid" = "fk_cls"."relnamespace" left join "pg_catalog"."pg_attribute" as "fk_att" on "fk_att"."attrelid" = "fk_cls"."oid" and "fk_att"."attnum" = any("fk_con"."confkey") where "att"."attrelid" = "cls"."oid" and "att"."attnum" >= 0 and "att"."attisdropped" != true) as agg) as "columns" from "pg_catalog"."pg_class" as "cls" inner join "pg_catalog"."pgnamespace" as "ns" on "cls"."relnamespace" = "ns"."oid" where "ns"."nspname" !~ '^pg' and "ns"."nspname" != 'information_schema' and "cls"."relkind" in ('r', 'v')...

Horrendous performance with relationalJoins active for deep includes through models/views

I have difficulties finding out why out prisma queries are running so slow. Im firing 15 queries simultanously and they seem to return in batches of 6 each block being 600ms delayed. We use the default postgres docker-image but our schema is fairly complex. I have no idea where the batch of 6 is coming from and also why a single prisma sql query would even take 600ms to begin with for a db that doesnt even have 2000 rows. I am aware that the inbcludes im doing sometimes are like model.include.model.include.view.include.model.include.model . SO like 5 deep sometimes with multiple sibling includes aswell. But i would expec this to be good performance. I dont think the schema would fit in here due to length limits and privacy reasons, but generally: we have ...

Help with Error in Schema engine with Planetscale.

I've recently changed to schema folder structure and now can't push a new table to db... ? When I try and push npx prisma db push I get an error "Oops, an unexpected error occurred! Error in Schema engine. Reason: [schema-engine/sql-schema-describer/src/mysql... [more...]" Prisma generates correctly, types for the new table are generated with no errors, prisma Studio recognises the new table but I cann't push it....

Getting Reading from "node:async_hooks" is not handled by plugins onnextJs server actions

Here is my config: - custom generated path inside my packages/db monorepo package - the prisma package is "type": "module" - The error only happens on nextJs server actions (I believe because of different runti then server components) Can anyone help me? Two days trying to figure this out already....

6.12 failing when using typedSql and tsx

I'm trying out prisma 6.12 and have switched over to using prisma-client and ran npx prisma generate as well as npx prisma generate --sql for my typedSql files. I can see that the generated folder get's created and my two sql related files are there. I then run npx tsx --test and for some reason my generated/prisma/sql folder's contents get deleted and my tests using typedSql fail. Any ideas as to what's happening?

Basic Prisma Optimize Is Not Working

Hi, I'm am trying to debug some bad query performance in our application. I was going to use prisma optimize, but no matter what I it absolutely refuses to push anything the website. I have a VERY minimal example that does not work: ```ts...

Prisma push to PlanetScale development branches crashing schema engine

Running prisma db push to a PlanetScale development branch is crashing the schema engine: (Vitess) ``` Environment variables loaded from prisma/.env Prisma schema loaded from prisma/schema.prisma...

MismatchedTokenException when migrating from neon/docker to prisma postgres

For some reason im getting a schema parsing error when moving from docker (locally) + neon to prisma postgres. I started with bunx prisma dev to spin up a local dev database. After running prisma generate + prisma migrate, I'm getting the following error MismatchedTokenException: Expecting --> '{' <-- but found --> 'non-linear' <-- I'm not sure why switching db providers would cause the schema to be invalid...

getting error "prisma:error Must call super constructor ..." at a simple insert

So, I get this error "prisma:error Must call super constructor in derived class before accessing 'this' or returning from derived constructor" when doing this insert: ``` const form = await prisma.forms.create({ data: formData...

Can't Null a Compound-unique Value

I have something like this: ``` model MyModel { fieldOne String fieldTwo String...

Warning: consolidate your env vars

Hi developers, I am new to prisma and started enjoying it, the whole ecosystem is amazing, however since i am new, started facing some initial hiccups. I just have a single .env file in my root directory, but whenever i get any prisma issue, it also put a warning with a code snippet, seems like not everyone is facing this and hence couldn't find much details online. may be its my tech stack :shrug: (Hono + Bun + Prisma) Can someone please guide me how to get rid of this. ...

DataBricks Adapter

Has anyone looked at creating a DataBricks adapter? The project I am working on has been advised that it should be moved from the current MySQL RDS to DataBricks. I love using Prisma to control the models (currently around ~140) and queries that we do. I was hoping someone might have already attempted to write an adapter, if not I was going to attempt it myself using https://www.npmjs.com/package/@prisma/adapter-libsql as a basis, or if there is some better documentation to follow....

Would be nice to see an example `.cursor/prisma-rule.mdc` or equivalent example

Hey all! I've seen some other library/projects start offering their own examples of some suggested/recommended rulesets by project authors for use in some of the Agentic IDE's (Cursor, Windsurf, Cline, Roo, etc...) which can come in especially helpful when we are able to specify glob patterns to select specific .prisma file extensions and specify Prisma-specific language as the project rule description. I'd be very interested to see what kinds of things would be used/specified by the Prisma developers themselves, if they are using Agents at all for things, right now....

Best Pratices on prisma.schema location

Hi everyone! I'm creating a nest microservice app with nestjs with each microservice in a different git repository, but all use the same database. In the project setup i replace the prisma.schema default localization. Since I am using DDD architecture, I put it inside infra/database/prisma, could this become a big problem in the future?...

prisma migrate dev hangs using Prisma Postgress

Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "accelerate.prisma-data.net"
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "accelerate.prisma-data.net"
It just hangs on this message indefinitely. This was previously working for us without any issue....

help node sea app with prisma

I created an API using Fastify and bundled it into an executable using Node.js SEA. It works fine on my machine, but when I send it to someone else, it throws an error saying it can't find the query_engine.dll.node file. I’ve figured out that the issue is due to the location of this DLL. Currently, I have to manually recreate the same folder structure (e.g., src/util/prisma/client) next to the executable and place the DLL there for it to work. However, instead of relying on this specific folder structure, I want the executable to load the query_engine.dll.node directly from the directory where the executable is located. How can I achieve this? (translated)...

Is there actually a best practice when it comes to naming conventions?

Yes, I've read the docs but found the weren't particularly explicit in what best practice actually is. What I've been able to deduce is the following: 1. It's best practice to use PascalCase for Prisma model names 2. It's best practice to use camelCase for Prisma column names...

Debugging Invalid `prisma.$queryRaw()` invocation

I am getting an Invalid prisma.$queryRaw() invocation error when running my code in the cloud (specifically trigger.dev). I have a fairly distinct setup in that I have multiple packages abstracting different Prisma schemas in my monorepo. They are all getting bundled together for Trigger with some bespoke code to copy the binary combined with the prisma extension. Example snippet from the schemas, which are all configured roughly the same way. ``` datasource db {...

`prisma-client` generator in compiled workspace package

Running into this error:
The inferred type of 'foo' cannot be named without a reference to '../../../node_modules/@mrb/mysql/dist/generated/internal/prismaNamespace'. This is likely not portable. A type annotation is necessary.
The inferred type of 'foo' cannot be named without a reference to '../../../node_modules/@mrb/mysql/dist/generated/internal/prismaNamespace'. This is likely not portable. A type annotation is necessary.
I know you can get rid of th error by setting declaration to false, but that is not an option for me. What is the best way to go about this?...