From bf31232d92c5f4047f9f9152c382c7f81fa97beb Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 3 Apr 2024 20:21:04 +0200 Subject: [PATCH] feat(connector): create basic queries for ProjectDatabase --- .../shared/database/ProjectDatabase.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/database/ProjectDatabase.kt diff --git a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/database/ProjectDatabase.kt b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/database/ProjectDatabase.kt new file mode 100644 index 0000000..cd45ce6 --- /dev/null +++ b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/database/ProjectDatabase.kt @@ -0,0 +1,42 @@ +package io.anthonyberg.connector.shared.database + +import io.anthonyberg.connector.shared.entity.Project + +internal class ProjectDatabase (driverFactory: DriverFactory) { + private val database = Database(driverFactory.createDriver()) + private val dbQuery = database.projectQueries + + /** + * Gets all the Projects in the database + */ + internal fun getAllProjects(): List { + return dbQuery.selectAllProjects(::mapProjectSelecting).executeAsList() + } + + private fun mapProjectSelecting( + id: Long, + name: String, + aircraftType: String, + createdUTC: String, + modifiedUTC: String? + ): Project { + return Project( + id = id.toInt(), + name = name, + aircraftType = aircraftType, + createdUTC = createdUTC, + modifiedUTC = modifiedUTC, + ) + } + + /** + * Inserts a project into the database + */ + internal fun createProject(project: Project) { + dbQuery.createProject( + name = project.name, + aircraftType = project.aircraftType, + createdUTC = project.createdUTC, + ) + } +}