mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-11 22:17:14 +03:00
Update tests to use promises
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
export interface IDatabase {
|
||||
init(): void;
|
||||
|
||||
prepare(type: QueryType, query: string, params: any[]): Promise<any | any[] | void>;
|
||||
prepare(type: QueryType, query: string, params?: any[]): Promise<any | any[] | void>;
|
||||
}
|
||||
|
||||
export type QueryType = 'get' | 'all' | 'run';
|
||||
|
||||
@@ -13,7 +13,7 @@ export class Mysql implements IDatabase {
|
||||
this.connection = new MysqlInterface(this.config);
|
||||
}
|
||||
|
||||
prepare(type: QueryType, query: string, params: any[]) {
|
||||
prepare(type: QueryType, query: string, params?: any[]) {
|
||||
Logger.debug(`prepare (mysql): type: ${type}, query: ${query}, params: ${params}`);
|
||||
const queryResult = this.connection.query(query, params);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ export class Mysql implements IDatabase {
|
||||
this.pool = new Pool();
|
||||
}
|
||||
|
||||
async prepare(type: QueryType, query: string, params: any[]) {
|
||||
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);
|
||||
|
||||
|
||||
@@ -12,18 +12,30 @@ export class Sqlite implements IDatabase {
|
||||
{
|
||||
}
|
||||
|
||||
async prepare(type: QueryType, query: string, params: any[]) {
|
||||
async prepare(type: QueryType, query: string, params?: any[]) {
|
||||
const preparedQuery = this.db.prepare(query);
|
||||
|
||||
switch (type) {
|
||||
case 'get': {
|
||||
return preparedQuery.get(...params);
|
||||
if (params) {
|
||||
return preparedQuery.get(...params);
|
||||
} else {
|
||||
return preparedQuery.get();
|
||||
}
|
||||
}
|
||||
case 'all': {
|
||||
return preparedQuery.all(...params);
|
||||
if (params) {
|
||||
return preparedQuery.all(...params);
|
||||
} else {
|
||||
return preparedQuery.all();
|
||||
}
|
||||
}
|
||||
case 'run': {
|
||||
preparedQuery.run(...params);
|
||||
if (params) {
|
||||
preparedQuery.run(...params);
|
||||
} else {
|
||||
preparedQuery.run();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user