mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2026-02-02 07:40:43 +03:00
Switch to postgres + promises
This commit is contained in:
31
src/databases/Postgres.ts
Normal file
31
src/databases/Postgres.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user