Subscribing to database events with @prisma/extension-pulse

Is it possible to suscribe to database events with pulse for the moment? If not, how can I follow easily database event for the moment?
12 Replies
kapa.ai
kapa.ai8mo ago
Hi @Estelle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The knowledge sources provided do not contain information about subscribing to database events with @prisma/extension-pulse in the context of Wasp. However, Wasp uses Prisma to interact with the database, and Prisma is a "Next-generation Node.js and TypeScript ORM" that provides a type-safe API for working with your database. You might find more information on this topic in the Prisma documentation (https://www.prisma.io/docs/concepts/components/preview-features/client-preview-features). For more specific information about Wasp and its interaction with databases, you can refer to the Wasp documentation (https://wasp-lang.dev/docs/data-model/backends#prisma-configuration). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Estelle, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Estelle
EstelleOP8mo ago
@kapa.ai follow up?
kapa.ai
kapa.ai8mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- I'm sorry, but I need more context to provide a follow-up answer. Could you please provide more details or clarify your question? ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Estelle, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Vinny (@Wasp)
Vinny (@Wasp)8mo ago
Hey Estelle. What's your end goal here?
Vinny (@Wasp)
Vinny (@Wasp)8mo ago
I'm not aware of pulse but if it's a Postgres/Prisma extension you can add it like this: https://wasp-lang.dev/docs/data-model/backends#postgresql-extensions
Databases | Wasp
Entities, Operations and Automatic CRUD together make a high-level interface for working with your app's data. Still, all that data has to live somewhere, so let's see how Wasp deals with databases.
Estelle
EstelleOP8mo ago
My goal is to do some action when I (for example) : - create a new line in a table - update a line in a table - update some specific columns in a table etc so I need to "suscribe" to these events, but idk if it's possible with wasp Example with pulse : import { PrismaClient } from '@prisma/client' import { withPulse } from '@prisma/extension-pulse' const prisma = new PrismaClient().$extends( withPulse({ apiKey: process.env.PULSE_API_KEY }) ) Then : const prisma = new PrismaClient().$extends(withPulse({ apiKey: apiKey })) async function main() { const subscription = await prisma.notification.subscribe() for await (const event of subscription) { console.log('just received a notification:', event) } } main() Like an event trigger on hasura, to automate asynchronous logic when changes are made in a connected database I will use your job for the moment it will do the work I want In your doc, it's written that it's "recommended for low-volume production use cases" Can you be more specific?
miho
miho8mo ago
Since the jobs are executed on the same server where you main app is running, you can't really scale it yet to extra worker servers and get high-availability and throughput. These are some things we want to figure out for 1.0 but right now the jobs implementation we have is sufficient for most apps. cc: @martinsos Also, given what you written here:
import { PrismaClient } from '@prisma/client'
import { withPulse } from '@prisma/extension-pulse'

const prisma = new PrismaClient().$extends(
withPulse({ apiKey: process.env.PULSE_API_KEY })
)
import { PrismaClient } from '@prisma/client'
import { withPulse } from '@prisma/extension-pulse'

const prisma = new PrismaClient().$extends(
withPulse({ apiKey: process.env.PULSE_API_KEY })
)
It seems to me that we should offer some sort of a "prismaSetup" hook where you can enrich the default PrismaClient
Estelle
EstelleOP8mo ago
Yes thank you
martinsos
martinsos8mo ago
@Estelle curious, why do you need to listen to these events in the DB, is that because those modifications to the DB are being done by some external process that is not a Wasp app? Do you have some kind of special use case?
Estelle
EstelleOP8mo ago
@martinsos I have a complex app, and the db can be "touched" by a lot of different points. When I add a line in my db, I need a script to run with this line. I don't want to repeat myself each time in the code, and I need it to be working even though my dev working on the app don't have the full picture. If I can trigger on the "create" on the db, I don't repeat myself in the code and it will ALWAYS work
MEE6
MEE68mo ago
Wohooo @Estelle, you just became a Waspeteer level 2!
martinsos
martinsos8mo ago
Makes sense, thanks!
Want results from more Discord servers?
Add your server