Creating Database Connections with the Database Manager
A lot of new power comes with the new Database Manager in Wappler.
You can quickly connect your project to all kind of databases you want to use in it.
There is a wide range of databases that you can fully manage from within Wappler. You can start with simple local SQLite database and grow to more strong high availability database servers like MySQL, MariaDB, PostgreSQL and Microsoft SQL Server.
You can choose to run those servers on your local machine during development and also have them running on your hosting server for your live site.
You can also use separate database servers as offered by Amazon RDS or Digital Ocean Managed Databases for your enterprise grade database access with maximum performance, security and scalability. See: https://www.digitalocean.com/community/tutorials/understanding-managed-databases
Database Connections in Wappler
With the new Database Manager in Wappler setting up a database connection is really easy.
You can use multiple, unique database connections for your Wappler project, depending on your needs. Those will be the database you use.
Since you can work in multiple environments like local development or live production, the database connection settings are dependent per project target. So you for each target you have defined you will have separate options for the database connection.
Defining a Database Connection
To use a database in your Wappler project, you will have to define it first.
Note: If your project is using Docker - the connection called “db” is already available for you.
If you have already used Server Connect in that project, you will see all the database connection that you have created in Server Connect already listed.
Creating a new Database Connection is easy. Just select the “Database Connections” branch on top and then choose “Add Connection” from the context menu.
Then give it a name and proceed. The database will be available under that name for the rest of your project.
Tip: The database connection name will be available on all your project targets. You are working with the database and its settings as defined for the currently selected target. To specify different settings you will have to switch the active target first.
When you select the new database connection you will see its options:
Default the connection will use local development server, so in case you are on Docker or use local WAMP/MAMP/XAMP server you don’t have to do anything else.
If you use a Server Modal, like PHP, ASP or
ASP.NET, you will be also using Server Connect and it’s Database Connector to allow you web server to connect to your database
Your server model is selected in the Project Options
Just make sure you define a Server Connect Connection so that your database can be accessed the same way as your local web server will access it. Again with Docker this will be defined automatically, but if you have your own local development server you have to enter it manually.
Note this is only for local development targets where you have and the web server and the database server running on the same local development machine.
Using Remote Database Servers
If you have a live database server and you want to be able to push changes to it or view its database structure, you will have to define a “Direct Connection” to it for Wappler.
So make sure you have selected your live target first, then select the database connection name and enable the “Use Direct Connection” option to allow Wappler to access your database directly.
Then a new button will appear “Direct Database Connect” that allows you to define that connection:
Click on it to see the Direct Database Connection options:
On this dialog you can choose the database type you are connecting to and enter all the needed credentials. The options vary per chosen database type.
Connecting to Digital Ocean Managed Database
Digital Ocean provides great service by offering you fully managed database. They will fully setup and backup the database for you so it is a very convenient and secure service. You can also easily choose the database type and scale your database server depending on your needs and growth.
You can setup such a managed database in a minute. Check for Introduction to Digital Ocean Managed Databases
In Wappler you can connect super easy to such remote dataabase. You can just import the database connection string from providers Digital Ocean and all the settings will be entered automatically:
Then you can just paste the connection string that you get with Digital Ocean:
Just choose the type of Connection String (1) and then show your passwork (2) and copy it to the clipboard (3)
Then you can paste it in the Wappler Import Connection String dialog and import it.
And there you go it is entered for you nicely:
Even SSL is automatically selected with the right Profile, so you don’t have to apply additional SSL options to connect to it.
You can test your connection to see if it is all working well:
When everything is fine and you see the Database Connection OK message you can save your connection. From now on Wappler will be able to access this database when needed and when the target is active.
Connecting to Amazon RDS
Amazon offer also a great service that offers you fully managed dedicated database servers available to you.
You can even run your database servers completely isolated in a VPC (Virtual Private Cloud) for maximum security. Then only your web server will have access to them and also Wappler with the right credentials. So this is really a high security setup.
To get started with such setup you can follow the Amazon tutorial Create a Web Server and an Amazon RDS Database
To connect to such isolated Amazon RDS instance, you will need the database instance name, SSL and special SSH tunneling options:
Test your connection and when everything is fine and you see the Database Connection OK message you can save your connection. From now on Wappler will be able to access this database when needed and when the target is active.
In this article you saw how easy it is to setup any kind of database connection in Wappler with the new Database Manager.
Wappler offers rich connectivity to wide range of database solutions, so it is up to your needs to choose the one that suits you best.
Wappler will connect then seamlessly and allows you to build the powerful solutions you want.