Is it possible to get only the query as a string i...
# prisma-client
l
Is it possible to get only the query as a string instead of sending the query to the engine? For example if I do
prisma.user.findOne({...})
I would like to get the query statement only and don't make the call. I know is possible to enable logs in the prisma client, but I am looking for something more specific where I can access the query builder result instead. Something like
prisma.user.findOne({...}).getRawQuery().
That would not make any call to the db but just get the query statement from the engine. Would be awesome! Any directions on how I can accomplish this? Thank you!
j
Interesting request, I do not think we have ever thoughts about this.
What is your usecase for having the raw query(ies)?
Definitely worth creating an issue for at https://github.com/prisma/prisma-client-js/issues
👍 1
l
That opens the possibility to use prisma client as query builder only but what I wanted is to be able to visualize the query that is going to execute in some sort of playground editor
👍 1
You could paste your schema.prisma file and write queries/mutations with the generated client to see the queries being built in real time
🔥 3
j
Right now you can do this
Copy code
const prisma = new PrismaClient({
  log: ['query'],
});

// or as events
const prisma = new PrismaClient({
  log: [
    {
      emit: 'event',
      level: 'query',
    },
  ],
});

prisma.on('query', e => {
  e.timestamp;
  e.query;
  e.params;
  e.duration;
  e.target;
  console.log(e);
});
l
Yes I am aware of this, but I would like to get this queries without actually hitting the db
👍 2
j
@Lucas Munhoz I just created this issue https://github.com/prisma/prisma-client-js/issues/746 let me know what you think and feel free to add feedback 🙂
j
(I think just a few days ago I or someone I talked to created an issue about this as well.)
🤷‍♂️ 1