Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
629 views
in Technique[技术] by (71.8m points)

postgresql - How to connect TYPEORM subscriber to client when using tech stack such as NextJS-NestJS

I'm having a hard time figuring out how to retrieve updated data from postgres database on client side (NextJS) using TYPEORM subscriber.

I used event.connection.query(SQL query here); inside the subscriber file to get updated data every time the user inserts new data. I'm using afterInsert method so that it listens every time the user makes an insert action from the browser.

  async afterInsert(event: InsertEvent<any>) {
    return await event.connection.query('SELECT * FROM movie_list');
    // console.log(event.connection.createQueryBuilder(TABLE NAME here).getMany());
  }

I can check that NestJS is successfully listening to changed data by logging out the output. How can I exactly listen that on the client side aka NextJS? I first attempted to send a GET request to the server using useEffect or every 10 seconds using setTimeout. But I believe this is not the best solution.

Should I use something like WebSocket?

Thanks guys. Be careful of corona!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...