Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. const mysql = require('mysql');
  2. const createTables = require('./config');
  3. const Promise = require('bluebird');
  4. const database = 'shortly';
  5.  
  6. const connection = mysql.createConnection({
  7. user: 'root',
  8. password: ''
  9. });
  10.  
  11. const db = Promise.promisifyAll(connection, { multiArgs: true });
  12.  
  13. db.connectAsync()
  14. .then(() => console.log(`Connected to ${database} database as ID ${db.threadId}`))
  15. .then(() => db.queryAsync(`CREATE DATABASE IF NOT EXISTS ${database}`))
  16. .then(() => db.queryAsync(`USE ${database}`))
  17. .then(() => createTables(db));
  18.  
  19. module.exports = db;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement