Query Records

The easiest way to turn your records into easily queryable data is to use the .toArray() method to convert your records to an array.

Once converted, you can use all of the native JavaScript array methods such as .find(), .filter(), .map(), .reduce(), .every() and more.

Usage

.toArray(): Model[]

Example

// load data
const data = {
    instruments = await new InstrumentModel().load()
};

// convert instrument records to array
const instrumentsArray = data.instruments.toArray();

// find brass instruments
const brassInstruments = instrumentsArray.filter((instrument) => {
    return instrument.type === 'brass';
});

// sort instruments
const sortedInstruments = instrumentsArray.sort((instrument) => {
    if (a.name < b.name) {
        return -1;
    } else if (a.name > b.name) {
        return 1;
    }
    return 0;
});