vexdb is a wrapper for VexDB.
- Promise Based
- Isomorphic: Works both in the browser and in Node.js
- Simple, but powerful filtering
- Smart cache
- Live API
- Complete TypeScript Definitions (it's written in TypeScript)
Install this package with yarn:
yarn add vexdb
or, if you want to use npm:
npm i vexdb
Retrieves data from an endpoint with the specified parameters. These parameters can include any that can be specified to VexDB, as well as final values in the response object.
Normally, vexdb limits responses to 5000 items per request.
vexdb will make enough requests to ensure that all applicable matches are returned
// Get all events in StarStruckvar vexdb = ;vexdb;// Get all teams from Californiavexdb;
This works basically identically to
.get(), but returns the number of items that fit this result.
// Get the number of all teams in Californiavexdbsize"teams" region: "California" ;// All examples from .get() above would work here...
Depending on the parameters specified,
size()may or may not send
nodatarequests. In order to minimize bandwidth, you'll want to only include parameters that can be passed directly to VexDB
In many cases, you'll want to share headers and parameters across requests. This can be done using
Warning: Because of the Cross Origin Policy, setting headers using
vexdb.constants.headermay cause the browser to automatically block requests to
https://api.vexdb.io. It is not reccomended to use headers in the browser.
Since VexDB only updates every 4 minutes, this module will prevent repeat requests by resolving them with the previous value immediately. You can control this behavior with
vexdb uses my own
keya module to handle cache. In Node, caching will take place using sqlite, while in the browser, caches will be stored first in IndexedDB
Update the Time To Live for new caches
See if a cache is present
vexdbcache; // Boolean
Directly resolve a cached value
vexdbcache; // The resolved value, or undefined if the cache isn't present
Clear the cache
This module also supports basic live features. Specify an endpoint and parameters (passed through to
get()) and recieve updates on new items that fit that criteria
Note that the
item event will trigger for every result on the inital poll. This means that every item that fits the parameters will be passed to
item. If you do not want this to be the case, specify
prefetch: true in your listed parameters
// Only new matches will trigger itemvexdb;
Emitted on a successful fetch
Emitted when a prefetch has been completed
Emitted for each new item
Emitted for each new item
Stop new polls
params(newParams: Object): Object
Override request parameters for future requests. Note: this does not change the current index of results
Returns the current cache of results