reposilite-playground / exposed-upsert

Upsert DSL extension for Exposed, Kotlin SQL framework
The Unlicense
34 stars 3 forks source link
exposed kotlin mariadb mysql postgresql sql sqlite upsert

Exposed Upsert CI codecov Maven Central

Upsert DSL extension for Exposed, Kotlin SQL framework. Project bases on various solutions provided by community in the official "Exposed: Support upsert functionality" feature request. After 4 years, maintainers still didn't provide a solution, so here's a straightforward alternative.

Coverage

Supported databases with tests run against real databases using Testcontainers:

DB Status
H2 Unsupported
H2 (MySQL Dialect)
MySQL
MariaDB
Oracle Not implemented (Licensed to enterprise)
PostgreSQL
SQL Server Unsupported
SQLite

Usage

class StatisticsTable : Table("statistics") {
    // [...]

    val uniqueTypeValue = withUnique("unique_http_method_to_uri", httpMethod, uri)
}

StatisticsTable.upsert(conflictIndex = StatisticsTable.uniqueTypeValue,
    insertBody = {
        it[this.httpMethod] = record.httpMethod
        it[this.uri] = record.uri
        it[this.count] = record.count
    },
    updateBody = {
        with(SqlExpressionBuilder) {
            it.update(StatisticsTable.count, StatisticsTable.count + record.count)
        }
    }
)

Notes

Download

Gradle

dependencies {
    implementation("net.dzikoysk:exposed-upsert:1.2.1")
}

Manual

You can find all available versions in the repository:

Who's using