yashodgayashan/environment_platform

[IMPROVEMENT] - Can we have the mongo db configurations in a central place?

Closed this issue · 10 comments

Improvement

When we are moving forward we will be using multiple db handler files so we will be duplicating the mongodb config each and every place. So can we get this to a central location which will be easier for us? If this is possible then let's mark this as an improvement rather than a question.

I did't get it. You are asking about for different modules ?

What I'm saying is that we will be using the mongodb config in many files in the future so isn't it good to have it at a central location?

What I'm saying is that we will be using the mongodb config in many files in the future so isn't it good to have it at a central location?

Isn't this done already with ballerina.conf?

If you are talking about the config in db_handler.bal, we could put that into a different file and then import it directly in the files where it is needed. If possible I suggest relying only on the ballerina .conf for the db config properties.

Yeah we can use ballerina conf file to change the database collection names and databases.

What I'm saying is that we will be using the mongodb config in many files in the future so isn't it good to have it at a central location?

Isn't this done already with ballerina.conf?

If you are talking about the config in db_handler.bal, we could put that into a different file and then import it directly in the files where it is needed. If possible I suggest relying only on the ballerina .conf for the db config properties.

That's only the Constants of the DB I'm referring to these:

Screenshot from 2020-05-22 13-04-53

If we don't have this in a central location then we'll have to duplicate the above in each file.

are you asking for make this in a different file and inherit this for every module.

Yeah I'm asking whether we can have those in a different file and then reuse when required. I don't think you can inherit in Ballerina.

What I'm saying is that we will be using the mongodb config in many files in the future so isn't it good to have it at a central location?

Isn't this done already with ballerina.conf?
If you are talking about the config in db_handler.bal, we could put that into a different file and then import it directly in the files where it is needed. If possible I suggest relying only on the ballerina .conf for the db config properties.

That's only the Constants of the DB I'm referring to these:

Screenshot from 2020-05-22 13-04-53

If we don't have this in a central location then we'll have to duplicate the above in each file.

Hmmm...that should be possible. If the file with those configs are in the same folder we are accessing it from, then we should be able to inherit those properties.

This works when running functions from different files in Ballerina. I have not tried this with variables though. The steps to import a function is shown below:

Steps:

  1. Make a new module along with the file that has the required function. For example, config module with mongoConfig() function in properties.bal file.
  2. Import the module into the file which needs the function. For example, import config;
  3. Access the function. For example, config:mongoConfig();

@yashodgayashan could you see whether this would work for importing variables?

What I'm saying is that we will be using the mongodb config in many files in the future so isn't it good to have it at a central location?

Isn't this done already with ballerina.conf?
If you are talking about the config in db_handler.bal, we could put that into a different file and then import it directly in the files where it is needed. If possible I suggest relying only on the ballerina .conf for the db config properties.

That's only the Constants of the DB I'm referring to these:
Screenshot from 2020-05-22 13-04-53
If we don't have this in a central location then we'll have to duplicate the above in each file.

Hmmm...that should be possible. If the file with those configs are in the same folder we are accessing it from, then we should be able to inherit those properties.

This works when running functions from different files in Ballerina. I have not tried this with variables though. The steps to import a function is shown below:

Steps:

  1. Make a new module along with the file that has the required function. For example, config module with mongoConfig() function in properties.bal file.
  2. Import the module into the file which needs the function. For example, import config;
  3. Access the function. For example, config:mongoConfig();

@yashodgayashan could you see whether this would work for importing variables?

@sanjulamadurapperuma @deshankoswatte I will check it and try to move it to a different file.

What I'm saying is that we will be using the mongodb config in many files in the future so isn't it good to have it at a central location?

Isn't this done already with ballerina.conf?
If you are talking about the config in db_handler.bal, we could put that into a different file and then import it directly in the files where it is needed. If possible I suggest relying only on the ballerina .conf for the db config properties.

That's only the Constants of the DB I'm referring to these:
Screenshot from 2020-05-22 13-04-53
If we don't have this in a central location then we'll have to duplicate the above in each file.

Hmmm...that should be possible. If the file with those configs are in the same folder we are accessing it from, then we should be able to inherit those properties.

This works when running functions from different files in Ballerina. I have not tried this with variables though. The steps to import a function is shown below:

Steps:

1. Make a new module along with the file that has the required function.  For example, `config` module with `mongoConfig()` function in `properties.bal` file.

2. Import the module into the file which needs the function. For example, `import config; `

3. Access the function. For example, `config:mongoConfig();`

@yashodgayashan could you see whether this would work for importing variables?

@sanjulamadurapperuma could not find a resource to make it work using the variables so I have used methods for it.