package database import database.tables.CarTable import database.tables.CoordinatesTable import database.tables.HumanBeingTable import database.tables.UserTable import io.github.oshai.kotlinlogging.KotlinLogging import models.HumanBeing import org.jetbrains.exposed.v1.core.* import org.jetbrains.exposed.v1.jdbc.* import org.jetbrains.exposed.v1.jdbc.transactions.transaction import java.util.UUID import kotlin.uuid.ExperimentalUuidApi import kotlin.uuid.Uuid private val logger = KotlinLogging.logger {} class Repository(private val filePath: String) { //fun read(): List {} @OptIn(ExperimentalUuidApi::class) fun write(items: Collection, userId: UUID): Boolean { transaction { for (item in items) { val cords = CoordinatesTable.insertAndGetId { it[x] = item.coordinates.x it[y] = item.coordinates.y } val cars = CarTable.insertAndGetId { it[cool] = item.car.cool } val user = UserTable .select(UserTable.id) .where { UserTable.id eq userId } .first() HumanBeingTable.insert { it[owner_id] = userId it[name] = item.name it[id] = user[UserTable.id] // it fucking autoincrements (check perplexity) it[coordinates] = cords it[creationDate] = item.creationDate it[realHero] = item.realHero it[hasToothpick] = item.hasToothpick it[impactSpeed] = item.impactSpeed it[soundtrackName] = item.soundtrackName it[minutesOfWaiting] = item.minutesOfWaiting it[car] = cars it[weaponType] = item.weaponType } } } } }