Managing data stores

Node.js provides a number of third-party libraries to retrieve data from the database. These libraries provide the same power and flexibility that other languages provide to access the database. With Node.js, you are able to work with most of the available SQL and NoSQL databases. This section describes how we can access data from relational databases directly from the Electron application. Here, we use MySQL database as the backend for our application.

For demonstration purposes, let's create a small database with a single table. Create a MySQL database called customer_manager to get started with our sample. You can use any database of your choice, but you need to use the corresponding Node.js bindings to access the data from the database. Create the database with the following command or use any MySQL GUI tools like MySQL workbench to create the database:

CREATE DATABASE customer_manager;

Add a table called customers in the newly-created database. Use the following sample query to create the table:

USE customer_manager;
CREATE TABLE customers (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
customer_name VARCHAR(50) NOT NULL,
customer_address VARCHAR(128),
customer_email VARCHAR(30),
customer_telephone VARCHAR(30),
customer_mobile VARCHAR(30),
customer_date_of_birth DATE,
remarks VARCHAR(300)
);

As you can see, this is a very basic table, which stores basic information about customers. We don't need to get into the details of database programming in this book, which is not in its scope. But let's cover some basic database operations with Angular 2 and Electron on top of the sample application that we created in the second chapter.

Open the Chapter06/Example01 from the code bundle. You can find an Angular application similar to the code that we had created in the previous chapters.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.251.169