Kotysa
Kotysa is a light ORM that offers the idiomatic way to write Kotlin type-safe SQL for JVM and Android.
Kotysa Query API is agnostic from the SQL Engine : change your database engine or your web framework (Ktor, Spring, Quarkus...), but keep your SQL layer stable.
Supported Databases
On JVM
- MySQL (supported data types)
- PostgreSQL (supported data types)
- H2 (supported data types)
- Microsoft SQL Server (supported data types)
- MariaDB (supported data types)
- Oracle (supported data types)
If you use Spring, check Kotysa for Spring JDBC for WebMVC sync SQL or Kotysa for Spring R2DBC for WebFlux, which supports both Reactive and Coroutines async SQL
If you use Quarkus Reactive with async Vertx sqlclient, check Kotysa for Vertx sqlclient
If you use Ktor, or anything else, check Kotysa for JDBC for a regular blocking SQL application or Kotysa for R2DBC for Coroutines async SQL.
On Android
Check Kotysa for SqLite on Android (supported data types)
Table of content
Easy to use : 3 steps only
Description
No annotations, no code generation, no proxy, just regular Kotlin code ! No JPA, just pure SQL !
step 1 -> Create Kotlin entities
data classes are great for that !
data class Role(
val label: String,
val id: UUID = UUID.randomUUID()
)
data class User(
val firstname: String,
val roleId: UUID,
val country: String,
val alias: String? = null,
val id: Int? = null
)
step 2 -> Describe database model
Use type-safe Tables DSL to map your entities with the database tables, this is the ORM (object-relational mapping) step
object Roles : H2Table<Role>("roles") {
val id = uuid(Role::id)
.primaryKey()
val label = varchar(Role::label)
.unique()
}
object Users : H2Table<User>("users") {
val id = autoIncrementInteger(User::id)
.primaryKey("PK_users")
val firstname = varchar(User::firstname, "fname")
val roleId = uuid(User::roleId)
.foreignKey(Roles.id, "FK_users_roles")
val country = varchar(User::country)
val alias = varchar(User::alias)
}
// List all your mapped tables
private val tables = tables().h2(Roles, Users)
step 3 -> Write SQL queries
Use type-safe SqlClient DSL, Kotysa executes SQL query for you !
You don't have to be aware of all subtle SQL differences between databases, Kotysa will generate the right SQL syntax for your database.
val admins = (sqlClient selectFrom Users
innerJoin Roles on Users.roleId eq Roles.id
where Roles.label eq "admin"
).fetchAll() // returns all admin users
Samples
- See our sample projects for jdbc, r2dbc, spring-jdbc, spring-r2dbc and vertx.
- A more complete real world sample project provide you a Spring Boot reactive web application with a R2DBC backend accessed via Kotysa, with HTTP2, JWT based Security, Bean validation, RestDoc...
Source code
👨💻 Open source code of Kotysa is available on github, feel free to watch it, submit issues, contribute, fork, copy, whatever you want.
Status
Regular releases will provide new features to Kotysa, see the next milestones.