You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently implementing CDC in a web application on top of postgres.
I want to:
Fetch the users table
Be notified whenever the users table changes and update my local copy
But obviously, I also need to be careful of the race condition: What happens if the data is modified between my fetch and subscribe calls?
The "right answer", as far as I can tell, is to get the WAL log location (lsn) along with my fetch query, and then subscribe to all changes from that location onwards. For example, to fetch:
letstartLsn{awaitsql.begin('ISOLATION LEVEL REPEATABLE READ',asyncsql=>{constlsnResult=awaitsql`SELECT pg_current_wal_lsn() as lsn`;startLsn=lsnResult[0].lsnconstresult=awaitsql<User[]>`SELECT * FROM users`;result.forEach((user)=>{users.set(user.id,user);});})}
But then to subscribe I need to pass the LSN in. I want to make this query:
I'm currently implementing CDC in a web application on top of postgres.
I want to:
But obviously, I also need to be careful of the race condition: What happens if the data is modified between my fetch and subscribe calls?
The "right answer", as far as I can tell, is to get the WAL log location (lsn) along with my fetch query, and then subscribe to all changes from that location onwards. For example, to fetch:
But then to subscribe I need to pass the LSN in. I want to make this query:
Unfortunately, the subscription code in postgres can't do this as far as I can tell?
The text was updated successfully, but these errors were encountered: