Skip to content
The idiomatic way to write type-safe SQL in Kotlin
Kotlin Java
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
gradle/wrapper
kotysa-android
kotysa-core
kotysa-spring-data-r2dbc
samples
.gitignore
LICENSE
README.md
RELEASE.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

GitHub License Download

Kotysa

The idiomatic way to write Kotlin type-safe SQL.

Easy to use : 3 steps only

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 alias: String? = null,
        val id: UUID = UUID.randomUUID()
)

step 2 -> Describe database model with type-safe DSL, based on these entities

val tables =
        tables().postgresql { // choose database type
            table<Role> {
                name = "roles"
                column { it[Role::id].uuid().primaryKey }
                column { it[Role::label].varchar() }
            }
            table<User> {
                name = "users"
                column { it[User::id].uuid().primaryKey }
                column { it[User::firstname].varchar().name("fname") }
                column { it[User::roleId].uuid().foreignKey<Role>() }
                column { it[User::alias].varchar() }
            }
        }

step 3 -> Write SQL queries with type-safe SqlClient DSL

Kotysa will generate SQL for you !

// return all admin users
sqlClient.select<User>()
        .innerJoin<Role>().on { it[User::roleId] }
        .where { it[Role::label] eq "admin" }
        .fetchAll()

No annotations, no code generation, just regular Kotlin code ! No JPA, just pure SQL !

Getting started

Kotysa is agnostic from Sql Engine (SqLite on Android, R2DBC, JDBC in the future) :

See sample projects here.

Kotysa is not production ready yet, some key features are still missing. Early releases will provide new features (see next milestones).

Type safety relies on type and nullability of the Entity property (or getter).

Kotysa provides Kotlin Coroutines first class support with R2DBC

You can’t perform that action at this time.