Flights is a web application, backed by the power of MariaDB ColumnStore, allows you to analyze millions flight records from the United States Department of Transportation in real time without needing to add any indexes!
This application is made of two parts:
- Client
- web UI that communicates with REST endpoints available through an API app (see below).
- is a React.js project located in the client folder.
- API
- uses the MariaDB Python Connector to connect to MariaDB.
- is a Python project located int the api folder.
This README will walk you through the steps for getting the Flights
web application up and running using MariaDB.
- Requirements
- Getting started with MariaDB ColumnStore
- Get the code
- Configure, build and run the app
- Support and contribution
- License
This sample application requires the following to be installed/enabled on your machine:
- Python (v. 3+)
- MariaDB Connector/C (v. 3.1.5+) (used by Connector/Python)
- Node.js (v. 12+) (for the Client/UI app)
- NPM (v. 6+) (for the Client/UI app)
- MariaDB command-line client (optional), used to connect to MariaDB database instances.
MariaDB is a community-developed, commercially supported relational database management system, and the database you'll be using for this application.
This sample uses MariaDB ColumnStore. The quickest way to get started is by using the MariaDB ColumnStore Quickstart Guide, which will walk you through the process of getting a MariaDB database instance (via Docker container) up, running and loaded with the data necessary for this sample app.
TL;DR - Check out the MariaDB ColumnStore Quickstart before proceeding to the next step.
First, use git (through CLI or a client) to retrieve the code using git clone
:
$ git clone https://github.com/mariadb-developers/flights-app-nodejs.git
Next, because this repo uses a git submodule, you will need to pull the client application using:
$ git submodule update --init --recursive
Important: Before proceeding you'll need to have a MariaDB ColumnStore instance preloaded with flight data for this application to use. You can find more information here.
This application is made of two parts:
- Client
- web UI that communicates with REST endpoints available through an API app (see below).
- is a React.js project located in the client folder.
- API
- uses the MariaDB Node.js Connector to connect to MariaDB.
- is a Node.js project located in the api folder.
Configure the MariaDB connection by adding an .env file to the project within the api folder.
Example implementation:
DB_HOST=<host_address>
DB_PORT=<port_number>
DB_USER=<username>
DB_PASS=<password>
DB_NAME=travel
Configuring db.js
The environmental variables from .env
are used within src/api/tasks.py for the MariaDB Python Connector connection configuration settings:
config = {
'host': os.getenv("DB_HOST"),
'port': int(os.getenv("DB_PORT")),
'user': os.getenv("DB_USER"),
'password': os.getenv("DB_PASS"),
'database': os.getenv("DB_NAME")
}
Configuring .env and tasks.py for the MariaDB cloud database service SkySQL
Note: MariaDB SkySQL requires SSL additions to connection. Details coming soon!
A virtual environment is a directory tree which contains Python executable files and other files which indicate that it is a virtual environment. Basically, it's the backbone for running your Python Flask app.
Creation of virtual environments is done by executing the following command (within /src/api):
$ python3 -m venv venv
Tip: Tip: pyvenv is only available in Python 3.4 or later. For older versions please use the virtualenv tool.
Before you can start installing or using packages in your virtual environment, you’ll need to activate it. Activating a virtual environment will put the virtual environment-specific python and pip executables into your shell’s PATH.
Activate the virtual environment using the following command (within /src/api):
$ . venv/bin/activate activate
Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries.
TL;DR It's what this app uses for the API.
This app also uses the MariaDB Python Connector to connect to and communicate with MariaDB databases.
Install the necessary packages by executing the following command (within /src/api):
$ pip3 install flask mariadb python-dotenv
d.) Build and run the API app
Once you've pulled down the code and have verified that all of the required packages are installed you're ready to run the application!
From /src/api execute the following CLI command to start the the Python project:
$ python3 api.py
e.) Build and run the UI (Client) app
Once the API project is running you can now communicate with the exposed endpoints directly (via HTTP requests) or with the application UI, which is contained with the client
folder of this repo.
To start the client
application follow the instructions here.
Please feel free to submit PR's, issues or requests to this project project directly.
If you have any other questions, comments, or looking for more information on MariaDB please check out:
Or reach out to us diretly via: