Skip to content

Run side effects when entities are updated/deleted #24121

Closed Answered by ludralph
m1212e asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @m1212e

Prisma does not directly support side effects or hooks that would allow you to automatically trigger API calls on database operations like create, update, or delete.

One way to do this is by using the repository pattern, as you mentioned. In this pattern, you would create a repository for each entity in your system. Each repository would contain the logic for interacting with the database using Prisma, as well as the logic for making the necessary API calls to the external system. For example:

class UserRepository {
  constructor(prismaClient, externalApiClient) {
    this.prisma = prismaClient;
    this.externalApi = externalApiClient;
  }

  async createUser(data) {
    // Cr…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@m1212e
Comment options

@ludralph
Comment options

Answer selected by m1212e
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants