I want to initialize a MySQL connection with credentials that i'm getting from a master database, is possible to do this on AdonisV4?
using adonis lucid
I can't set the credentials in config, because they're specific for every request that is made.
You would invoke npm library related to mysql in terminal shell.
AdonisJs uses the connection value defined inside the config/database.js file. Thus, you may to create a configuration file for a single database connection in your JavaScript application like following:
You can create an initial environment file for your master database like :
For several connections, you would setup your config file like this:
So, you can select any of the connections defined by the database configuration file at runtime with:
However, if yo have a lot of databases, this approach impacts the RAM server. So, if you have a master database like your case, choose connection dynamically following an ORM for Node.JS using a SQL query builder like Objection.js with knex - based support for MySQL.
A multitenancy approach could be adopted from here.