Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
pg-live-query
Advanced tools
This package makes it possible in PostgreSQL to get (almost) realtime notifications whenever the results of a query change.
To use this package, you need to also use the amazing pg driver for PostgreSQL.
const Pool = require('pg').Pool;
const LiveQuery = require('pg-live-query');
const pool = new Pool(); // Or however you set up pg
pool.connect((error, client, done) => {
const lq = new LiveQuery(client);
const sql = `
SELECT
*
FROM
users u JOIN
logins l ON
l.user_id = u.id
WHERE
l.date > '2016-01-01'
`;
// To get 'insert', 'update', 'delete', and 'changes' events
const handle = lq.watch(sql);
// To get the above plus an additional 'rows' event with the full rowset
// This consumes more memory as it has to maintain the current state of the rowset
const handle = lq.query(sql);
// The "update" event looks the same as "insert"
// They contain the id, row data (as an array), and column names
handle.on('insert', (id, row, cols) => {
const out = {};
cols.forEach((col, i) => {
out[col] = row[i] || null;
});
console.log('row inserted', id, row);
});
// The "delete" event only contains the id
handle.on('delete', (id) => {
console.log('row deleted', id);
});
// The "changes" event contains several changes batched together
handle.on('changes', (changes) => {
changes.forEach(({ id, rn, data }) => {
if(data) {
console.log(`upsert: ${id} at row ${rn}`, data);
}
else {
console.log(`delete: ${id}`);
}
});
});
// The "rows" event contains an array of objects
// that represent the entire current result set
handle.on('rows', (rows) => {
console.log('all rows', rows);
});
});
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.
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.
FAQs
(Almost) realtime query update events in PostgreSQL
The npm package pg-live-query receives a total of 6 weekly downloads. As such, pg-live-query popularity was classified as not popular.
We found that pg-live-query demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.