Skip to content

Commit

Permalink
Eksplisitt sett database
Browse files Browse the repository at this point in the history
  • Loading branch information
oddgfa committed Aug 14, 2023
1 parent 7e9dd75 commit 01329d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ package no.nav.arbeidsgiver.sykefravarsstatistikk.api.infrastruktur.database

import no.nav.arbeidsgiver.sykefravarsstatistikk.api.applikasjon.domenemodeller.ImportEksportStatus
import no.nav.arbeidsgiver.sykefravarsstatistikk.api.applikasjon.domenemodeller.ÅrstallOgKvartal
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 : Table("import_eksport_status") {
open class ImportEksportStatusRepository(
@Qualifier("sykefravarsstatistikkJdbcTemplate") private val namedParameterJdbcTemplate: NamedParameterJdbcTemplate,
val database: Database,
) : Table("import_eksport_status") {
val årstall = varchar("aarstall", 4)
val kvartal = varchar("kvartal", 1)
val importertStatistikk = bool("importert_statistikk").default(false)
Expand All @@ -19,7 +25,7 @@ open class ImportEksportStatusRepository : Table("import_eksport_status") {
override val primaryKey: PrimaryKey = PrimaryKey(årstall, kvartal)

fun settImportEksportStatus(importEksportStatus: ImportEksportStatus) {
transaction {
transaction(database) {
upsert {
it[årstall] = importEksportStatus.årstallOgKvartal.årstall.toString()
it[kvartal] = importEksportStatus.årstallOgKvartal.kvartal.toString()
Expand All @@ -34,7 +40,7 @@ open class ImportEksportStatusRepository : Table("import_eksport_status") {
fun hentImportEksportStatus(
årstallOgKvartal: ÅrstallOgKvartal
): List<ImportEksportStatus> {
return transaction {
return transaction(database) {
select {
årstall eq årstallOgKvartal.årstall.toString()
kvartal eq årstallOgKvartal.kvartal.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ open class ImportEksportStatusRepositoryTest {
}

private fun ImportEksportStatusRepository.slettAlt() {
transaction {
transaction(database) {
deleteAll()
}
}
Expand Down

0 comments on commit 01329d2

Please sign in to comment.