import { DataSource } from 'typeorm'; import path from 'path'; import debug from 'debug'; import { User } from './entity/User'; import { DatabaseConfig } from './config'; const log = debug('snowball:database'); export class Database { private dataSource: DataSource; constructor ({ dbPath }: DatabaseConfig) { this.dataSource = new DataSource({ type: 'better-sqlite3', database: dbPath, entities: [path.join(__dirname, '/entity/*')], synchronize: true, logging: false }); } async init () : Promise { await this.dataSource.initialize(); log('database initialized'); } async getUser (userId: number) : Promise { const userRepository = this.dataSource.getRepository(User); const user = await userRepository.findOneBy({ id: userId }); return user; } }