How to use relational DB with online/offline replica with Electron-Node? - mysql

I am just starting to use Electron and I have a question about databases. Due to the kind of App I am developing I need a relational DB.
The idea is the user will open the App, if there is connection it would store the data both locally and remotely. If the App is offline it will store the data locally and whenever is online again it will send that data to the remote server. Basically it will be thee same database (local and remote) but it can work offline if necessary.
I am lost on which database will be better for this. As I said I am using MySQL right now and I know you can use MySQL with nodejs so I might give it a try. Also, I am used to use MySQL within a backend language such as PHP, how would you do it in Electron?
Thanks for your time guys!

Related

How to connect to my mysql database installed in my host (domain)

I want to develop a desktop application (with VB) and connect it to an online database (MySQL), I already had my hosting site and I thought why not create a MySQL database in my domain (which by the way is offered in the pack) and connect my desktop application to this database.
Why an online database? Because I want to develop a mobile application to keep me informed of any changes in my business without moving to my office.
The problem is that my VB6 application cannot connect to my MySQL due to domain restrictions. I wondered how these thousands of apps work with online data? What are their magic solutions? Or did I miss something?
Please any idea? I worked with VB6 and a local database which is no longer productive.
You can create a simple PHP file on your server that will take the data from your VB6 apps and store it in your database. You can also create a simple PHP file that will query your database and return the results in a format that your app can read. This is the typical way that a VB6 app will interact with a server-side database.

Accessing Mysql Database from a Machine to another machine using an application

So, I basically made a Windows Application using Visual Studio 2019, and used MySQL as my database to store records.
Now I want to publish that application and send it to a client or try to run it on a different machine, but i think since i have used the localhost as my database connection it wont be able to read or write data on my database from another machine.
So basically I want to know how can i host my mysql database on a machine and access that database from another machine using an application.
I am unable to find any sort of guide to do it online, if someone can guide me or give me a referrence from where I can get information and solve my issue.
You can expose your localhost to be accessed remotely, However, this is not ideal or advised. I will suggest you host your database on one of the virtual or cloud services and access it in your application.
Examples of services like https://remotemysql.com/ https://www.db4free.net/ which I advice you use for testing purpose only. You can create your database and they will give you the connection parameters to fill your connection string.
Let me know if is helpful.

How do I connect a desktop app to an hosted database

I am developing a desktop app and I want to store data in hosted database like MySQL/MongoDB. I know one solution is using webservice to manipulate db. I am wondering is there a way to connect desktop app with hosted db directly.
I am using OpenShift I know I can use port-forward to do this. But it's unpractical to open port forward every time for every PC. So is a way simply like this:
mongoose.connect('mongodb://user:pass#host:port/db');
I tried this but I got 'connect refused' or 'connect not found' errors. OpenShift doesn't allow external access to database directly because security issues, right? Then how could I do it without port-forward?
Also I read some articles about SSH, is it possible to use SSH to access db directly when desktop app is launched?
Thanks for any suggestion.
I don't think OpenShift is going to be a good fit for what you are trying to do, unless you decide to build a service layer between your desktop app and the database. It sounds like you are looking for a Database As A Service. You mentioned both MongoDB and MySQL. MongoLab is a good MongoDB DBaaS option. For other databases like MySQL, PostgreSQL and several others you could look at Amazon RDS.

How to connect to a client server database in PhoneGap?

I have been searching this topic for a long time but I haven't found the answer I wanted. I want to connect to a MySQL database on a client-server and insert some info on a table using an app I made using PhoneGap. I found things like that but didn't seem to do what I want them to do: http://docs.phonegap.com/en/2.7.0/cordova_storage_storage.md.html#SQLTransaction
This documentation page doesn't make any sense to me.
Does anyone know how can I solve my problem? Thanks in advance.
You normally don't access database on your server dirrectly from the app in your phone.
The doc you saw about SQLTransaction is about writing data to the SQLite database that is inside your device, not to write to a remote database.
What is usually done to communicate with a remote database is we perform http requests to a web server (php, java, .net, ruby, perl or whatever you like) and that server will communicate with the database server.
If you really want to communicate with your mysql server from your phonegap app, you would have to include native mysql libraries in your project and write native code to communicate with the mysql server. And I don't think it woule work very well through a data connection...

How to integrate database into software

I am practicing writing an app which use MySQL to manipulating data.
My concern is if my client machine doesn't have have MySQL pre-installed, it's not be able to run my app, is it?. So is there anyway to embed the database server right into the app, or to run the app without the data server. I wonder how all the softwares out there manipulates data. It's not like we need to install some kind of database server before install the app.
MySQL is a client/server database engine, which means that you must install the client and server separately from each, and they communicate over some kind of network protocol.
If you want to deploy a stand-alone application, you are probably better off using a library like SQLite, which gives you as much of the functionality of a SQL database as you are likely to need in such an app, but instead operates on local files and doesn't require installation of a separate server.
You can embed MySQL in your application, see MySQL as an Embedded Database for details.
Your application could work with the remote database, when configuring database connection you should set your DB server IP address(host), port and login credentials. so in order to write application which is dealing with data manipulation, you need to connect to any database instant.
If you are working on client-server application, MySQL database may be accessed either by means of MySQL (this solution may be suitable for internal networks), or through some database-side service, which can provide some API and which can be accessed from client via some application-level protocol (for example, XML-RPC).
If you are working on client application, there are other database solution, which can be used in stand-alone software: SQLite, Derby. As an alternative to database approach, you may consider storing data in XML / YAML format.
I suggest to wrap db layer in you application witch simple interface provided for all operations performed on the database. In this way, you will not have to go into the details of the atomic operations on the database and through unified interface, you can create several different classes which will be responsible for access to different databases in the same way (the same interface). These classes should realize the interface and implement all necessary methods inside (for example ADO). Now your db layer can be visible in all program it the same way. Wrapped class can realize singleton desing pattern and can be used as one instance enywhere in your application. Universal class design (interface) gives you many benefits such as the possibility of substitution on another layer if necessary (switch to a totally different db).