Table and Column
Name a table and its columns
Use @Table on the KPojo class when the database table name should be explicit. Use @Column on a property when the database column name should differ from the Kotlin property name. These annotations take priority over the naming strategies described in 📚Naming Strategy.
model
import com.kotlinorm.annotations.Column
import com.kotlinorm.annotations.ColumnType
import com.kotlinorm.annotations.CreateTime
import com.kotlinorm.annotations.Default
import com.kotlinorm.annotations.NonNull
import com.kotlinorm.annotations.PrimaryKey
import com.kotlinorm.annotations.Table
import com.kotlinorm.annotations.UpdateTime
import com.kotlinorm.enums.KColumnType
import com.kotlinorm.interfaces.KPojo
import java.time.LocalDateTime
@Table("tb_account")
data class Account(
@PrimaryKey(identity = true)
var id: Int? = null,
@Column("user_name")
@ColumnType(KColumnType.VARCHAR, length = 80)
@NonNull
var username: String? = null,
@Default("0")
var loginCount: Int? = null,
@CreateTime
var createdAt: LocalDateTime? = null,
@UpdateTime
var updatedAt: LocalDateTime? = null
) : KPojoThe table metadata shape is:
| Kotlin property | Database column | DDL behavior |
|---|---|---|
id | id | Primary key identity column. |
username | user_name | VARCHAR(80) NOT NULL. |
loginCount | loginCount | Default value 0. |
createdAt | createdAt | Creation time field populated by the creation time strategy. |
updatedAt | updatedAt | Update time field populated by the update time strategy. |
Nullability and defaults
Properties are nullable in table DDL unless the field is a primary key or uses @NonNull. Put the raw database default expression in @Default.
MySQL
CREATE TABLE IF NOT EXISTS `tb_account` (
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`user_name` VARCHAR(80) NOT NULL,
`loginCount` INT DEFAULT 0,
`createdAt` DATETIME,
`updatedAt` DATETIME
)For a string literal default, include the quotes in the annotation value:
default
@Default("'active'")
var status: String? = nulldefault sql
`status` VARCHAR(255) DEFAULT 'active'Creation and update timestamps
Use @CreateTime and @UpdateTime on the timestamp properties that should receive the current time during insert, update, or upsert operations.
timestamps
@Table("tb_account")
data class AccountTime(
@PrimaryKey(identity = true)
var id: Int? = null,
@CreateTime
var createdAt: LocalDateTime? = null,
@UpdateTime
var updatedAt: LocalDateTime? = null
) : KPojoInsert parameter shape:
insert params
createdAt -> 2026-07-06T10:15:30
updatedAt -> 2026-07-06T10:15:30Update parameter shape:
update params
updatedAt -> 2026-07-06T10:20:00See 📚Annotations for the full annotation parameter list, 📚Column Types for Kotlin type inference, and 📚Indexes for table index mapping.