ActiveJDBC & Kotlin
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;
class Person():Model() {
open :CompanionModel<Person>(Person::class)
companion object}
Then use it as in Java
:Person = Person.findById(1) val person
Approach #2 (with English inflections)
The first class is only for the entity itself
import org.javalite.activejdbc.Model;
class Person():Model() open
The second class stands for the table and its name matches English inflection (Person => People)
import org.javalite.activejdbc.CompanionModel;
class People {
open :CompanionModel<Person>(Person::class)
companion object}
Usage:
:Person = People.findById(1L) val person
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