Search code examples
mysqlkotlinkotlin-exposed

What would be the eqivalent of show tables from MySQL in Kotlin Exposed


Trying out Kotlin Exposed for the first time. I have been able to learn Kotlin to a reasonable extent now and now I'm trying to learn Kotlin Exposed API for database access. But I'm unable to find an equivalent for SHOW tables; of MySQL.

It would be nice to be able to list out tables without previously hard coding them into the program.

Is there an equivalent to that query in Exposed? if so how? Thanks in advance


Solution

  • There is VendorDialect.allTableNames() function in Exposed which uses jdbc DatabaseMetadata to fetch tables.

    Database.connect(/* your connection string */)
    
    transaction { 
        val tableNames = TransactionManager.current().db.dialect.allTablesNames()
    }