Autodesk Forge - Extension button to get data from external SQL database - javascript

I am trying to connect my Forge app to a sql database, but I have no idea how to do that. I am new to forge and web development, so I don't know how to look for the best approach to solve this.
I found a code that does exactly what I want, that is getting the data from a specific table of my database, but I'm not able to put this code inside my forge app, mainly because it uses a require() function and I can't put it inside my extension button.
By the way, I'm trying to make a button in my extension where I click, it access my database and get data from it.
Would be really nice if someone could help me with this silly doubt that probably already has a solution in the internet and I'm not able to find it.
Sorry in advance if it's too obvious.

This problem is more related to web development than Forge.
Your app should be made of 2 parts : the frontend (html/css/js) and a backend (probably nodejs as you tagged it).
Your frontend should not access the database directly. This is the job of your backend.
In your backend, add a library to access your database such as Sequelize (if you are working with NodeJS). Then you will do a request from your frontend to your backend to get the data from the database.
You probably have something working like that for your Forge Access Token, depending on what you use to start your development.

Related

How to connect dynamic HTML to MySQL

First, I'd like to say this is part of a university undergrad project, so my knowledge will be limited.
I have a MySQL database set up with data and I want to click a button in HTML that queries the database and updates HTML table elements with returned data. I have done A LOT of reading and it always returns to nodejs which I have absolute beginner experience with. I have code set up to query my database with nodeJS which works fine, however, I see absolutely no solution to update the HTML dynamically and I refuse to believe it is not in some way possible. I have read about expressJS templating but this dynamic updating of data is expected to occur hourly from the database (the database is a dummy stand-in for a real-life one) and the expressJS templates are not a good fit at all.
How can I return nodeJS data to a HTML page without serving a new page each time? perhaps return server-side JS data to client-side JS? how does nodeJS allow the HTML to then load client-side JS files? I am unable to get a PHP install working so it's unfortunately not an option. I am open to any alternatives that allows HTML to MySQL connections.
Thanks
I'm not 100% sure what you have set up or what your level of knowledge is, but I hope I can help.
Sounds like you have your server running and querying your DB just fine, so that's good. Now you need to route that to your frontend. This is where expressJS usually comes in. It's a backend framework for creating API's in node. Think of it as a middleman. You send a request to your API, and your API makes a request to the DB and gives you what you want.
To make the request from the frontend, you can use the fetch() API. It's an asynchronous function used to make https requests and receive data. You then need to use that data to dynamically populate your html. Since it's done with javascript, it won't force a reload of the page either.
Feel free to ask questions and hopefully we can get you pointed in the right direction at the very least.

How do I hide database connection information for a vanilla HTML/CSS/JS GitHub Pages project?

I'm working on a school project using vanilla HTML, CSS, and JS. When compete, we're expected to have the repo working via GitHub Pages. It's above and beyond the scope of the assignment, but I wanted to connect to a Firebase Firestore database.
The question is, how do I hide the API key/information, using only vanilla HTML, CSS, and JS (no frameworks), and have a working GitHub Pages demo for the instructor to mark?
I've looked at a number of websites and YouTube videos, but every tutorial I've come across is either using a framework or some stack of packages that would go against the 'rules' of the assignment. I can use a .env file, but to my understanding, because the repo is public the key would be public.
Any advice would be greatly appreciated.
The answer is .env files (sort of).
If you're building a frontend project and you're connecting the front end directly to your database, your credentials will be visible.
The correct way to handle keys is to put them in your backend API. Of course, when I asked this question, I wasn't "there yet".
Your backend API can have a public endpoint that listens to incoming requests. You don't need to include your database credentials in the request coming from your frontend app. It hits your backend api at its public endoint where your backend code then handles the incoming request. On your backend you have the connection to your database with the necessary credentials. This is how you are supposed to build it.
For beginners, you might want to try Google Firebase. With Firebase you can create Firebase Functions. With these, you can create a simplified API endpoint to target with your front-end requests. It triggers the Firebase Function to run, and inside this function, you can store your private keys/credentials. Because your Firebase Functions run on your own secure backend, the client never sees the keys.
If you're learning or familiar with Vue3, here's a good article to check out: https://www.bezkoder.com/vue-3-firebase/#more-9260

How do I make an Electron login system using mysql or should i do something else?

I'm making my first Electron app and I'm not sure whether or not I should use the MySQL npm package or whether I should just use a MySQL in standard JavaScript that loads when the application starts for a login page if you could give me any advice on which to use and how to do it, it would help a lot
Edit:
The kind of thing I'm making is an application where there is admins and standard users both using the same login interface and to login they will connect to an online mysql database where it will check if there login details are correct and if they are then it will either give them the standard or admin view in the application and I'm not sure whether or not I should use mysql in javascript or whether or not I should use the npm mysql package and if I should use that instead of using standard javascript?
Also i would like the application to be able to run offline where the user can login online and make edits to things in the app such as their username or password etc (things that would be stored in the database) and have it so when connection is re-established it allows the information in the database to be updated.
I'm simply looking for some advice on how i could do that or some pointers in the right direction like some documentation or some up to date tutorials which might be able to help me and I am new to node/electron and therefore please be patient :P
tl;dr; Checkout nedb
To interact with mysql database server, you will need it installed and running.
Ask yourself
Does user has mysql installed and server running?
How do you handle the users who do not have mysql server installed? Are you going to ask them to download it?
Do I really want to use this mysql or can my functionalities work with some other lightweight database?
For most cases, requirements are simpler and you will not need database such as mysql, I recommend to use lightweight databases such as nedb
For some really simple applications, I don't even use nedb, rather I simply write and read from a file but you seem to be past that simple situation.
I ended up using a remote mysql server and used the mysql node package to do this which is very easy to use
npm install mysql --save
https://github.com/mysqljs/mysql

How can I connect a SQLite local database to a HTML frontend?

I've recently ported a simple database from Ms Access to SQLite, because I wanted an open source option. Now I'm facing the problem of developing a visual form for data entry in that database.
This related question (HTML/JS as interface to local SQLite database) pretty much summaries what I want to do: create an HTML/JavaScript frontend for data entry in a SQLite local database. In that thread, the user solved the issue by creating a local web server via Python script.
The question is: how do I connect my HTML file to that local web server? Is that via PHP or something similar? Please point me to the right research direction. Thank you!
Yes, you should use PHP or something similar, possibly Ruby on Rails or Django. The last two make life really easy and help abstract the database.

how to connect Website to MYSQL database?

Am currently working on a website(html 5) that calculate the expenses for the user, after the calculation, user has to save it as report for future purposes. So i wanna know if there is anyway to connect the website to MYSQL database or any alternative way rather than create database using java script because am a novice on Js.
thankyou
ideally you should be writing some server side code to add this sort of information to a database. that way you can secure access to authorised users (i.e. logged in users) and your queries cannot be modified on the browser by any user. you can use a programming language like PHP (with a framework like Yii, CodeIgniter) which is quite lightweight.
Browsers have no built in mechanisms for connecting to a MySQL server.
Your options are:
Write a browser plugin
Write a web service and use JavaScript to create an XMLHttpRequest object to communicate with it
The second option is the most common one (and almost certainly the best since it doesn't require that the user install a browser plugin or that you give direct access to the database to all your users).
If you want to use JavaScript, then you can create your web service with (for example) Node.js and the mysql driver in npm.
You should use HTML5 Web SQL for this purpose. Here is link you can refer to:
http://www.tutorialspoint.com/html5/html5_web_sql.htm

Categories