Query Extensions
Query extensions are methods added to standard WireBootstrap select queries that are specific to a data connector.
Creating an Extension
To create an extension, override the base wire.data.select
function and then add methods to the new version.
wire.data.select = function () {
let self = select.apply(null, arguments);
self.myMethod = function(){
///
}
}
Methods
Query extensions can be used for a variety of operations specific to a data connector.
Here, a method is used to wrap a category
filter on a specific value
.
wire.data.select = function () {
...
self.category = function(value){
return self.eq("category", value);
}
}
This new method can now be used to create a standard query.
const query = wire.data.select().from("product").category("apples");
Custom Property
Query extensions can also be used to pass custom data to a data connector. Use the Custom
property on the TableQuery class inside the extension method to pass custom data to a data connector.
The following example is a short/modified version of a method taken from the WireBootstrap for Azure search query extension.
wire.data.select = function () {
...
self.facet = function(field){
self.Custom = self.Custom || {};
self.Custom.facets = self.Custom.facets || [];
self.Custom.facets.push(field);
return this;
}
}
Last updated
Was this helpful?