Repository: louislam/uptime-kuma
File: server/database.js (JavaScript)

Code before:
        try {
            dbConfig = this.readDBConfig();
            Database.dbConfig = dbConfig;
        } catch (err) {
            log.warn("db", err.message);
            dbConfig = {
                type: "sqlite",
            };
        }

        let config = {};

        let parsedMaxPoolConnections = parseInt(process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS);
        let error = undefined;

        if (!process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS || Number.isNaN(parsedMaxPoolConnections)) {
            error = "invalid";
        } else if (parsedMaxPoolConnections < 1) {
            error = "less than 1";
        } else if (parsedMaxPoolConnections > 100) {
            error = "more than 100";
            log.warn("db", "We cap pool connections because Mysql/Mariadb connections are heavy. consider using a proxy like ProxySQL or MaxScale.");
        }

        if (error) {
            log.warn("db", `Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was ${error}.`);
        } else {
            log.info("db", `Max database connections: ${parsedMaxPoolConnections}`);
        }

        let mariadbPoolConfig = {
            min: 0,
            max: error ? 10 : parsedMaxPoolConnections,
            idleTimeoutMillis: 30000,
        };

        log.info("db", `Database Type: ${dbConfig.type}`);

        if (dbConfig.type === "sqlite") {

            if (! fs.existsSync(Database.sqlitePath)) {
                log.info("server", "Copying Database");
                fs.copyFileSync(Database.templatePath, Database.sqlitePath);
            }

            const Dialect = require("knex/lib/dialects/sqlite3/index.js");
            Dialect.prototype._driver = () => require("@louislam/sqlite3");

            config = {
                client: Dialect,
                connection: {

Review comment (refactor):
Your switching on error way of writing this is fairly hard to read.
Lets simplify

```suggestion
        let parsedMaxPoolConnections = parseInt(process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS);

        if (!process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS) {
            parsedMaxPoolConnections = 10;
        } else if (Number.isNaN(parsedMaxPoolConnections)) {
            log.warn("db", "Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was invalid.");
            parsedMaxPoolConnections = 10;
        } else if (parsedMaxPoolConnections < 1) {
            log.warn("db", "Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was less than 1.");
            parsedMaxPoolConnections = 10;
        } else if (parsedMaxPoolConnections > 100) {
            log.warn("db", "Max database connections capped to 100 because Mysql/Mariadb connections are heavy. consider using a proxy like ProxySQL or MaxScale.");
            parsedMaxPoolConnections = 100;
        }
```

Code after:
        try {
            dbConfig = this.readDBConfig();
            Database.dbConfig = dbConfig;
        } catch (err) {
            log.warn("db", err.message);
            dbConfig = {
                type: "sqlite",
            };
        }

        let config = {};

        let parsedMaxPoolConnections = parseInt(process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS);

        if (!process.env.UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS) {
            parsedMaxPoolConnections = 10;
        } else if (Number.isNaN(parsedMaxPoolConnections)) {
            log.warn("db", "Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was invalid.");
            parsedMaxPoolConnections = 10;
        } else if (parsedMaxPoolConnections < 1) {
            log.warn("db", "Max database connections defaulted to 10 because UPTIME_KUMA_DB_POOL_MAX_CONNECTIONS was less than 1.");
            parsedMaxPoolConnections = 10;
        } else if (parsedMaxPoolConnections > 100) {
            log.warn("db", "Max database connections capped to 100 because Mysql/Mariadb connections are heavy. consider using a proxy like ProxySQL or MaxScale.");
            parsedMaxPoolConnections = 100;
        }

        let mariadbPoolConfig = {
            min: 0,
            max: parsedMaxPoolConnections,
            idleTimeoutMillis: 30000,
        };

        log.info("db", `Database Type: ${dbConfig.type}`);

        if (dbConfig.type === "sqlite") {

            if (! fs.existsSync(Database.sqlitePath)) {
                log.info("server", "Copying Database");
                fs.copyFileSync(Database.templatePath, Database.sqlitePath);
            }

            const Dialect = require("knex/lib/dialects/sqlite3/index.js");
            Dialect.prototype._driver = () => require("@louislam/sqlite3");

            config = {
                client: Dialect,
                connection: {
                    filename: Database.sqlitePath,
                    acquireConnectionTimeout: acquireConnectionTimeout,
                },