Sam Clark

Sam Clark

Read more posts by this author.

< 1 min read

BaseModel.js

const { Model } = require('objection');

class BaseModel extends Model {
  static get QueryBuilder() {
    return CustomQueryBuilder;
  }

  static get namedFilters() {
    paging: builder => {
        const context = builder.context();
        builder.page(context.page || 0, context.page_size || 30);
     },
  }
}

Something.js

class Something extends BaseModel {
  static get tableName() {
    return 'somethings';
  }
  // Something inherits filters from BaseModel

}

Calling lense

const somethingQuery = Something
  .query().context({page: 0, page_size: 50})
  .applyFilter('paging')
return somethingQuery;