feat(connector): add count projects function

This commit is contained in:
Anthony 2024-04-03 21:24:07 +02:00
parent ac986abcb3
commit 0013cf1a41
3 changed files with 28 additions and 3 deletions

View File

@ -10,6 +10,13 @@ import io.anthonyberg.connector.shared.entity.Project
class ProjectTransaction (driverFactory: DriverFactory) { class ProjectTransaction (driverFactory: DriverFactory) {
private val database = ProjectDatabase(driverFactory) private val database = ProjectDatabase(driverFactory)
/**
* Creates a project in the database.
*/
fun createProject(project: Project) {
database.createProject(project)
}
/** /**
* Gets all Projects in the database. * Gets all Projects in the database.
*/ */
@ -19,9 +26,17 @@ class ProjectTransaction (driverFactory: DriverFactory) {
} }
/** /**
* Creates a project in the database. * Gets the number of projects in the database
*/ */
fun createProject(project: Project) { fun countProjects(): Long {
database.createProject(project) return database.countProjects()
}
/**
* Checks if projects are on the database.
* @return `true` if projects exist
*/
fun projectExists(): Boolean {
return database.countProjects() > 0
} }
} }

View File

@ -39,4 +39,11 @@ internal class ProjectDatabase (driverFactory: DriverFactory) {
createdUTC = project.createdUTC, createdUTC = project.createdUTC,
) )
} }
/**
* Counts the amount of entries there are for projects
*/
internal fun countProjects(): Long {
return dbQuery.countProjects().executeAsOne()
}
} }

View File

@ -12,3 +12,6 @@ VALUES (?, ?, ?);
selectAllProjects: selectAllProjects:
SELECT * FROM Project; SELECT * FROM Project;
countProjects:
SELECT COUNT(*) FROM Project;