Thanks! Ktorm is pretty close to what I’m looking for! I would like the operations to be more list-like (filter, map etc), but it would work pretty fine I think
A pretty awesome Java library for something like this is jOOQ. I haven’t tried it, but it looks very promising. Surely it’s Java, but Java interop is there in Kotlin so we can use it, right?
The biggest advantage most likely would be a type & structure safety. Normally you represent your queries as plain strings, but by having a proper model any changes to it would also affect all your queries.
The problem is with the lambda expressions like { it.age < 30 }. In Kotlin, there is no reasonable way for the filter function to process that and turn it into an SQL expression.
C# has LINQ, which solves exactly that problem. It needs to be built into the language, and in Kotlin it’s not.
Without that sort of thing, these kinds of libraries will always be pretty awkward.
I’m afraid you are right here. Just for fun I started to write some library like this myself, but it’s not really possible to make things turn into SQL. You come in with a Comparator (I tried in Java), but how to get it to SQL? I don’t think it’s possible… There should be something like LINQ in Java or Kotlin! I will come with a feature request.