Defining the table

To define a table you need to create an object with the required fields and extend the Table class and Exposed will create the table in the database for you with the fields as columns:

    object Messages: Table() {
      val id = integer("id").autoIncrement().primaryKey()
      val name = varchar("name", 100)
    }

It will result in the following query called by Exposed:

    CREATE TABLE IF NOT EXISTS Messages (id INT AUTO_INCREMENT NOT      NULL, name VARCHAR(100) NOT NULL, CONSTRAINT pk_Messages PRIMARY      KEY (id))
Currently Exposed doesn't have support for data classes and the repository pattern. It requires the creation of an object of the required structure. 

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.