From ac909d4730e2657b14df1b0a66c63db6af38855d Mon Sep 17 00:00:00 2001 From: Mikko Ala-Fossi Date: Tue, 25 Jul 2023 11:33:44 +0300 Subject: [PATCH] Add description on how to setup DB table to use snake_case names --- DAO.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/DAO.md b/DAO.md index 50a30c4..71d50d0 100644 --- a/DAO.md +++ b/DAO.md @@ -29,6 +29,20 @@ object StarWarsFilms : Table() { override val primaryKey = PrimaryKey(id, name = "PK_StarWarsFilms_Id") // PK_StarWarsFilms_Id is optional here } ``` +By default, the lower case of the DB table representation will be used as the table name unless another name is explicitly +specified. In this case, Exposed will assume the `StarWarsFilms` stores records in the `starwarsfilms` table. + +If your DB table representation name does not fit this convention, you may manually specify the +table name by calling the `Table` constructor with the correct name as argument: +```kotlin +object StarWarsFilms : Table("star_wars_films") { + val id: Column = integer("id").autoIncrement() + val sequelId: Column = integer("sequel_id").uniqueIndex() + val name: Column = varchar("name", 50) + val director: Column = varchar("director", 50) + override val primaryKey = PrimaryKey(id, name = "PK_StarWarsFilms_Id") // PK_StarWarsFilms_Id is optional here +} +``` Tables that contain an `Int` id with the name `id` can be declared like this: ```kotlin object StarWarsFilms : IntIdTable() {