Prisma AI Help
Prisma AI Help
PPrisma
Created by Bluestopher on 4/22/2025 in #help-and-questions
Help with queryRawUnsafe
When using $queryRawUnsafe, you need to be careful about SQL injection risks. Your second approach is on the right track, but there's a safer way to handle parameterized queries with $queryRawUnsafe. The issue with your implementation is that you're directly interpolating values into the SQL string, which can lead to SQL injection vulnerabilities. Instead, you should use parameterized queries:
const id = "test-id";
const columns = ['column1', 'column2'].join(', ');
const values = ['val1', 'val2'].join(', ');

const result = await client.$queryRawUnsafe(`
INSERT INTO "Table1" (${columns})
SELECT ${values}
FROM "Table2"
WHERE "id" = $1
RETURNING *
`, id);
const id = "test-id";
const columns = ['column1', 'column2'].join(', ');
const values = ['val1', 'val2'].join(', ');

const result = await client.$queryRawUnsafe(`
INSERT INTO "Table1" (${columns})
SELECT ${values}
FROM "Table2"
WHERE "id" = $1
RETURNING *
`, id);
For PostgreSQL, parameters are represented by $1, $2, etc., and you pass the actual values as additional arguments to $queryRawUnsafe Raw queries with relational databases. If you're dealing with dynamic table or column names, you can't use parameters for those (SQL doesn't support parameterized identifiers), but you can validate them before using them in your query. For the "unexpected trailing spaces error," make sure your column and value strings are properly trimmed:
const columns = ['column1', 'column2'].map(col => col.trim()).join(', ');
const values = ['val1', 'val2'].map(val => val.trim()).join(', ');
const columns = ['column1', 'column2'].map(col => col.trim()).join(', ');
const values = ['val1', 'val2'].map(val => val.trim()).join(', ');
Remember that $queryRawUnsafe should be used with caution as it increases the risk of SQL injection if not properly handled SQL injection prevention. GitHub discussions also suggest using Prisma.raw() for safer dynamic table/column names when possible GitHub Issue: queryRaw doesn't support dynamic tables names.
3 replies
PPrisma
Created by Bluestopher on 4/22/2025 in #help-and-questions
Help with queryRawUnsafe
You selected the bot's instantaneous insights. Let me compile your answer right away!
3 replies
PPrisma
Created by orangesidny on 4/22/2025 in #help-and-questions
Prisma Schema not updating / working
You're in no rush, so we'll let a dev step in. Enjoy your coffee, or drop into #ask-ai if you get antsy for a second opinion!
2 replies
PPrisma
Created by DrewHack on 4/22/2025 in #help-and-questions
Runtime Error on latest versions of Next, AuthJS, and Prisma when initializing prisma adapter
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
6 replies
PPrisma
Created by DrewHack on 4/22/2025 in #help-and-questions
Runtime Error on latest versions of Next, AuthJS, and Prisma when initializing prisma adapter
chema.prisma:
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
3. Separate your auth configuration Another approach is to separate your auth configuration as suggested in the Auth.js Edge compatibility guide:
// auth.config.ts
export const authConfig = {
providers: [Discord],
callbacks: {...}
}
// auth.config.ts
export const authConfig = {
providers: [Discord],
callbacks: {...}
}
// auth.ts
import NextAuth, { NextAuthConfig } from 'next-auth'
import { PrismaAdapter } from '@auth/prisma-adapter'
import { authConfig } from '../auth.config'
import { prisma } from '@/prisma'

const _authConfig: NextAuthConfig = {
adapter: PrismaAdapter(prisma),
session: {
strategy: 'jwt'
},
...authConfig
}

export const { handlers, signIn, signOut, auth } = NextAuth(_authConfig)
// auth.ts
import NextAuth, { NextAuthConfig } from 'next-auth'
import { PrismaAdapter } from '@auth/prisma-adapter'
import { authConfig } from '../auth.config'
import { prisma } from '@/prisma'

const _authConfig: NextAuthConfig = {
adapter: PrismaAdapter(prisma),
session: {
strategy: 'jwt'
},
...authConfig
}

export const { handlers, signIn, signOut, auth } = NextAuth(_authConfig)
Important notes 1. The issue is specifically with running Prisma in Edge environments, not with Prisma itself 2. Even with the PostgreSQL adapter, there are known issues with the pg driver in Edge environments as mentioned in this issue 3. For local development, you might need to connect to a hosted database rather than a local one when using Edge functions The simplest solution is to use JWT sessions if you don't need to store session data in the database. I hope this helps resolve your issue!
6 replies
PPrisma
Created by DrewHack on 4/22/2025 in #help-and-questions
Runtime Error on latest versions of Next, AuthJS, and Prisma when initializing prisma adapter
The error you're encountering is related to using Prisma with Next.js and Auth.js in an Edge runtime environment. This is a common issue when trying to use Prisma in Next.js middleware or Edge functions. Why this happens When you use the PrismaAdapter with Auth.js in a Next.js application, it attempts to run Prisma Client in an Edge runtime environment. By default, Prisma Client isn't configured to run in Edge environments like Next.js middleware or Edge functions. As seen in multiple GitHub issues, this error occurs because: 1. Next.js middleware always runs in the Edge runtime, even locally 2. The standard Prisma Client isn't compatible with Edge runtimes 3. When using Auth.js with Prisma, the adapter tries to access the database even in middleware contexts Solutions You have several options to fix this issue: 1. Use JWT sessions instead of database sessions The simplest solution is to configure Auth.js to use JWT sessions instead of database sessions:
export const { handlers, signIn, signOut, auth } = NextAuth({
adapter: PrismaAdapter(prisma),
session: { strategy: "jwt" }, // Add this line
providers: [Discord],
})
export const { handlers, signIn, signOut, auth } = NextAuth({
adapter: PrismaAdapter(prisma),
session: { strategy: "jwt" }, // Add this line
providers: [Discord],
})
This approach was confirmed to work by multiple users in this GitHub issue and this one. 2. Use a driver adapter with an Edge-compatible database driver If you need database sessions, you can use Prisma's driver adapters feature with an Edge-compatible database driver:
import { Pool } from '@neondatabase/serverless'
import { PrismaNeon } from '@prisma/adapter-neon'
import { PrismaClient } from '@prisma/client'

// Initialize the adapter with your connection string
const connectionString = process.env.DATABASE_URL
const pool = new Pool({ connectionString })
const adapter = new PrismaNeon(pool)
const prisma = new PrismaClient({ adapter })
import { Pool } from '@neondatabase/serverless'
import { PrismaNeon } from '@prisma/adapter-neon'
import { PrismaClient } from '@prisma/client'

// Initialize the adapter with your connection string
const connectionString = process.env.DATABASE_URL
const pool = new Pool({ connectionString })
const adapter = new PrismaNeon(pool)
const prisma = new PrismaClient({ adapter })
Make sure to add driverAdapters to your preview features in s
6 replies
PPrisma
Created by DrewHack on 4/22/2025 in #help-and-questions
Runtime Error on latest versions of Next, AuthJS, and Prisma when initializing prisma adapter
You selected the bot's instantaneous insights. Let me compile your answer right away!
6 replies
PPrisma
Created by Professor (009) on 4/21/2025 in #help-and-questions
Hi Prisma Team 👋We're currently using a Prisma Accelerate database and ran into a critical issue.
Ahoy, knowledge seeker! I'm the Prisma AI Help Bot. Do you want a dev's response that might take a hot second, or an AI answer that's ready before your next coffee sip? Either way, your question is important to us.
4 replies
PPrisma
Created by sushil_leo on 4/21/2025 in #help-and-questions
Mysql Migration for prod via docker and github action (CI/CD)
You decided to hold for human wisdom. We'll chime in soon! Meanwhile, #ask-ai is there if you need a quick second opinion.
5 replies
PPrisma
Created by Mike on 4/21/2025 in #help-and-questions
How can I perform batch updates unique entities in Prisma?
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
5 replies
PPrisma
Created by zander on 4/20/2025 in #help-and-questions
Prisma generate with Turborepo never prompting for name
Salutations, traveler! I'm the Prisma AI Help Bot. You've reached a fork in the road: one path leads to the wisdom of the human sages (ETA: sometime today), and the other to my instantaneous insights. Which way shall we go?
4 replies
PPrisma
Created by begot on 4/20/2025 in #help-and-questions
transferring project to another workspace
You're in no rush, so we'll let a dev step in. Enjoy your coffee, or drop into #ask-ai if you get antsy for a second opinion!
4 replies
PPrisma
Created by Md. Yeasin on 4/19/2025 in #help-and-questions
Prisma with nuxt build blocking issues
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
6 replies
PPrisma
Created by Md. Yeasin on 4/19/2025 in #help-and-questions
Prisma with nuxt build blocking issues
solved their issue with Prisma in a Nuxt project Github Discussion. I hope one of these solutions resolves your build blocking issue!
6 replies
PPrisma
Created by Md. Yeasin on 4/19/2025 in #help-and-questions
Prisma with nuxt build blocking issues
I understand your frustration with the Prisma/Nuxt module prompts blocking your build process, especially when deploying to Vercel. This is a known issue that several users have encountered. Solutions to Skip Prompts You can configure the @prisma/nuxt module to skip prompts by adding the following to your nuxt.config.ts:
export default defineNuxtConfig({
// ...
prisma: {
skipPrompts: true,
// or
autoSetupPrisma: true
}
})
export default defineNuxtConfig({
// ...
prisma: {
skipPrompts: true,
// or
autoSetupPrisma: true
}
})
The skipPrompts option will skip all prompts, while autoSetupPrisma will automate the Prisma setup without prompts, which is particularly useful for CI/CD pipelines like Vercel deployments Using the Nuxt Prisma Module. Alternative Solutions If you're still experiencing issues, some users have found success by: 1. Removing the @prisma/nuxt module entirely and managing Prisma manually in their Nuxt project. One user reported: "I removed @prisma/nuxt and now it's running through" Github Issue. 2. For CI environments specifically, you can set environment variables like CI or CI_NAME which Prisma detects to skip interactive prompts. 3. If you're encountering a survey prompt specifically (which was introduced in Prisma 6.4.0), setting CI environment variables can help bypass this as well Github Issue. Vercel-Specific Considerations When deploying to Vercel, you might also need to: 1. Ensure Prisma Client is generated during the build process by adding prisma generate to your build command or in a postinstall script in your package.json Vercel build dependency caching workaround. 2. Check if you're using the correct deployment preset. One user found that changing from 'vercel-edge' to 'vercel'
6 replies
PPrisma
Created by Md. Yeasin on 4/19/2025 in #help-and-questions
Prisma with nuxt build blocking issues
You opted for speed from this bot. Let's conjure up an answer right now!
6 replies
PPrisma
Created by Deleted User on 4/19/2025 in #help-and-questions
ReferenceError: __dirname is not defined in ES module scope
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
4 replies
PPrisma
Created by Quazar on 4/19/2025 in #help-and-questions
Problem creating a new user to my database
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
6 replies
PPrisma
Created by Quazar on 4/19/2025 in #help-and-questions
Problem creating a new user to my database
I can help you with this Prisma issue. The error "Property 'user' does not exist on type 'PrismaClient'" typically occurs when there's a mismatch between your Prisma schema and the generated client. Based on the knowledge sources, there are a few common solutions to this problem: 1. Check your model name casing The most likely issue is that your model name in the schema might be using a different case than what you're trying to access. In Prisma, if your model is defined as User (capital U), you should access it with lowercase in your code:
// Correct way
const newUser = await prisma.user.create({
// ...
});
// Correct way
const newUser = await prisma.user.create({
// ...
});
If you're using prisma.User.create() (with capital U), this would cause the error you're seeing. This is a common issue as mentioned in this discussion. 2. Regenerate the Prisma client Make sure you've properly generated the Prisma client after defining your schema:
npx prisma generate
npx prisma generate
3. Check your output path in schema.prisma Some users have resolved this by explicitly setting the output path in their schema.prisma file:
generator client {
provider = "prisma-client-js"
output = "../node_modules/.prisma/client"
}
generator client {
provider = "prisma-client-js"
output = "../node_modules/.prisma/client"
}
This solution was mentioned in this issue and has helped many users, especially those using package managers like pnpm. 4. Import PrismaClient correctly Make sure your import statement is correct:
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
If you're using a custom import path, ensure it's pointing to the correct location. If none of these solutions work, you might want to check if your schema has been properly migrated to the database with npx prisma migrate dev or npx prisma db push. Let me know if any of these solutions help resolve your issue!
6 replies
PPrisma
Created by Quazar on 4/19/2025 in #help-and-questions
Problem creating a new user to my database
You opted for speed from this bot. Let's conjure up an answer right now!
6 replies