multiple mysql databases for different clients
is jsreport can work with multi-tenant environments, such as multiple databases for different clients?, should I collect the data from the database firstly before I send it to the jsreport function?
hi! yes, you can handle this in the best way you like, for example, you can collect the data from the database before calling render, this way jsreport keeps agnostic if it is data from a tenant or not and basically, your app decides how to fetch such data and what params you need to fetch the correct information linked to a specific tenant.
the other option is that you use a db client you like in a jsreport-script beforeRender function, then you put there the logic you want to fetch the data about the tenant, of course, you will need to send some basic things to your report params like the tenant id/name for example so you can use it in the script to create your query. i think the best option is that you just handle in your app and just pass it to jsreport transparently
@daram12341 Did you found the solution ? I do have same requirement. Please help.
@bjrmatos Can you please elaborate the first option?
Can you please elaborate the first option?
this option basically means you keep jsreport as simple as possible, just create and design templates in a way that can work generally for all tenants and that templates expect that you just send the data and they will replace such values. you will just need to call jsreport with the data the specific template you want to render needs, how to prepare that data will depend on your app code (means that in your app you will handle the specific logic to query different tenants data/database).
@bjrmatos I want to pass database name in query string and reload or re-init the jsreport. Is that possible?
localhost:5488/reporting?db=mydb1 if I run with this URL, jsreport connect it to mydb1 database and fetch templates that stored in mydb1 and if I change it to localhost:5488/reporting?db=mydb2 and if i reload it will go and connect to mydb2.
@nisarg170 I see, but just for clarification, this is a different case for what this thread was open for.
there is no built-in support for multi-tenant support in jsreport, but it is possible by using custom extension code, we do this for example for the jsreportonline service which fetch different parts of our database depending on the tenant that has a session.
the code for this is public and you can check it here