chore(frontend): improve comment formatting, fix minor code inconsistencies, and enhance SQLite worker initialization

- Standardized comment formatting across SQLite worker and local DB modules for clarity and consistency.
- Fixed minor typos in comments and removed redundant placeholders.
- Refined SQLite Web Worker initialization logic by aligning method implementations with clean code practices.
- Updated Kotlin code in DB driver factories to handle exceptions concisely and improve robustness during schema initialization.
This commit is contained in:
2026-02-01 12:15:16 +01:00
parent af0b7c5f9b
commit 77c20bf2ba
5 changed files with 114 additions and 116 deletions
View File
@@ -25,7 +25,7 @@ actual class DatabaseDriverFactory {
setVersion(driver, schemaVersion) setVersion(driver, schemaVersion)
console.log("Database Schema created and version set to $schemaVersion") console.log("Database Schema created and version set to $schemaVersion")
} catch (e: Throwable) { } catch (e: Throwable) {
// If tables already exist but version was 0 (e.g. previous broken run), we might get here. // If tables already exist but a version was 0 (e.g., previous broken run), we might get here.
val msg = e.message ?: "" val msg = e.message ?: ""
if (msg.contains("already exists", ignoreCase = true)) { if (msg.contains("already exists", ignoreCase = true)) {
console.warn("Tables already exist but version was 0. Assuming DB is initialized. Setting version to $schemaVersion.") console.warn("Tables already exist but version was 0. Assuming DB is initialized. Setting version to $schemaVersion.")
@@ -58,7 +58,7 @@ actual class DatabaseDriverFactory {
var cursorRef: SqlCursor? = null var cursorRef: SqlCursor? = null
// executeQuery returns QueryResult<Boolean> because mapper returns QueryResult<Boolean> // executeQuery returns QueryResult<Boolean> because mapper returns QueryResult<Boolean>
val hasNext = driver.executeQuery<Boolean>( val hasNext = driver.executeQuery(
identifier = null, identifier = null,
sql = "PRAGMA user_version;", sql = "PRAGMA user_version;",
mapper = { cursor -> mapper = { cursor ->
@@ -16,15 +16,15 @@ actual class DatabaseDriverFactory {
// Schema creation/migration needs to be handled carefully. // Schema creation/migration needs to be handled carefully.
// For now, we just create it if it doesn't exist. // For now, we just create it if it doesn't exist.
// In a real app, we'd check version and migrate. // In a real app, we'd check the version and migrate.
// Since generateAsync=true, the Schema.create signature might be suspend or return AsyncResult. // Since generateAsync=true, the Schema.create signature might be suspended or return AsyncResult.
// However, JdbcSqliteDriver is synchronous. We might need to wrap or await. // However, JdbcSqliteDriver is synchronous. We might need to wrap or await.
// But wait! Schema.create(driver) returns void or Unit usually. // But wait! Schema.create(driver) usually returns void or Unit.
// Let's check the generated code later. For now, we assume standard behavior. // Let's check the generated code later. For now, we assume standard behavior.
try { try {
AppDatabase.Schema.create(driver).await() AppDatabase.Schema.create(driver).await()
} catch (e: Exception) { } catch (_: Exception) {
// Schema might already exist. // Schema might already exist.
// SQLDelight doesn't have "createIfNotExists" built-in easily without version check. // SQLDelight doesn't have "createIfNotExists" built-in easily without version check.
// We'll leave this simple for now and refine with proper migration logic later. // We'll leave this simple for now and refine with proper migration logic later.
@@ -12,9 +12,7 @@ import io.ktor.client.request.parameter
interface SyncableRepository<T : Syncable> { interface SyncableRepository<T : Syncable> {
/** /**
* Cursor für Delta-Sync. * Cursor für Delta-Sync.
*
* Konvention: UUIDv7 als String (Backend kann `>` vergleichen) oder ein kompatibler Cursor. * Konvention: UUIDv7 als String (Backend kann `>` vergleichen) oder ein kompatibler Cursor.
*
* @return letzter bekannter Cursor lokal oder `null`, wenn noch keine Daten existieren. * @return letzter bekannter Cursor lokal oder `null`, wenn noch keine Daten existieren.
*/ */
suspend fun getLatestSince(): String? suspend fun getLatestSince(): String?