Join the Webstudio community

Updated 4 months ago

best practice for connecting to an external database with multiple tables

At a glance
The post is seeking suggestions on the best practice for connecting an external database with multiple tables. The community members discuss the use of a token auth variable, whether it should be hardcoded or bound as a variable, and the benefits of using a separate variable for the token. They also discuss the ability to reuse the token variable across different pages and endpoints, and how this can be simplified with global data variables. While there is no explicitly marked answer, the community members provide guidance on the recommended approach and the potential future improvements to the global data variable feature.
I'm looking for suggestions on the best practice.

If I need to connect an external db and lots of tables, should I be adding each one like this? I've created my token auth as a property and bind that into my header value.
Attachment
CleanShot_2024-10-21_at_11.58.132x.png
N
B
J
18 comments
I had a similar question recently.

As I understand it, this will mask the token as the variable will be server-side and not exposed on the front-end.

However, it isn't a global variable, so, currently, you would have to add the data variable into each component you're using to make the call.
Auth token is masked whether you hardcode it in resource or bind as variable
Unless you bind this variable to some attribute or html embed
Bogdan, is what I'm doing the recommended way?
The recommended way to structure project until it feels good πŸ™‚
But seriously separate variable may just simplify access to token if you need to change it often
In marketplace it is especially important as some kind of documentation so user can change all these named parts with own.
Ok, thanks. This isn't for a marketplace but a personal project. Documentation would be really nice though.
With global data variables separate variable will make more sense when token is reused in different endpoints
and on different pages
For now variable can be reused only within page
I've seen that in the roadmap, it will be a very cool feature when it's ready.
Thanks for the info.
@TrySound, I just tried copy/paste a collection from one page into a new one. The collection accesses the data through an API endpoint. It appears that I'd need to recreate the connection on the new page for it to work. Will the global data variables allow me to do this action?
Yeah, global variable with resource will be copied as is
I mean collection will be copied as is
And will reuse global variable with resource
gotcha, that's how I assumed it would work. Thank you.
Add a reply
Sign up and join the conversation on Discord