Step 5: Live Demo with a Sample Application

This page details step 5 of a 5-step guided walkthrough to help you get started with SkySQL.

In this step, you will perform a live demonstration, importing sample data and connecting to a sample application.

About our Sample Apps

MariaDB provides a set of sample applications you can use to explore and experiment with various MariaDB Connectors and MariaDB SkySQL services.

Each sample app demonstrates a front-end web application UI written in React.js, a MariaDB Connector that connects the application to the database, and a MariaDB SkySQL service back-end.

Our guided walkthrough uses the Todo sample app with MariaDB Connector/Node.js.

For information on other sample app and Connector options, see "Sample Apps".

Prerequisites

  • Download and install Node and NPM (Node Package Manager) from https://nodejs.org/en/download/ . You need node version v12.16.1.

    You can check for version with:

    $ node -v
    
  • Install git if you don't have it.

Create Sample Database

  1. Connect to your database service.

  2. Use CREATE DATABASE to create a database for the application:

    CREATE DATABASE todo;
    
  3. 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;
    

Install Todo

  1. Clone the Todo repository:

    $ git clone https://github.com/mariadb-corporation/dev-example-todo.git
    
  2. Change to the API directory in the cloned repository:

    $ cd dev-example-todo/api/nodejs/basic
    
  3. Create an .env environment file to configure the API to connect to your SkySQL instance:

    DB_HOST = example.skysql.net
    DB_USER = db_user
    DB_PASS = db_user_passwd
    DB_PORT = 5001
    DB_NAME = todo
    
  4. Edit the db.js file and modify the value of the serverCert constant, so that it points to the location of the skysql_chain.pem file on your file system:

    // 2.) Retrieve the Certificate Authority chain file (wherever you placed it - notice it's just in the Node project root here)
    const serverCert = [fs.readFileSync("/path/to/skysql_chain.pem", "utf8")];
    
  5. In the mariadb.createPool() configuration, confirm that the ssl property sets the ca property to the serverCert constant, so that MariaDB Connector/Node.js uses TLS with SkySQL's CA certificate:

    // Create a connection pool
    var pool =
      mariadb.createPool({
        host: process.env.DB_HOST,
        user: process.env.DB_USER,
        password: process.env.DB_PASS,
        port: process.env.DB_PORT,
        database: process.env.DB_NAME,
        connectionLimit: 5,
        // 3.) Add an "ssl" property to the connection pool configuration, using the serverCert const defined above
        ssl: {
          ca: serverCert
        }
      });
    
  6. Install and start the API:

    $ npm install
    $ npm start
    
  7. In a separate terminal, start the client:

    $ cd dev-example-todo/client
    $ npm install
    $ npm start
    

The client is now running, and you can access it through your web browser at http://localhost:3000/ .

Result

Todo Application

Next Step