Skip to main content

Kotlin SDK quick reference for agents

Baseline: Maven coordinate io.ekodb:ekodb-client-kt:0.37.0. Add it to the application's Gradle dependencies with implementation("io.ekodb:ekodb-client-kt:0.37.0"). Checked against the client, Record type and CRUD example.

Runnable Examples (Check Before Guessing)​

Before writing SDK code, consult the matching runnable example below for exact imports, method signatures and error handling. These links follow the SDK's main branch; compare them with the version installed in your application. Follow the language directory's run instructions and use a disposable deployment when executing examples that write data.

TaskRunnable example
CRUDexamples/ClientSimpleCrud.kt
QueryBuilderexamples/ClientQueryBuilder.kt
Joinsexamples/ClientJoins.kt
Schemasexamples/ClientSchemaManagement.kt
TTLexamples/ClientDocumentTtl.kt
Transactionsexamples/ClientTransactions.kt
Stored Functionsexamples/ClientFunctions.kt
Concurrency / Locks / RateLimitsexamples/ClientConcurrencyStages.kt
Chat / RAGexamples/ClientChatBasic.kt, examples/RagConversationSystem.kt
Searchexamples/ClientSearch.kt
WebSocketsexamples/ClientWebsocketSubscribe.kt
Admin / Permissionsexamples/ClientAdmin.kt

Initialize and query​

The application supplies runtime credentials and calls this function from its coroutine lifecycle:

import io.ekodb.client.EkoDBClient
import io.ekodb.client.QueryBuilder
import io.ekodb.client.types.Record

suspend fun listActive(baseUrl: String, apiKey: String): List<Record> {
val client = EkoDBClient.builder().baseUrl(baseUrl).apiKey(apiKey).build()
val query = QueryBuilder.new().eq("active", true).limit(25).build()
return client.find("agent_tasks", query)
}

The builder is synchronous; database methods are suspend. The client manages JWT exchange and refresh. Do not block an application thread with an extra runBlocking around each call.

Method map​

TaskSuspend call shape
Insertclient.insert(collection, record)
Findclient.find(collection, query)
Point readclient.findById(collection, id)
Merge updateclient.update(collection, id, fields)
Deleteclient.delete(collection, id)
Batch insertclient.batchInsert(collection, records)
Read / change schemaclient.getSchema(collection) / client.updateSchemaConstraints(collection, constraints)
Save / call a functionclient.saveUserFunction(definition) / client.callFunction(idOrLabel, params)
Transactionsclient.beginTransaction(), client.commitTransaction(id), client.rollbackTransaction(id)

Kotlin uses named optional arguments such as transactionId where supported by the method, rather than a TypeScript-style options object. The raw function-save overload accepts a JsonObject; call parameters are Map<String, JsonElement>.

Values, TTL and failures​

  • Construct records with Record.new().insert("name", "Ada").insert("active", true). Use FieldType.obj(...) and FieldType.array(...) for native nested structures, not stringified JSON.
  • Returned fields are FieldType values. The CRUD example uses (inserted["id"] as? FieldType.StringValue)?.value for the ID and the io.ekodb.client utility helpers for other fields. Preserve the returned ID and handle a missing field explicitly.
  • Put ttl into the record directive when inserting/updating; insertWithTtl(collection, record, "5m") is also available. Omitting update TTL preserves expiry.
  • A callFunction result contains records. Count replaces the working set: read the named field on the first result record. Query stages cannot use join.
  • Preserve exceptions and their HTTP status. Existing-transaction operations, including commit, are not automatically retried after failure. Classify a retryable conflict before re-running an entire transaction; a legacy 409 Apply(...) is not a reason to retry unchanged data.

See canonical formats, versioned Kotlin examples and REST.