I think what you're looking for is https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/logging#event-based-logging.
Like this you can get the passed in parameters using the code mentioned in the docs
prisma.$on('query', (e) => {
console.log('Query: ' + e.query)
console.log('Params: ' + e.params)
console.log('Duration: ' + e.duration + 'ms')
})
The placeholders are for parameters. See here https://stackoverflow.com/a/7505842/9530790 for why parameterized queries is beneficial.
Answer from shmuels on Stack OverflowPrisma
prisma.io › docs › data-platform › query-console
Test and run queries with Query Console - Prisma
Use Query Console to run the 3 pre-defined findMany() test queries or add and test queries of your own using the Prisma Client API for model queries.
Prisma
prisma.io › docs › data-platform › classic-projects › platform › query-console
Test and run queries with Query Console | Prisma Docs
Use Query Console to run the 3 pre-defined findMany() test queries or add and test queries of your own using the Prisma Client API for model queries.
Stack Overflow
stackoverflow.com › questions › 74274673 › raw-query-in-prisma-query-console
Raw query in Prisma Query Console - Stack Overflow
await prisma.$queryRaw`SELECT * FROM "public"."User";`
Prisma
prisma.io › home › logging › logging › logging › logging
Logging | Prisma Documentation
const prisma = new PrismaClient({ log: [ { emit: "event", level: "query", }, { emit: "stdout", level: "error", }, { emit: "stdout", level: "info", }, { emit: "stdout", level: "warn", }, ], }); prisma.$on("query", (e) => { console.log("Query: " + e.query); console.log("Params: " + e.params); console.log("Duration: " + e.duration + "ms"); }); Query: SELECT "public"."User"."id", "public"."User"."email", "public"."User"."name" FROM "public"."User" WHERE 1=1 OFFSET $1 Params: [0] Duration: 3ms Query: SELECT "public"."Post"."id", "public"."Post"."title", "public"."Post"."authorId" FROM "public"."Post" WHERE "public"."Post"."authorId" IN ($1,$2,$3,$4) OFFSET $5 Params: [2, 7, 18, 29] Duration: 2ms ·
Vercel
qc.prisma-adp.vercel.app
Query Console
We cannot provide a description for this page right now
GitHub
github.com › Kinjalrk2k › prisma-console
GitHub - Kinjalrk2k/prisma-console: REPL style console for Prisma ORM, heavily inspired from Rails console · GitHub
Starred by 76 users
Forked by 3 users
Languages JavaScript
DEV Community
dev.to › this-is-learning › its-prisma-time-logging-4i7m
It's Prisma Time - Logging - DEV Community
January 26, 2022 - The level field can have query, info, warn, or error as values; whereas the emit field can have two values: stdout or event. If the "emit" value is equal to "stdout", the result of this log level will be written in the console, otherwise, if the value is "event", the result must be handled by a subscriber. But let’s clarify and see how to manage these logs. const prisma = new PrismaClient({ log: [ { emit: "event", level: "query", }, "info", "warn", "error", ], }); prisma.$on("query", e => { console.log("Query: " + e.query); console.log("Duration: " + e.duration + "ms"); });
Prisma
prisma.io › home › postgresql › postgresql › postgresql
How to add Prisma ORM to an existing project using PostgreSQL (15 min) | Prisma Documentation
Now you can use Prisma Client to query your database. Create a script.ts file: script.ts · import { prisma } from "./lib/prisma"; async function main() { // Example: Fetch all records from a table // Replace 'user' with your actual model name const allUsers = await prisma.user.findMany(); console.log("All users:", JSON.stringify(allUsers, null, 2)); } main() .then(async () => { await prisma.$disconnect(); }) .catch(async (e) => { console.error(e); await prisma.$disconnect(); process.exit(1); }); Run the script: bun ·
Prisma
prisma.io › home › query insights
Query Insights with Prisma Postgres | Prisma Documentation
Open the query detail view. Read the AI analysis and inspect the SQL. Copy the suggested prompt and paste it into your editor. Review the suggested change, then apply it in code or schema. Re-run the workload and compare the same signals again. In most cases, the next change falls into one of these buckets: ... const users = await prisma.user.findMany({ select: { id: true, name: true, email: true }, }); for (const user of users) { await prisma.post.findMany({ where: { authorId: user.id }, select: { id: true, title: true }, }); }
npm
npmjs.com › package › prisma-query-log
prisma-query-log - npm
import { createPrismaQueryEventHandler } from 'prisma-query-log'; import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient({ log: [ { level: 'query', emit: 'event', }, ], }); const log = createPrismaQueryEventHandler(); prisma.$on('query', log); function createPrismaQueryEventHandler( options?: CreatePrismaQueryEventHandlerArgs, ): (event: PrismaQueryEvent) => void; const defaultOptions = { /** * Boolean of custom log function, * if true `console.log` will be used, * if false noop - logs nothing.
» npm install prisma-query-log
Published Jul 01, 2024
Version 3.2.1
GitHub
github.com › prisma › prisma › issues › 5026
Printing full SQL queries with parameters in debug mode · Issue #5026 · prisma/prisma
February 19, 2020 - I am initializing prisma with {debug: true, log: ['info', 'query'],} and this is printing SQL queries without actual parameters, just ? to mask them. Wouldn't it be useful to pr...
Author prisma
npm
npmjs.com › package › prisma-query
prisma-query - npm
November 6, 2022 - import { processFindUniqueQuery } from 'prisma-query'; const req = { query: { _expand: 'comments', 'comments.user.name': 'justin' }, }; const args = processFindUniqueQuery(req.query); // JSON.stringify is used for clean output in the console console.log(JSON.stringify(args, null, 2)); /* { "include": { "comments": { "where": { "user": { "name": "justin" } } } } } */ // above args can be passed in model.findUnique function const post = await prismaClient.post.findUnique(args);
» npm install prisma-query
Published Nov 06, 2022
Version 2.0.0
Author Rahul Gupta
Repository https://github.com/rgsk/prisma-query
Top answer 1 of 3
4
Try checking your prisma instance. If it is like this:
export const prisma = new PrismaClient({
log:
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
});
Then, remove log: from options.
export const prisma = new PrismaClient();
2 of 3
1
Try handling your prisma errors with this code :
import { PrismaClient, Prisma } from '@prisma/client'
const client = new PrismaClient()
try {
await client.user.create({ data: { email: 'alreadyexisting@mail.com' } })
} catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError) {
// The .code property can be accessed in a type-safe manner
if (e.code === 'P2002') {
console.log(
'There is a unique constraint violation, a new user cannot be created with this email'
)
}
}
throw e
Run code snippetEdit code snippet Hide Results Copy to answer Expand
Also check this reference
Prisma
prisma.io
Prisma | Agent Infrastructure for TypeScript
Begin with Prisma ORM, add Prisma Postgres when you need managed infrastructure, and deploy your app on Prisma Compute. Try it out in the Console ·
Prisma
prisma.io › get started › prisma orm › start from scratch › relational databases
Querying the database using JavaScript and SQL Server | Prisma Documentation
March 21, 2020 - Adjust the main function to send a create query to the database: index.js · async function main() { await prisma.user.create({ data: { name: 'Alice', email: 'alice@prisma.io', posts: { create: { title: 'Hello World' }, }, profile: { create: { bio: 'I like turtles' }, }, }, }) const allUsers = await prisma.user.findMany({ include: { posts: true, profile: true, }, }) console.dir(allUsers, { depth: null }) } This code creates a new User record together with new Post and Profile records using a nested write query.