Todo App with MariaDB Connector/R2DBC
This page is part of MariaDB's MariaDB Documentation.
The parent of this page is: Sample Code
Topics on this page:
Todo is a sample web application for managing a todo list. The application is compatible with MariaDB Connector/R2DBC and MariaDB SkySQL Single Node Transactions and Replicated Transactions services.
Todo demonstrates the ease-of-use of MariaDB Connectors and Single Node Transactions or Replicated Transactions on MariaDB SkySQL by managing a list of arbitrary tasks, adding new tasks, and tracking their status.
Todo has three components:
React.js front-end web application
Java-based back-end application service
Single Node Transactions database back-end running on MariaDB SkySQL
Clone the Repository
The Todo example application is available from the MariaDB Corporation repository on GitHub. It contains the API code in Java and other languages, and the React.js front-end web application that connects to the API.
To download the Todo application, clone the repository from GitHub:
$ git clone https://github.com/mariadb-corporation/dev-example-todo.git
This creates a
dev-example-todo directory on your file system.
Provision Database Service
Todo requires a back-end database service using the InnoDB storage engine. The application is compatible with Single Node Transactions and Replicated Transactions topologies of MariaDB SkySQL. For the purposes of demonstration, this guide uses the Single Node Transactions topology on MariaDB SkySQL.
For additional information, see "Launch".
Create the Database Schema
Todo uses an InnoDB table to store the todo entries.
Use the MariaDB Client to connect to the database service and initialize the schema:
Connect to your database service.
Use CREATE DATABASE to create a database for the application:
CREATE DATABASE todo;
Use CREATE TABLE to create a table to store the todo entries:
CREATE TABLE todo.tasks ( id INT PRIMARY KEY AUTO_INCREMENT, description VARCHAR(500) NOT NULL, completed BOOLEAN NOT NULL DEFAULT 0 ) ENGINE = InnoDB;
This creates a
todo.tasks table for use by the Todo application with MariaDB SkySQL as a database back-end.
Install the Back-end Application Service
The Todo front-end web application connects to the database service using a back-end application service. The repository contains different versions of the back-end app, enabling you to test and experiment with different languages and different MariaDB Connectors. These instructions are for Java using MariaDB Connector/R2DBC.
Navigate to the
api directory for MariaDB Connector/R2DBC in the cloned repository:
$ cd dev-example-todo/api/r2dbc
Configure the Back-end Application Service
To connect to your MariaDB SkySQL database service, the application must be configured to use the appropriate credentials.
Create properties file at
src/main/resources/db.propertiesand populate it with the login credentials for your MariaDB SkySQL service:
host = example.skysql.net username = db_user password = db_password database = todo port = 5001 clientSslCert = classpath:static/skysql_chain.pem
Create a directory for static files:
$ mkdir src/main/resources/static
Copy your SkySQL CA file into the
$ cp /path/to/skysql_chain.pem src/main/resources/static
Build the Back-end Application Service
To build the Java back-end application service:
$ mvn package
Start the Back-end Application Service
Once you have the back-end application service configured and installed, you can start the service:
$ mvn spring-boot:run
In the Todo sample application, the client is a React.js application that connects to the back-end application service and provides a web interface.
To install and start the web application:
Navigate to the
clientdirectory in the cloned repository:
$ cd dev-example-todo/client
Install the web application:
$ npm install
Start the web application:
$ npm start
The React.js web application is now running. You can access it through your web browser at http://localhost:3000.
When the front-end web application and the back-end application service are running, Todo simulates an online todo list application, maintaining a record of open and completed tasks on a Single Node Transactions database service on MariaDB SkySQL.
The web application provides basic task management functionality, allowing you to add, finish, and delete tasks.
The client connects to the database service through the back-end application service, retrieves a list of todo entries from the table, crossing through any that have been completed. To add a task, click the "Add New Task" button. To mark a task as complete, click the checkbox. To delete a task, click the trash can icon.