This commit is contained in:
Ajay Ramachandran
2021-09-27 20:17:24 -04:00
95 changed files with 2727 additions and 2957 deletions

View File

@@ -1,5 +1,5 @@
import {Logger} from "../utils/logger";
import {IDatabase, QueryType} from "./IDatabase";
import { Logger } from "../utils/logger";
import { IDatabase, QueryType } from "./IDatabase";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import MysqlInterface from "sync-mysql";
@@ -10,6 +10,7 @@ export class Mysql implements IDatabase {
constructor(private config: unknown) {
}
// eslint-disable-next-line require-await
async init(): Promise<void> {
this.connection = new MysqlInterface(this.config);
}

View File

@@ -57,7 +57,7 @@ export class Postgres implements IDatabase {
try {
const client = await this.pool.connect();
const queryResult = await client.query({text: query, values: params});
const queryResult = await client.query({ text: query, values: params });
client.release();
switch (type) {

View File

@@ -1,9 +1,9 @@
import {IDatabase, QueryType} from "./IDatabase";
import Sqlite3, {Database, Database as SQLiteDatabase} from "better-sqlite3";
import { IDatabase, QueryType } from "./IDatabase";
import Sqlite3, { Database, Database as SQLiteDatabase } from "better-sqlite3";
import fs from "fs";
import path from "path";
import {getHash} from "../utils/getHash";
import {Logger} from "../utils/logger";
import { getHash } from "../utils/getHash";
import { Logger } from "../utils/logger";
export class Sqlite implements IDatabase {
private db: SQLiteDatabase;
@@ -12,6 +12,7 @@ export class Sqlite implements IDatabase {
{
}
// eslint-disable-next-line require-await
async prepare(type: QueryType, query: string, params: any[] = []): Promise<any[]> {
// Logger.debug(`prepare (sqlite): type: ${type}, query: ${query}, params: ${params}`);
const preparedQuery = this.db.prepare(query);
@@ -30,13 +31,14 @@ export class Sqlite implements IDatabase {
}
}
// eslint-disable-next-line require-await
async init(): Promise<void> {
// Make dirs if required
if (!fs.existsSync(path.join(this.config.dbPath, "../"))) {
fs.mkdirSync(path.join(this.config.dbPath, "../"));
}
this.db = new Sqlite3(this.config.dbPath, {readonly: this.config.readOnly, fileMustExist: !this.config.createDbIfNotExists});
this.db = new Sqlite3(this.config.dbPath, { readonly: this.config.readOnly, fileMustExist: !this.config.createDbIfNotExists });
if (this.config.createDbIfNotExists && !this.config.readOnly && fs.existsSync(this.config.dbSchemaFileName)) {
this.db.exec(Sqlite.processUpgradeQuery(fs.readFileSync(this.config.dbSchemaFileName).toString()));

View File

@@ -1,8 +1,8 @@
import {config} from "../config";
import {Sqlite} from "./Sqlite";
import {Mysql} from "./Mysql";
import {Postgres} from "./Postgres";
import {IDatabase} from "./IDatabase";
import { config } from "../config";
import { Sqlite } from "./Sqlite";
import { Mysql } from "./Mysql";
import { Postgres } from "./Postgres";
import { IDatabase } from "./IDatabase";
let db: IDatabase;