Skip to content

TriCoreDB for Kotlin

0.1.0

The official Kotlin client: SQL, documents, cache, vectors and graphs over one native connection.

Install

Gradle (Kotlin DSL)
implementation("com.tricoredb:tricoredb-kotlin:0.1.0")
Maven
<dependency>
  <groupId>com.tricoredb</groupId>
  <artifactId>tricoredb-kotlin</artifactId>
  <version>0.1.0</version>
</dependency>

Requirements

  • Java 17 or later
  • Kotlin 2.0 or later
  • A TriCoreDB server, 0.1.0-rc.1 or later (install one)

Highlights

  • Every call is a suspend function
  • One dependency: kotlinx-coroutines-core
  • Transactions, connection pool, TLS and mutual TLS

Quick start

Main.kt
import com.tricoredb.kt.TriCore
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {
    TriCore.connect("127.0.0.1", 8427, "admin", "your-password").use { db ->
        db.execute("CREATE TABLE IF NOT EXISTS users (id INT PRIMARY KEY, name TEXT)")
        db.execute("INSERT INTO users VALUES (?, ?)", 1, "O'Hara")

        val rows = db.query("SELECT name FROM users WHERE id = ?", 1)
        println(rows[0][0])            // O'Hara

        db.cache.setText("sessions", "u1", "token")
        println(db.cache.getText("sessions", "u1"))
    }
}

TLS

This example connects without TLS, which matches the development container. The default image requires TLS. The README shows how to connect with a CA certificate, and documents every call.