Comparing version 4.7.2 to 4.8.0
@@ -101,1 +101,14 @@ # Queries | ||
``` | ||
## refresh | ||
`refresh` can be used with [materialized views](https://www.postgresql.org/docs/current/static/rules-materializedviews.html), which cache the view query results to sacrifice realtime updates for performance. Materialized views must be refreshed whenever you need to ensure the information in them is up to date. | ||
Materialized views ordinarily block reads while refreshing. To avoid this, invoke the function passing `true` to specify a concurrent refresh. | ||
`refresh` returns an empty query result. | ||
```javascript | ||
db.cached_statistics.refresh(true) // concurrently | ||
.then(() => {...}); | ||
``` |
@@ -17,3 +17,4 @@ 'use strict'; | ||
* @extends Entity | ||
* @param {Object} spec - An {@linkcode Entity} specification representing a queryable: | ||
* @param {Object} spec - An {@linkcode Entity} specification representing a | ||
* queryable: | ||
* @param {Object} spec.db - A {@linkcode Database}. | ||
@@ -23,5 +24,9 @@ * @param {String} spec.name - The table or view's name. | ||
* view. | ||
* @param {Boolean} [spec.is_matview] - Whether the object is a materialized view | ||
* (default false). | ||
*/ | ||
const Queryable = function () { | ||
const Queryable = function (spec) { | ||
Entity.apply(this, arguments); | ||
this.isMatview = spec.is_matview || false; | ||
}; | ||
@@ -112,2 +117,18 @@ | ||
/** | ||
* Refresh a materialized view. | ||
* | ||
* @param {Boolean} [concurrently] - Do it without locking reads. | ||
* @return {Promise} A query with no results. | ||
*/ | ||
Queryable.prototype.refresh = function (concurrently) { | ||
if (!this.isMatview) { | ||
return this.db.$p.reject(new Error(`${this.delimitedName} is not a materialized view`)); | ||
} | ||
const concurrentlyStr = concurrently ? 'CONCURRENTLY' : ''; | ||
return this.db.query(`REFRESH MATERIALIZED VIEW ${concurrentlyStr} ${this.delimitedName}`); | ||
}; | ||
/** | ||
* Determine whether criteria represent a search by primary key. If a number or | ||
@@ -114,0 +135,0 @@ * uuid are passed, it is assumed to be a primary key value; if an object, it |
{ | ||
"name": "massive", | ||
"version": "4.7.2", | ||
"version": "4.8.0", | ||
"description": "A small query tool for Postgres that embraces json and makes life simpler", | ||
@@ -58,3 +58,3 @@ "homepage": "https://dmfay.github.io/massive-js/", | ||
"lodash": "~4.17.4", | ||
"pg-promise": "~8.2.0", | ||
"pg-promise": "~8.4.0", | ||
"pg-query-stream": "~1.1.1" | ||
@@ -70,3 +70,3 @@ }, | ||
"mocha": "~5.1.0", | ||
"nyc": "~11.6.0" | ||
"nyc": "~11.7.1" | ||
}, | ||
@@ -73,0 +73,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
159612
2059
+ Addedpg@7.4.3(transitive)
+ Addedpg-promise@8.4.6(transitive)
- Removedjs-string-escape@1.0.1(transitive)
- Removedpg@7.4.1(transitive)
- Removedpg-promise@8.2.3(transitive)
Updatedpg-promise@~8.4.0