import { SQLDataSource } from 'datasource-sql'; import { Market } from '../types/market-types'; const MINUTE = 60; // TODO: perhaps rename to MarketLocale API and add market_locales and locales here. export class MarketAPI extends SQLDataSource { constructor(config) { super(config); } async getMarketById(id: number): Promise { return this.knex .select('*') .from('markets') .where('id', id) .first() .cache(MINUTE * 5); } async getMarketByName(name: string): Promise { return this.knex .select('*') .from('markets') .where('name', name) .first() .cache(MINUTE * 5); } async getMarkets(): Promise> { return this.knex .select('*') .from('markets') .cache(MINUTE * 5); } }