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)
console.log("Database Schema created and version set to $schemaVersion")
} 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 ?: ""
if (msg.contains("already exists", ignoreCase = true)) {
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
// executeQuery returns QueryResult<Boolean> because mapper returns QueryResult<Boolean>
val hasNext = driver.executeQuery<Boolean>(
val hasNext = driver.executeQuery(
identifier = null,
sql = "PRAGMA user_version;",
mapper = { cursor ->
@@ -33,27 +33,27 @@ try {
rowMode: 'array',
callback: (row) => rows.push(row)
});
return postMessage({ id: data.id, results: { values: rows } });
return postMessage({id: data.id, results: {values: rows}});
}
case 'begin_transaction':
db.exec('BEGIN TRANSACTION;');
return postMessage({ id: data.id, results: [] });
return postMessage({id: data.id, results: []});
case 'end_transaction':
db.exec('END TRANSACTION;');
return postMessage({ id: data.id, results: [] });
return postMessage({id: data.id, results: []});
case 'rollback_transaction':
db.exec('ROLLBACK TRANSACTION;');
return postMessage({ id: data.id, results: [] });
return postMessage({id: data.id, results: []});
default:
throw new Error(`Unsupported action: ${data && data.action}`);
}
} catch (err) {
console.error("Worker: Error processing message", err);
return postMessage({ id: data && data.id, error: err?.message ?? String(err) });
return postMessage({id: data && data.id, error: err?.message ?? String(err)});
}
}
self.onerror = function(event) {
self.onerror = function (event) {
console.error("Error in Web Worker (onerror):", event.message, event.filename, event.lineno);
// Don't postMessage here as it might confuse the driver if it expects a response to a query
};
@@ -16,15 +16,15 @@ actual class DatabaseDriverFactory {
// Schema creation/migration needs to be handled carefully.
// For now, we just create it if it doesn't exist.
// In a real app, we'd check version and migrate.
// Since generateAsync=true, the Schema.create signature might be suspend or return AsyncResult.
// In a real app, we'd check the version and migrate.
// Since generateAsync=true, the Schema.create signature might be suspended or return AsyncResult.
// 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.
try {
AppDatabase.Schema.create(driver).await()
} catch (e: Exception) {
} catch (_: Exception) {
// Schema might already exist.
// 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.
@@ -12,9 +12,7 @@ import io.ktor.client.request.parameter
interface SyncableRepository<T : Syncable> {
/**
* Cursor für Delta-Sync.
*
* Konvention: UUIDv7 als String (Backend kann `>` vergleichen) oder ein kompatibler Cursor.
*
* @return letzter bekannter Cursor lokal oder `null`, wenn noch keine Daten existieren.
*/
suspend fun getLatestSince(): String?