December 2018
Intermediate to advanced
642 pages
15h 5m
English
First, let's have some constants that we will be using later; apart from the Flow and strict usage lines, we just require the MariaDB library, the promisify() function, and we define four constants to access the database:
// Source file: src/dbaccess.js/* @flow */"use strict";const mariaSQL = require("mariasql");const { promisify } = require("util");const DB_HOST = "127.0.0.1";const DB_USER = "fkereki";const DB_PASS = "modernJS!!";const DB_SCHEMA = "world";// continues...
Now, let's get a database connection. We just create a new object, and promisify its .query() method. The dbConn variable will be passed as a parameter to every function that will need to access the database:
// ...continuedfunction getDbConnection(host, ...
Read now
Unlock full access