37 lines
817 B
TypeScript
37 lines
817 B
TypeScript
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<Market> {
|
|
return this.knex
|
|
.select('*')
|
|
.from('markets')
|
|
.where('id', id)
|
|
.first()
|
|
.cache(MINUTE * 5);
|
|
}
|
|
|
|
async getMarketByName(name: string): Promise<Market> {
|
|
return this.knex
|
|
.select('*')
|
|
.from('markets')
|
|
.where('name', name)
|
|
.first()
|
|
.cache(MINUTE * 5);
|
|
}
|
|
|
|
async getMarkets(): Promise<Array<Market>> {
|
|
return this.knex
|
|
.select('*')
|
|
.from('markets')
|
|
.cache(MINUTE * 5);
|
|
}
|
|
}
|