将新的数据行添加到Postgresql数据库时如何更新前端

时间:2019-03-12 18:51:15

标签: javascript postgresql

我创建了一个电子邮件解析器,该解析器接收传入的电子邮件,剥离一些数据并将其插入到postgres数据库中。该数据反映在前端。每当我从电子邮件中插入新的一行数据时,我都必须刷新前端才能看到新数据。当有新数据插入postgres时,有没有办法从前端触发我预先存在的API GET请求,以便我可以在前端看到实时数据更新?

1 个答案:

答案 0 :(得分:0)

You have two primary options:

  • Use technique so-called long polling, when the frontend requests for some data from the server, server checks whenever there is a new record to send back if there is a record(s) it sends a response if there is not, it keeps the connection opened until the new record appears.
  • Use socket connection (bidirectional client-server communication), when the client opens a socket connection and waits for a specific event to be emitted by the server