XTDB in Kotlin - Save and retrieve object example

Hi,
Is there an example of how to save a kotlin (or java) object to XTDB, modify it, then retrieve it in kotlin? I kind of have it running but I don’t think what I am doing is optimal and was wondering if I can get my hands on an example

1 Like

Hey @niko,

I’m afraid I don’t personally know the Kotlin ecosystem well enough to be able to give a good answer here. If you’re using XT in-process, my first guess would be to use a library that can serialize to/deserialize from java.util.Maps - maybe something in kotlinx.serialization would work, or maybe there’s a way of getting Jackson to do it?

If you’re using XT as a remote service, though, it might be preferable to use the HTTP API directly, at which point it’ll take and return JSON objects.

If you can share, mind me asking how you’re currently doing it? Can run it via the more Kotlin-oriented folks at JUXT if that’d help.

Cheers,

James

Hi @jarohen,

Although I’m not a Kotlin expert, I needed to implement one of my services that interacts with XTDB in Kotlin. Here’s how I currently have it set up:

  1. I begin by starting a node in my Kotlin Spring Boot application as a bean during the application’s startup.
  2. Configuration is loaded from a JSON file, and I use this node in my data access objects via the XTDB Java package.

Writing to the database is straightforward; I create an XTDBDocument object and then place it into the database. However, the process for querying is a bit less clean. Currently, I’m constructing Clojure queries as strings and passing them to the node.

If you have any suggestions for improving this setup, I’d greatly appreciate hearing them.

Regards,
Niko

Hey @niko did you spot https://github.com/xtdb/xtdb/tree/master/labs/kotlin-dsl already? It might be helpful for constructing your queries, or helping you devise your own abstraction.

Thanks Jeremy, this is helpful.

1 Like