The bug
Prisma client mutations do not get executed without await or callback.
To Reproduce
Using Prisma JS client:
index.js
const { prisma } = require('./generated/prisma')
const foo = async () => {
await prisma.updateManyLoans({ data: { isCanceled: true } }) // Gets executed
}
foo()
const bar = () => {
prisma.updateManyLoans({ data: { isCanceled: true } }) // Doesn't get executed
}
bar()
prisma.updateManyLoans({ data: { isCanceled: true } }).then() // Gets executed
prisma.updateManyLoans({ data: { isCanceled: true } }) // Doesn't get executed
Expected behavior
Expect prisma.updateManyPosts({ data: { isCanceled: true } }) to get executed and be reflected in the DB.
Versions:
Windows 10prisma CLI: prisma/1.19.0 (windows-x64) node-v8.11.21.19.0graphql-cli: 2.16.5prisma-client-lib: 1.19.0Additional context
I need to create a job task to be executed every day, for that I want to run a prisma client mutation.
Hey @Elfayer ,
is it a problem for you that you need to await it? The prisma client is intentionally designed in a lazy way so that queries are executed only when the developer consumes the promise.
Hi @mavilein , thanks for the quick answer!
I was hopping to be able to run multiple parallel commands at the same time. It is also confusing that nothing happens, since it is described to work as a Promise.
Is this meant to avoid consistency issues?
It is mostly used to allow for chaining in queries, e.g. the example from the homepage:
await prisma
.post({ id: "cjl4srkaqqxa30b46pqcyzpyo" })
.comments()
This results in one query being sent to the backend. If the evaluation would be eager we would have two roundtrips to the server.
@Elfayer you can execute multiple queries in parallel like this in JS/TS:
const q1 = prisma.posts() // no await here
const q2 = prisma.users() // no await here
const [posts, users] = await Promise.all([q1, q2])
Does that answer your question?
@mavilein @schickling Makes sense thanks to you two! ;)