ffffng/server/db/__mocks__/database.ts

49 lines
1.6 KiB
TypeScript
Raw Normal View History

import {RunResult, SqlType, Statement, TypedDatabase} from "../../types";
2022-07-18 17:49:42 +02:00
import * as sqlite3 from "sqlite3";
2022-07-18 17:49:42 +02:00
export async function init(): Promise<void> {
}
2022-07-18 17:49:42 +02:00
export class MockDatabase implements TypedDatabase {
constructor() {
}
2022-07-18 17:49:42 +02:00
async on(event: string, listener: any): Promise<void> {
}
2022-07-18 17:49:42 +02:00
async run(sql: SqlType, ...params: any[]): Promise<RunResult> {
return {
stmt: new Statement(new sqlite3.Statement()),
};
}
2022-07-18 17:49:42 +02:00
async get<T = any>(sql: SqlType, ...params: any[]): Promise<T | undefined> {
return undefined;
}
2022-07-18 17:49:42 +02:00
async each<T = any>(sql: SqlType, callback: (err: any, row: T) => void): Promise<number>;
async each<T = any>(sql: SqlType, param1: any, callback: (err: any, row: T) => void): Promise<number>;
async each<T = any>(sql: SqlType, param1: any, param2: any, callback: (err: any, row: T) => void): Promise<number>;
async each<T = any>(sql: SqlType, param1: any, param2: any, param3: any, callback: (err: any, row: T) => void): Promise<number>;
async each<T = any>(sql: SqlType, ...params: any[]): Promise<number>;
async each(sql: SqlType, ...callback: (any)[]): Promise<number> {
return 0;
}
2022-07-18 17:49:42 +02:00
async all<T>(sql: SqlType, ...params: any[]): Promise<T[]> {
return [];
}
2022-07-18 17:49:42 +02:00
async exec(sql: SqlType, ...params: any[]): Promise<void> {
}
2022-07-18 17:49:42 +02:00
async prepare(sql: SqlType, ...params: any[]): Promise<Statement> {
return new Statement(new sqlite3.Statement());
}
}
export const db: MockDatabase = new MockDatabase();
2022-07-18 17:49:42 +02:00
export {TypedDatabase, Statement}