When you execute a query with the find()
function, it returns a Promise that resolves to an EventsQueryResult
object.
This object contains the items that match the query, information about the
query itself, and functions for paging through the query results.
Returns the index of the current results page number.
The currentPage
is a zero-based index of the current page of results.
The page size is defined by the limit()
function, can be retrieved using the pageSize
property, and
navigating through pages is done with the prev()
and
next()
functions.
The currentPage
property returns undefined
if the query returned no results.
const resultPage = results.currentPage; // 0
Returns the items that match the query.
The current page of Wix events retrieved by the query.
Note: When no items match the query, the items
array is empty.
To paginate your query results, use the EventsQueryResult
pagination properties and functions.
import { wixEvents } from "wix-events-backend";
// ...
wixEvents
.queryEvents()
.find()
.then((results) => {
if (results.items.length > 0) {
const items = results.items;
const firstItem = items[0];
const totalCount = results.totalCount;
const pageSize = results.pageSize;
const currentPage = results.currentPage;
const totalPages = results.totalPages;
const hasNext = results.hasNext();
const hasPrev = results.hasPrev();
const length = results.length;
const query = results.query;
} else {
// handle case where no matching items found
}
})
.catch((error) => {
const queryError = error;
});
const resultLength = results.length; // 20
const resultPageSize = results.pageSize; // 50
Contains functionality for refining a Wix events query.
The EventsQueryBuilder
functions enable you to run, sort, filter, and control
which results a query returns.
Typically, you build a query using any of the event query functions,
refine the query by chaining EventsQueryBuilder
functions, and then execute the
query by chaining the find()
function.
For example, the following code returns the first 5 upcoming Wix events created by a given event manager, including scheduled events and events that have started. The events are listed in ascending order by the event's start date.
import { wixEvents } from 'wix-events-backend';
wixEventsBackend.queryEvents()
.eq("createdBy", "4c47c608-cfa8-4037-93ac-738f09560ed3")
.hasSome("status", ["SCHEDULED", "STARTED"])
.ascending("scheduling.startDate")
.limit(5)
.find()
.then( (results) => {
console.log(results.items);
} );
const resultQuery = results.query;
Returns the total number of items that match the query.
The totalCount
returns the total number of items that match the query,
not just the number of items in the current page.
const resultCount = results.totalCount; // 150
const resultPages = results.totalPages; // 3
Indicates if the query has more results.
function hasNext(): boolean;
const hasNext = results.hasNext(); // true