import Knex from 'knex';

import dotenv from 'dotenv';
dotenv.config()

const dbs = {
    get public() {
        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#smart_self-overwriting_lazy_getters
        delete this.public;
        return this.public = Knex({
            client: 'mysql2',
            useNullAsDefault: true,
            connection: {
                host : process.env.MYSQL_HOST || '127.0.0.1',
                user : process.env.MYSQL_USER || '',
                password : process.env.MYSQL_PASSWORD || '',
                database : process.env.MYSQL_DB || 'testldapi'
            },
        });
    },

    get private() {
        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#smart_self-overwriting_lazy_getters
        delete this.private;
        return this.private = Knex({
            client: 'mysql2',
            useNullAsDefault: true,
            connection: {
                host : process.env.MYSQL_HOST || '127.0.0.1',
                user : process.env.MYSQL_USER || '',
                password : process.env.MYSQL_PASSWORD || '',
                database : process.env.MYSQL_DB || 'testldapi' // `${process.env.MYSQL_DB || 'testldapi'}pvt`
            },
        });
    }
}

export { dbs };

import Knex from 'knex';

import dotenv from 'dotenv';
dotenv.config()

const dbs = {
    get public() {
        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#smart_self-overwriting_lazy_getters
        delete this.public;
        return this.public = Knex({
            client: 'mysql2',
            useNullAsDefault: true,
            connection: {
                host : process.env.MYSQL_HOST || '127.0.0.1',
                user : process.env.MYSQL_USER || '',
                password : process.env.MYSQL_PASSWORD || '',
                database : process.env.MYSQL_DATABASE || 'testldapi'
            },
        });
    },

    get private() {
        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#smart_self-overwriting_lazy_getters
        delete this.private;
        return this.private = Knex({
            client: 'mysql2',
            useNullAsDefault: true,
            connection: {
                host : process.env.MYSQL_HOST || '127.0.0.1',
                user : process.env.MYSQL_USER || '',
                password : process.env.MYSQL_PASSWORD || '',
                database : process.env.MYSQL_DATABASE || 'testldapi' // `${process.env.MYSQL_DATABASE || 'testldapi'}pvt`
            },
        });
    }
}

export { dbs };

Use env name MYSQL_DATABASE instead of MYSQL_DB
Use env name MYSQL_DATABASE instead of MYSQL_DB

MYSQL_DATABASE matches the environment variable name expected by the
Docker MySQL image (https://hub.docker.com/_/mysql/) which will make it
easier to set up deployments, as I can just set up a secret with
MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD and so on, and allow that
secret to populate environment variables for both the mysql container
and the ldapi container.
