Switch to postgres + promises

This commit is contained in:
Ajay Ramachandran
2021-03-01 20:40:31 -05:00
parent 9a9038d5e0
commit ff4af3786e
37 changed files with 424 additions and 291 deletions

31
src/databases/Postgres.ts Normal file
View File

@@ -0,0 +1,31 @@
import { Logger } from '../utils/logger';
import { IDatabase, QueryType } from './IDatabase';
import { Pool } from 'pg';
export class Mysql implements IDatabase {
private pool: Pool;
constructor(private config: any) {}
init(): void {
this.pool = new Pool();
}
async prepare(type: QueryType, query: string, params: any[]) {
Logger.debug(`prepare (postgres): type: ${type}, query: ${query}, params: ${params}`);
const queryResult = await this.pool.query(query, params);
switch (type) {
case 'get': {
return queryResult.rows[0];
}
case 'all': {
return queryResult.rows;
}
case 'run': {
break;
}
}
}
}