Local DB Commits
Source:lib/local-db-commits.ts (248 lines, 10.7KB)
The local-db-commits module is the “Vault Guard” — a specialized repository that handles all task-level CRUD operations against the local SQLite database using atomic transactions and the Unified Identity strategy.
Unified Identity Strategy
To prevent “Split-Brain” duplication, the module uses the official Convex _id as the local primary key. The remoteId parameter in every function IS the Convex _id, and it is used as both the id and convex_id columns:Core Operations
insertTaskToLocalDb()
Creates a new task with all projected instances in a single atomic transaction:- INSERT OR REPLACE into local_tasks with all 17 columns
- Call syncInstancesToLocalDb() to batch-insert all backend-projected instances
- Both operations wrapped in db.withTransactionAsync()
updateTaskInLocalDb()
Updates task master rules and overwrites the future instance trajectory:- UPDATE local_tasks SET with all mutable columns
- DELETE FROM task_instances WHERE task_id = ? AND is_manual_edit = 0 (protects manual edits)
- Call syncInstancesToLocalDb() to repopulate with newly projected instances
updateStrictModeInLocalDb()
Activates or extends Strict Mode:- UPDATE local_tasks SET strict_until and strict_duration_days
- DELETE non-manual instances
- Re-sync instances (which now inherit the strict_until timestamp)