Skip to content

Commit

Permalink
Lag interface for Exposed
Browse files Browse the repository at this point in the history
  • Loading branch information
oddgfa committed Aug 14, 2023
1 parent 01329d2 commit 3f76aa8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ import no.nav.arbeidsgiver.sykefravarsstatistikk.api.applikasjon.domenemodeller.
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.upsert
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
import org.springframework.stereotype.Component

@Component
open class ImportEksportStatusRepository(
@Qualifier("sykefravarsstatistikkJdbcTemplate") private val namedParameterJdbcTemplate: NamedParameterJdbcTemplate,
val database: Database,
) : Table("import_eksport_status") {
override val database: Database,
) : Table("import_eksport_status"), UsingExposed {
val årstall = varchar("aarstall", 4)
val kvartal = varchar("kvartal", 1)
val importertStatistikk = bool("importert_statistikk").default(false)
Expand All @@ -25,7 +21,7 @@ open class ImportEksportStatusRepository(
override val primaryKey: PrimaryKey = PrimaryKey(årstall, kvartal)

fun settImportEksportStatus(importEksportStatus: ImportEksportStatus) {
transaction(database) {
transaction {
upsert {
it[årstall] = importEksportStatus.årstallOgKvartal.årstall.toString()
it[kvartal] = importEksportStatus.årstallOgKvartal.kvartal.toString()
Expand All @@ -40,7 +36,7 @@ open class ImportEksportStatusRepository(
fun hentImportEksportStatus(
årstallOgKvartal: ÅrstallOgKvartal
): List<ImportEksportStatus> {
return transaction(database) {
return transaction {
select {
årstall eq årstallOgKvartal.årstall.toString()
kvartal eq årstallOgKvartal.kvartal.toString()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package no.nav.arbeidsgiver.sykefravarsstatistikk.api.infrastruktur.database

import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.Transaction
import org.jetbrains.exposed.sql.transactions.transaction

interface UsingExposed {
val database: Database

fun <T> transaction(statement: Transaction.() -> T): T = transaction(database, statement)
}

0 comments on commit 3f76aa8

Please sign in to comment.