Hey there, I try to understand the concept behind ...
# orm-help
s
Hey there, I try to understand the concept behind Prisma Middleware. In the docs it says:
Middlewares act as query-level lifecycle hooks, which allow you to perform an action before or after a query runs.
When running a nested write or update query, is there any chance to get the result of all the queries/statements executed? Or am I on a prisma-client-function-level when in a Middleware and the result is the result returned from that client call? Something like
Copy code
prisma.user.create({
  data: {
    email: '<mailto:elsa@prisma.io|elsa@prisma.io>',
    name: 'Elsa Prisma',
    posts: {
      create: [{ title: 'How to make an omelette' }, { title: 'How to eat an omelette' }],
    },
  },
  include: {
    posts: true, // Include all posts in the returned object
  },
})
j
The middleware is only on the Client Query level - so the
next()
function call will split this apart into the individual bits, do the magic, and then return all the data.
Unfortunately you can not go in between the individual steps - you "only" can do things before and after the query is executed. So for example manipulate the params before, and then the returned data afterwards.
s
Ok, thanks @janpio
j
What are you trying to do here? Maybe there are other ways.
s
Basically I want to know which nested resources have been created. With the above example it is easy, since everything is created, everything is new. But say I have an
update
to the user and within that update an post gets updated too. I would like to get that updated Post for further processing. Ideally it would be possible to retrieve changesets on/after operations