Thanks to all for your help,
In base of your suggestions and after too much test and error, this is what I did.
Basic example in a table mysql (NOT JSON, easy to update fields from some Backend just like with any other Database Update Action):
id(int) | config_name(varchar) | config_value (varchar)
1 | smtp_env | dev
2 | smtp_host | smtp.gmail.com
3 | smtp_host_dev | maildev
4 | smtp_port | 465
4 | smtp_port_dev | 1025
5 | smtp_user | myuser_smtp
6 | smtp_pass | mypass_smtp
With this table the idea is to use the column “config_name” with value “smtp_env”, this can be “dev” or “real”, base on that I configure the Mailer Action in Globals.
So, If “smtp_env” is “dev” I need the values from “smtp_host_dev” and “smtp_port_dev”,
else if “smtp_env” is “real” I need the values from “smtp_host” and “smtp_port”.
Steps (Option 1):
- A simple query (smtp_db):
SELECT config_name, config_value FROM system_config
- A Set Value:
smtp_env = smtp_db[0].config_value
(The above should output “dev” or “real” base on the database values, and is [0] because is the first row in table.)
- Another Set Value (using ternary):
smtp_host_db = smtp_env=='dev' ? smtp_db.where('config_name','==','smtp_host_dev') : smtp_db.where('config_name','==','smtp_host)
- Repeat - output fields both cols (smtp_host_db)–>EXEC–>Set Value =
smtp_host = ''
- Set Value:
smtp_host = repeat[0].config_value
Results:
smtp_env = 'env'
smtp_host = 'maildev'
Steps (Option 2)
- A simple query (smtp_db):
SELECT config_name, config_value FROM system_config
- A Set Value:
smtp_env = smtp_db[0].config_value
(The above should output “dev” or “real” base on the database values, and is [0] because is the first row in table.)
- Set Value:
db_host_dev = smtp_db.where('config_name', '==', 'smtp_host_dev')
- Set Value:
db_host_real = smtp_db.where('config_name', '==', 'smtp_host')
- Set Value:
host_dev = db_host_dev[0].config_value
- Set Value:
host_real = db_host_real[0].config_value
- Set Value (ternary): db_host = smtp_env == ‘dev’ ? host_dev : host_real
Results:
smtp_env = 'env'
db_host= 'maildev'
Now, in both Options 1 or 2 if in the database the column of “config_value” of “smtp_env” change from “dev” to “real”, both results will be:
smtp_env = 'real'
db_host= 'smtp.gmail.com'
The Option 3 is with custom query using SELECT JSON_VALUE
. The only inconvennient for me with this option is the parcial update from some Backend, update values bases on keys, everything will be with custom code in querys, updates, etc. (Would be great if Wappler Team implement in house options for this scenarios)
All this needs to be in Global, otherwise in Mailer not be able to choose from Data Binding.
This same structure works for conditions using server side bindings, e.g., hide content base on admin conditions in any scenario.
QUESTION: Is All this sceneario OK? I really do not know which “Option” 1 or 2 or 3 is more efficcient and secure in production, keeping in mind that this is loading in Globals in a NodeJS project. Someone can guide me with that please? Any help is totally welcome