pg-live-query
This package makes it possible in PostgreSQL to get (almost) realtime notifications whenever the results of a query change.
Usage
To use this package, you need to also use the amazing pg driver for PostgreSQL.
const Pool = Pool;const LiveQuery = ; const pool = ; // Or however you set up pg pool;
How it Works
This package should provide much better performance than it used to. I definitely wouldn't consider it production-ready, but that's at least a feasible goal now.
The way it works is by computing an aggregate unique id and latest revision based on columns (that this package adds) from each input row that contributed to a particular output row. It also stores the previous state of the result set in a temporary table. This makes it trivial to compute the differences between two result sets from different executions of the same query inside the database, instead of in Node.
Known Issues
- Queries with implicit grouping don't work (SELECT MIN(id) FROM foo)
To Test
- Queries with CTEs
- Queries with UNIONs
- Queries that select scalar values that change each time the query is run (nextval, current_timestamp)
Note: This package was previously "deprecated" in favor of pg-live-select. It has since been completely rewritten with a fundamentally different mechanism for determining changes. It should greatly outperform both pg-live-select and any previous versions of this package.