Is there a function with prisma to subscribe to it...
# prisma-client
d
Is there a function with prisma to subscribe to items being added? I have no graphql server only prisma.
t
Prisma 1 comes with subscriptions via websockets, is that what you’re asking? https://www.prisma.io/docs/prisma-client/features/realtime-TYPESCRIPT-rsc9/#limitations
d
@tmoney Thanks for your reply! My setup basically has no frontend. I have only a backend application with a scheduler which performs an action to retrieve data for my prisma database. Now I want to execute an alert message (in my nodejs application) when data is being added -- So I think websockets are not the right use case for this
I will try this now:
Copy code
const createdUserIterator = await db.$subscribe
  .user({
    mutation_in: ['CREATED'],
    node: {
      email_contains: `<mailto:alice@prisma.io|alice@prisma.io>`,
    },
  })
  .node()
t
Oh ok, ya you usually need another graphql server to have that code you just posted to actually hit the prisma server. You can hit it directly from like a lambda, but then you don’t get the security and control benefits of having your own server
d
okay alright then I need to think about something else. Right now I have a setInterval() which checks for new items every 5 minutes and inserts the items into the database. As the createItem function always returns what you added, even if it's already in the database, I now need to figure out how to check if there has been a new item added to the database. Do you have any idea for that? 😄
Thanks for your help again! 🙂 much appreciated