Skip to content

tRPC (on nextjs) kill not awaited Prisma #1474

Answered by HardCoreQual
HardCoreQual asked this question in Q&A
Discussion options

You must be logged in to vote

I'm sorry, Prisma doesn't work as I expected

      prisma.posts.create({
        data: {postId, ...input}
      });

don't start promise, promise started only after call .then()

I don't want use await prisma.post.create() but can use prisma.post.create().then() or prisma.$transaction([prisma.post.create()])

the correct version of initial code

  .mutation('post.add', {
    input: z.object({ title: z.string(), text: z.string() }),
    async resolve({ input }) {
      const postId = await useExternApiForPublicThisPost(input);
      
      // save change in my database, but not await response
      prisma.posts.create({
        data: {postId, ...input}
      }).then();
    }
  })

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@KATT
Comment options

Answer selected by HardCoreQual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1473 on January 30, 2022 20:12.