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, + ) + } +}