Update tests to use promises

This commit is contained in:
Ajay Ramachandran
2021-03-01 21:37:35 -05:00
parent ff4af3786e
commit 46b42da5bd
19 changed files with 274 additions and 259 deletions

View File

@@ -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';

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
}
}