be-hase/kuery-client
be-hase/kuery-client has 31 GitHub stars and 3 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-12 20:58 UTC. Last push 2026-11-06.
A Kotlin/JVM database client for those who want to write SQL
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 기록 수집 중
- in 15 days
- 기록 수집 중
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalWrite SQL as it is.
A Kotlin SQL client built on Spring Data — interpolated runtime values become bind parameters via a compiler plugin.
It looks like plain string interpolation...
val user: User? = kueryClient
.sql { +"SELECT * FROM users WHERE user_id = $userId" }
.singleOrNull()
...but it executes as a parameterized query. A Kotlin compiler plugin rewrites the interpolated runtime value into named parameter binding at compile time — so you get the readability of raw SQL without the risk of SQL injection:
SELECT * FROM users WHERE user_id = :p0 -- :p0 = userId, bound as a named parameter
Why Kuery Client?
- ♥️ Love SQL
- ORM libraries are convenient, but they each require learning their own DSL, which we believe is a steep cost. Kuery Client emphasizes writing SQL as it is.
- 🛡️ Safe by design
- Interpolated runtime values are converted into bind parameters by the compiler plugin, so the normal SQL-building path never concatenates them into the SQL text.
- ✅ Compile-time checks
- The compiler plugin warns when a SQL string cannot be converted safely, and can optionally validate SQL syntax — mistakes surface at compile time, not in production.
- 🍃 Built on Spring Data
- Kuery Client is implemented on top of
spring-data-r2dbcandspring-data-jdbc. Use whichever you prefer. You can keep using Spring's ecosystem as is, such as@Transactional.
- Kuery Client is implemented on top of
- 🔭 Observability
- It supports Micrometer Observation, so you can collect and customize metrics, tracing, and logging.
- 🧩 Extensible
- When dealing with complex data schemas, you often want to share common query logic. Kotlin's extension functions make this easy.
A Taste of the DSL
Dynamic SQL is just Kotlin — if / when / loops, no template syntax to learn.
Whether using R2DBC or JDBC, the way of writing is almost the same.
data class User(...)
class UserRepository(private val kueryClient: KueryClient) {
suspend fun findById(userId: Int): User? = kueryClient
.sql { +"SELECT * FROM users WHERE user_id = $userId" }
.singleOrNull()
suspend fun search(status: String, vip: Boolean?): List<User> = kueryClient
.sql {
+"""
SELECT * FROM users
WHERE
status = $status
"""
if (vip != null) {
+"AND vip = $vip"
}
}
.list()
suspend fun insertMany(users: List<User>): Long = kueryClient
.sql {
+"INSERT INTO users (username, email)"
// useful helper function
values(users) { listOf(it.username, it.email) }
}
.rowsUpdated()
}
There are only two things you need to remember:
- Concatenate SQL strings using
+(unaryPlus). Express logic such asifdirectly in Kotlin. - Bind parameters using string interpolation.
Motivation
We have used numerous ORM libraries, but in the end, we preferred libraries like MyBatis that allow writing SQL directly.
To construct SQL dynamically, custom template syntax (such as if/foreach) is often used, but we prefer to write logic using the syntax provided by the programming language as much as possible. We want to write dynamic SQL using Kotlin syntax, similar to kotlinx.html.
To meet these needs, we implemented Kuery Client.
Kuery Client simply provides the SQL builder shown above on top of the well-established
spring-data-r2dbc / spring-data-jdbc. It is designed to be usable alongside plain
spring-data code, so you can start small.
Getting Started
Kuery Client requires Java 17 or later and Gradle 8.4 or later.
Install
Replace <version> with the latest version, which you can find in the Maven Central badge above or on
the Getting Started page.
plugins {
id("dev.hsbrysk.kuery-client") version "<version>"
}
dependencies {
implementation("dev.hsbrysk.kuery-client:kuery-client-spring-data-r2dbc:<version>")
// or, implementation("dev.hsbrysk.kuery-client:kuery-client-spring-data-jdbc:<version>")
}
Build KueryClient
For kuery-client-spring-data-r2dbc:
val connectionFactory: ConnectionFactory = ...
val kueryClient = SpringR2dbcKueryClient.builder()
.connectionFactory(connectionFactory)
.build()
For kuery-client-spring-data-jdbc:
val dataSource: DataSource = ...
val kueryClient = SpringJdbcKueryClient.builder()
.dataSource(dataSource)
.build()
Let's Use It
val userId = "..."
val user: User? = kueryClient
.sql { +"SELECT * FROM users WHERE user_id = $userId" }
.singleOrNull()
Documentation
More details are on the document site:
- Getting Started — choose R2DBC or JDBC and run the first query
- Building SQL — interpolation, collections, dynamic SQL, and reusable fragments
- Fetching Results — terminal operations, streaming, generated values, and statement options
- Compile-Time Checks — the compiler diagnostics that catch unsafe SQL, and the strict option
- SQL Syntax Check — opt-in compile-time validation of your SQL syntax
- Transaction / Type Conversion / Row Mapping
- Observation — Micrometer-based metrics, tracing, and logging
- Configuration — Gradle plugin and runtime builder options
- Supported Platforms / Compatibility — tested databases and supported Kotlin / Spring versions
For AI assistants and LLM-based tools, the entire documentation is also available in the llms.txt format: llms.txt (index) and llms-full.txt (full content in a single file).
Examples
Runnable example projects live in examples/:
License
관련 프로젝트 살펴보기
Asabeneh/30-Days-Of-Python
30 Days of Python 프로그래밍 챌린지는 Python 프로그래밍 언어를 30일 동안 배우기 위한 단계별 가이드입니다. 이 챌린지는 100일 이상 걸릴 수 있습니다. 자신의 속도에 맞춰 진행하세요. 다음 동영상도 도움이 될 수 있습니다: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,618 스타grafana/grafana
개방적이고 조합 가능한 옵저버빌리티 및 데이터 시각화 플랫폼입니다. Prometheus, Loki, Elasticsearch, InfluxDB, Postgres 등 여러 소스의 메트릭, 로그, 트레이스를 시각화합니다.
77,859 스타redis/redis
실시간 데이터 기반 애플리케이션을 구축하는 개발자에게 Redis는 가장 선호되고, 가장 빠르며, 기능이 가장 풍부한 캐시, 데이터 구조 서버이자 문서 및 벡터 쿼리 엔진입니다.
77,472 스타apache/superset
Apache Superset는 데이터 시각화 및 데이터 탐색 플랫폼입니다.
75,495 스타