A light ORM that offers the idiomatic way to write Kotlin type-safe SQL for JVM and Android
- Kotysa supports various drivers : JDBC, R2DBC, Vertx sqlclient
- Kotysa supports various database engines : PostgreSQL, MySQL, Microsoft SQL Server, MariaDB, Oracle, H2
- Kotysa supports SqLite on Android
See the project website for documentation and APIs.
Kotysa is easy to use : 3 steps only
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 alias: String? = null,
val id: Int? = null
)
Use our 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, "f_name")
val roleId = uuid(User::roleId)
.foreignKey(Roles.id, "FK_users_roles")
val alias = varchar(User::alias)
}
// List all your mapped tables
private val tables = tables().h2(Roles, Users)
Use our type-safe SqlClient DSL, Kotysa executes SQL query for you !
val admins = (sqlClient selectFrom Users
innerJoin Roles on Users.roleId eq Roles.id
where Roles.label eq "admin"
).fetchAll() // returns all admin users
No annotations, no code generation, no proxy, no additional plugin, just regular Kotlin code ! No JPA, just pure SQL !
Contributions are welcome.
- Compile Kotysa with a JDK 17.
- You need a local docker, like docker-ce : some tests use testcontainers to start real databases like PostgreSQL, MySQL...
- Clone this repo
git clone [email protected]:ufoss-org/kotysa.git
- Build project
./gradlew clean build