node.jssequelize.js

Make Sequelize show tables


I'm creating a project in node.js and one of my pages will show a list of all the tables in the database. I would like to know if Sequelize has a function like "Show tables".

Thanks!


Solution

  • I don't think there's an API in Sequelize, but you can always fall back to raw SQL. "Show tables" is a MySQLism, so you could just do:

    var seq = new Sequelize('mysql://localhost/mysql');
    seq.query('show tables').then(function(rows) {
        console.log(JSON.stringify(rows));
    });
    

    Replace the console.log with your own parsing and display logic.