Is there a performance difference between using a ...
# orm-help
s
Is there a performance difference between using a prisma function like .users() at the end of a db query vs querying the table directly for users? If so which is best, seems .users() gets a record first then finds related users so seems less effective then just querying users table directly?
šŸ‘ 1
r
Hey @Shehab šŸ‘‹ In which case would you be checking this for? Also in the Prisma client you can view the queries by passing this as a parameter
Copy code
const prisma = new PrismaClient({
  log: ['query'],
})
Then you would be able to view the queries perfomed as well
s
Hi @Ryan well I have a lot of cases where I can either use the function that was created by prisma when I specified the relationships between the tables in my schema.prisma file or I am query the Tables directly. Like say I had a many to many relationship between two tables users and workspaces, I can directly get the workspaces of a user by querying my explicit join table like db.useronworkspace.findMany({where{userId obj.id}) or I can use a prisma function and instead say dB.user.findOne({where: id:obj.id}).workspaces(). Both will give me the same thing but I’m not sure which is better to use. It seems like I said that the prisma function has to first get the user record and then use that to find the associated records in the join table instead of just finding the records from join table using the id. I will add that log and compare queries also
I have tried adding the log inside of my prisma client as you said but i do not seen any queries being logged..?
r
You are on Prisma2?
Because if you're using Prisma2, you can directly add the above field in the client and check all the queries that are generated for you above use cases šŸ™‚
s
Yes, prisma 2, i have added it in my seeds file. i dont see any queries in my console except the graphql queries not sql