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.
| Task | Runnable example |
|---|---|
| CRUD | examples/ClientSimpleCrud.kt |
| QueryBuilder | examples/ClientQueryBuilder.kt |
| Joins | examples/ClientJoins.kt |
| Schemas | examples/ClientSchemaManagement.kt |
| TTL | examples/ClientDocumentTtl.kt |
| Transactions | examples/ClientTransactions.kt |
| Stored Functions | examples/ClientFunctions.kt |
| Concurrency / Locks / RateLimits | examples/ClientConcurrencyStages.kt |
| Chat / RAG | examples/ClientChatBasic.kt, examples/RagConversationSystem.kt |
| Search | examples/ClientSearch.kt |
| WebSockets | examples/ClientWebsocketSubscribe.kt |
| Admin / Permissions | examples/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
| Task | Suspend call shape |
|---|---|
| Insert | client.insert(collection, record) |
| Find | client.find(collection, query) |
| Point read | client.findById(collection, id) |
| Merge update | client.update(collection, id, fields) |
| Delete | client.delete(collection, id) |
| Batch insert | client.batchInsert(collection, records) |
| Read / change schema | client.getSchema(collection) / client.updateSchemaConstraints(collection, constraints) |
| Save / call a function | client.saveUserFunction(definition) / client.callFunction(idOrLabel, params) |
| Transactions | client.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). UseFieldType.obj(...)andFieldType.array(...)for native nested structures, not stringified JSON. - Returned fields are
FieldTypevalues. The CRUD example uses(inserted["id"] as? FieldType.StringValue)?.valuefor the ID and theio.ekodb.clientutility helpers for other fields. Preserve the returned ID and handle a missing field explicitly. - Put
ttlinto the record directive when inserting/updating;insertWithTtl(collection, record, "5m")is also available. Omitting update TTL preserves expiry. - A
callFunctionresult containsrecords.Countreplaces the working set: read the named field on the first result record.Querystages cannot usejoin. - 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.