Hi!
I'm the author of KtMongo, a Kotlin driver for MongoDB. One of the features of KtMongo is the ability to use Kotlin's DSLs to recreate typesafe requests within Kotlin itself.
For example, a user could declare the structure of a document using a Kotlin class;
@Serializable
class User(
val name: String,
val grades: List<Grade>,
val bestPassingGrades: List<Int>
)
@Serializable
class Grade(
val value: Int,
val subject: String,
)
and then use typesafe operators to represent queries:
users.aggregate()
.project {
include(User::name)
User::bestPassingGrades set User::grades
.map { it / Grade::value }
.filter { it gt 50 }
.sortedByDescending()
.take(3)
}
I'm considering adopting Elasticsearch alongside MongoDB, because the search capabilities of Elasticsearch are obviously superior. Are there any existing projects that follow a similar typesafety-based approach to querying?
Are you aware of libraries allowing the creation of typesafe queries? I'm curious how different programming languages approach this problem, both for traditional queries and for ES|QL.