Skip to content

shaimael-ws-java-demo/mariadb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Places

Places is a web application backed by the power of the power, performance, and simplicity of MariaDB platform, allows you to record all of your favorite locations!

This README will walk you through the steps for getting the Places web application up and running using MariaDB. To ensure success, please follow the instructions in order.

Note: The code provided within this repository is completely open source. Please feel free to use it as you see fit.

Table of Contents

  1. Requirements
  2. Introduction to MariaDB
    1. MariaDB Platform
    2. MariaDB SkySQL
    3. Using JSON in a relational database
  3. Getting started
    1. Get the code
    2. Create the schema
    3. Anatomy of the app
    4. Build and run the app
  4. JSON Data Models
  5. Support and Contribution
  6. License

Requirements

This sample application, no matter which API project you target, will requires the following to be installed/enabled on your machine:

Introduction to MariaDB

MariaDB Platform

MariaDB Platform integrates the former MariaDB TX (transactions) and MariaDB AX (analytics) products so developers can build modern applications by enriching transactions with real-time analytics and historical data, creating insightful experiences and compelling opportunities for customers – and for businesses, endless ways to monetize data. It’s the only enterprise open source database built for modern applications running in the cloud.

To get started using MariaDB locally you can:

MariaDB SkySQL

SkySQL is the first and only database-as-a-service (DBaaS) to bring the full power of MariaDB Platform to the cloud, including its support for transactional, analytical and hybrid workloads. Built on Kubernetes, and optimized for cloud infrastructure and services, SkySQL combines ease of use and self-service with enterprise reliability and world-class support – everything needed to safely run mission-critical databases in the cloud, and with enterprise governance.

Get started with SkySQL!

Using JSON in a relational database

JSON is fast becoming the standard format for data interchange and for unstructured data, and MariaDB Platform (in fact, all MariaDB versions 10.2 and later) include a range of JSON supporting functions.

The Places application uses only a single table for all location, and uses JSON to store more specific information based on the location type.

For more information on how JSON can be used within MariaDB please check out this blog post!

Getting started

In order to run the Places application you will need to have a MariaDB instance to connect to. For more information please check out "Get Started with MariaDB".

Get the code

Download this code directly or use git (through CLI or a client) to retrieve the code using git clone:

$ git clone https://github.com/mariadb-corporation/dev-example-places.git

Create the schema

Connect to the database using CLI or a client and execute the following:

CREATE TABLE `locations` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL DEFAULT '',
  `description` varchar(500) DEFAULT '',
  `type` char(1) NOT NULL DEFAULT '',
  `latitude` decimal(9,6) NOT NULL,
  `longitude` decimal(9,6) NOT NULL,
  `attr` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`attr`)),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Anatomy of the app

This application is made of two parts:

  • Client
    • communicates with the API.
    • is a React.js project located in the client folder.
  • API
    • uses a MariaDB Connector to connect to MariaDB.
    • contains multiple projects, located in the api folder.

See the README's in client and api for more information on how to get started!

Build and run the app

  1. Nagivate to the client folder and execute the following CLI command before proceeding:

    $ npm install
    
  2. Configure the MariaDB connection by an environmental (called .env) file within the client folder.

    $ touch .env
    

    Then add the key REACT_APP_GOOGLE_API_KEY and a Google Maps API Key.

    REACT_APP_GOOGLE_API_KEY=<google_api_key_here>
    

    Note: The REACT_APP_GOOGLE_API_KEY environmental variable is used here.

  3. Pick an API project and follow the instructions of the README to build and run the API project.

  4. Navigate to the client folder and execute the following CLI command to start the React.js application.

    $ npm start
  5. Open a browser window and navigate to http://localhost:3000.

JSON Data Models

Below are samples of the data model per Location Type.

Attraction

{
   "category":"Landmark",
   "lastVisitDate":"11/5/2019"
}

Location

{
   "details":{
      "foodType":"Pizza",
      "menu":"www.giodanos.com/menu"
   },
   "favorites":[
      {
         "description":"Classic Chicago",
         "price":24.99
      },
      {
         "description":"Salad",
         "price":9.99
      }
   ]
}

Sports Venue

{
   "details":{
      "yearOpened":1994,
      "capacity":23500
   },
   "events":[
      {
         "date":"10/18/2019",
         "description":"Bulls vs Celtics"
      },
      {
         "date":"10/21/2019",
         "description":"Bulls vs Lakers"
      },
      {
         "date":"11/5/2019",
         "description":"Bulls vs Bucks"
      },
      {
         "date":"11/5/2019",
         "description":"Blackhawks vs Blues"
      }
   ]
}

Support and Contribution

Thanks so much for taking a look at the Places app! As this is a very simple example, there's plenty of potential for customization. Please feel free to submit PR's to the project to include your modifications!

If you have any questions, comments, or would like to contribute to this or future projects like this please reach out to us directly at developers@mariadb.com or on Twitter.

License

License