node.js - How to connect, create database, reconnect with that database and create tables in knex.js? -


i working knex.js. have kind of weird set going on. can't sure mysql database i'm connecting has database set up.

so, first connect without specifying database. then, create database , reconnect specified database. after that, want create 3 different tables. keep getting error: er_bad_db_error: unknown database '<dbname>'. have code,

    knex.raw('create database if not exists ' + database + ';'     ).then(function() {         knex.destroy();         knexconnect.connection.database = database;         knex = require('knex')(knexconnect);     }).then(function() {         knex.schema.createtable('items', initializeitems         ).catch(function (err) {             console.log(err);           });          knex.schema.createtable('lessons', initializelessons         ).catch(function (err) {             console.log(err);           });          knex.schema.createtable('reviews', initializereview         ).catch(function (err) {             console.log(err);         });     }); 

what need change in order table creation commands executed after reconnection has been established , database created?

i figured out can done using promises; then constructs.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -