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_PRIVATE || process.env.MYSQL_DATABASE_PVT || (process.env.MYSQL_DATABASE ? `${process.env.MYSQL_DATABASE}pvt` : 'testldapi')
            },
        });
    }
}

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_PRIVATE || process.env.MYSQL_PASSWORD_PVT || process.env.MYSQL_PASSWORD || '',
                database : process.env.MYSQL_DATABASE_PRIVATE || process.env.MYSQL_DATABASE_PVT || (process.env.MYSQL_DATABASE ? `${process.env.MYSQL_DATABASE}pvt` : 'testldapi')
            },
        });
    }
}

export { dbs };

Allow different DB password for private instance
Allow different DB password for private instance

Now the private instance password can be set with the
MYSQL_PASSWORD_PRIVATE or MYSQL_PASSWORD_PVT environment variables. If
neither of those are set, it defaults to the same password as the public
database (MYSQL_PASSWORD environment variable).
