Dependency Setup

In order to setup ActiveJDBC with Kotlin, add the ActiveJDBC dependency as well as the Kotlin module:

<dependency>
    <groupId>org.javalite</groupId>
    <artifactId>activejdbc-kt</artifactId>
    <version>LATEST_VERSION</version>
</dependency>

Instrumentation

Setting up instrumentation is not any different, please follow instructions here.

Usage

Unlike the Java layer, the Kotlin layer offers two similar ways of setting up a model.

Approach #1

First define an entity

import org.javalite.activejdbc.Model;
import org.javalite.activejdbc.CompanionModel;

open class Person():Model() {
    companion object:CompanionModel<Person>(Person::class)
}

Then use it as in Java

val person:Person = Person.findById(1)

Approach #2 (with English inflections)

The first class is only for the entity itself

import org.javalite.activejdbc.Model;

open class Person():Model()

The second class stands for the table and its name matches English inflection (Person => People)

import org.javalite.activejdbc.CompanionModel;

open class People {
    companion object:CompanionModel<Person>(Person::class)
}

Usage:

val person:Person = People.findById(1L)

How to comment

The comment section below is to discuss documentation on this page.

If you have an issue, or discover bug, please follow instructions on the Support page