0

hi i have a table that store all configuration setting, at the same time, i also have one hardcoded config file. but, i have problem when user, which is non developer want to access some config value, and the config value is not presence in database but present in hardcoded file, how can i achieve this objective?

how can i make sure that my configuration table overrides value that were already present in hardcoded file? so that user can access all values in the config file as well as those in database?

I'm using nodeJS, es6, objections JS

Naju Mat Isa
  • 55
  • 1
  • 7

2 Answers2

0

It's a bit hard to tell exactly what you're asking. If you have an ordered set of locations where configuration values can be stored and you want them to be accessed in a particular way such as:

read the value from the database
if value not stored in the database, 
    then check for value in the config file

Then, you would likely need to do one of these things:

  1. Expose an API for reading the value and your own logic checks for the value in the right order and force you clients to use the API, not read database or config file directly.

  2. Force the clients to all check for things in the proper order.

  3. Keep the config file up to date with the latest value so an outside developer can always just read the config file to get the latest value. This means that any time a relevant value in the database is updated, you have to update the database.

  4. Read the config file values on startup into the database so you only have one storage place for the "live" values (the database). Then force all clients to only read config values from the database.

  5. Get rid of the config file entirely and just store things in the database. If you need to change the config, modify the values in the database.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • yes, it is something like you are saying: "read the value from the database if value not stored in the database, then check for value in the config file”. I am trying to get rid of user modifying value in database directly or is it possible if i create a class to read both value in config file and the value stored in database synchronously?.. what do you think about this? Or, Create a global variables to store the hardcoded value and import the file to any file that are using the value at the same time ensure that system to read database file and the global variables values. – Naju Mat Isa Oct 18 '19 at 06:57
  • @NajuMatIsa - It sounds to me like you need a function for reading config values that contains the appropriate logic and everyone who needs to get a config value calls that function - nobody reads the data directly from db or config file. Any state can be stored in module scoped variables so it will be shared by all callers of the function. Sounds to me like a perfect stand-alone module. – jfriend00 Oct 18 '19 at 15:41
  • @NajuMatIsa - If this answered your question, then you can indicate that to the community here by clicking the checkmark to the left of the answer. That will also earn you some reputations points here on stackoverflow which can eventually earn you more privileges. – jfriend00 Oct 21 '19 at 00:55
0

i created a different file and include function to store the hardcoded value as in config file, example, change.js. inside my controller, i import the function to something like, newConfig.getConfig(); so the values can be dynamically obtained from changes.js. if the value cannot be found, then only i query from database.

Naju Mat Isa
  • 55
  • 1
  • 7