-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30b7f93
commit 1d2fd1d
Showing
4 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/kotlin/no/kartverket/matrikkel/bygning/repositories/DemoRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package no.kartverket.matrikkel.bygning.repositories | ||
|
||
import kotlinx.serialization.Serializable | ||
import no.kartverket.matrikkel.bygning.models.EnergikildeDTO | ||
import java.sql.Connection | ||
import java.sql.ResultSet | ||
|
||
@Serializable | ||
data class DemospokelseDTO( | ||
val id: Int, | ||
val spokelsesnavn: String, | ||
) | ||
|
||
class DemoRepository(private val dbConnection: Connection) { | ||
fun getDemospokelser(): List<DemospokelseDTO> { | ||
val statement = dbConnection.createStatement() | ||
|
||
val resultSet = statement.executeQuery( | ||
""" | ||
select * from demospokelser; | ||
""".trimIndent() | ||
) | ||
|
||
return resultSet.toDemospokelseDTO() | ||
} | ||
|
||
fun ResultSet.toDemospokelseDTO(): List<DemospokelseDTO> { | ||
val demospokelser: MutableList<DemospokelseDTO> = emptyList<DemospokelseDTO>().toMutableList() | ||
|
||
while (this.next()) { | ||
demospokelser.add( | ||
DemospokelseDTO( | ||
id = this.getInt("id"), spokelsesnavn = this.getString("spokelsesnavn") | ||
) | ||
) | ||
} | ||
|
||
return demospokelser | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
create table if not exists demospokelser | ||
( | ||
id serial primary key, | ||
spokelsesnavn varchar(50) not null | ||
); | ||
|
||
insert into demospokelser(spokelsesnavn) | ||
values ('Mr. Spooky'), | ||
('Ghostman'), | ||
('Hattifnatten'), | ||
('Mr. Bones'); |