Answers for "get list of tables in knex"

0

get list of tables in knex

export function listTables(knex:Knex) {
    let query:string;
    let bindings: string[];

    switch(knex.client.constructor.name) {
        case 'Client_MSSQL':
            query = 'SELECT table_name FROM information_schema.tables WHERE table_schema = \'public\' AND table_catalog = ?',
            bindings = [ knex.client.database() ];
            break;
        case 'Client_MySQL':
        case 'Client_MySQL2':
            query = 'SELECT table_name FROM information_schema.tables WHERE table_schema = ?';
            bindings = [ knex.client.database() ];
            break;
        case 'Client_Oracle':
        case 'Client_Oracledb':
            query = 'SELECT table_name FROM user_tables';
            break;
        case 'Client_PG':
            query =  'SELECT table_name FROM information_schema.tables WHERE table_schema = current_schema() AND table_catalog = ?';
            bindings = [ knex.client.database() ];
            break;
        case 'Client_SQLite3':
            query = "SELECT name AS table_name FROM sqlite_master WHERE type='table'";
            break;
    }

    return knex.raw(query, bindings).then(function(results) {
        return results.rows.map((row) => row.table_name);
    });
}
Posted by: Guest on March-17-2021
0

get list of tables in knex

MFR Frost Dragon
Posted by: Guest on April-25-2021

Code answers related to "ActionScript"

Browse Popular Code Answers by Language