Repository navigation
Closed
Description
Implement NodeStore Trait for Turso Backend
Parent Epic: #461 (SurrealDB Migration)
Phase: 1 - Abstraction Layer
Estimated Time: 2-3 days
Depends On: #462 (NodeStore Trait)
Objective
Wrap existing Turso database code with the NodeStore trait implementation, ensuring zero regressions while enabling backend abstraction.
Implementation
1. Create TursoStore Wrapper
File: packages/desktop-app/src-tauri/src/datastore/turso/store.rs
use async_trait::async_trait;
use anyhow::Result;
use crate::datastore::NodeStore;
use crate::models::{Node, NodeFilter, NodeUpdate};
pub struct TursoStore {
// Existing Turso connection/client fields
connection: libsql::Connection,
}
#[async_trait]
impl NodeStore for TursoStore {
async fn create_node(&self, node: Node) -> Result<Node> {
// Wrap existing create_node implementation
// Use existing SQL queries and logic
}
async fn get_node(&self, id: &str) -> Result<Option<Node>> {
// Wrap existing get_node implementation
}
async fn update_node(&self, id: &str, update: NodeUpdate) -> Result<Node> {
// Wrap existing update_node implementation
}
async fn delete_node(&self, id: &str) -> Result<()> {
// Wrap existing delete_node implementation
}
async fn query_nodes(&self, filter: NodeFilter) -> Result<Vec<Node>> {
// Wrap existing query implementation
}
async fn search_nodes(&self, query: &str) -> Result<Vec<Node>> {
// Wrap existing search implementation
}
async fn get_children(&self, parent_id: &str) -> Result<Vec<Node>> {
// Wrap existing hierarchy queries
}
async fn move_node(&self, id: &str, new_parent: Option<&str>) -> Result<()> {
// Wrap existing move operation
}
async fn set_property(&self, id: &str, key: &str, value: serde_json::Value) -> Result<()> {
// Wrap existing property setting (JSON column update)
}
async fn get_property(&self, id: &str, key: &str) -> Result<Option<serde_json::Value>> {
// Wrap existing property retrieval
}
async fn batch_create(&self, nodes: Vec<Node>) -> Result<Vec<Node>> {
// Wrap existing batch insert logic
}
async fn transaction<F, T>(&self, f: F) -> Result<T>
where
F: FnOnce() -> Result<T> + Send,
{
// Wrap existing transaction support
}
}
impl TursoStore {
pub async fn new(connection_string: String) -> Result<Self> {
// Use existing Turso connection logic
Ok(Self { connection })
}
}2. Update Existing Code to Use Trait
Strategy: Minimal changes to existing code
- Replace direct Turso calls with
NodeStoretrait calls - Use factory pattern for store instantiation
- Keep all existing SQL queries and logic intact
3. Module Structure
src/datastore/
├── trait.rs # NodeStore trait (from #462)
├── factory.rs # Factory pattern (from #462)
├── turso/
│ ├── mod.rs
│ └── store.rs # TursoStore impl (this issue)
└── surreal/ # (future: #463)
Acceptance Criteria
- TursoStore implements all NodeStore trait methods
- All existing functionality preserved (zero regressions)
- All existing tests pass with new wrapper
- Turso backend selected by default (feature flag "turso")
- Code compiles with clippy checks passing
- Documentation updated with migration notes
Testing
Existing Tests
- All current Turso tests pass unchanged
- CRUD operations work identically
- Query performance unchanged
New Tests
- TursoStore correctly implements NodeStore trait
- Factory pattern creates TursoStore when feature="turso"
- Transaction support works correctly
Migration Impact
Zero Breaking Changes Required:
- Existing code calling Turso directly will be gradually refactored
- Old and new code can coexist during transition
- Feature flag ensures Turso remains default backend
Dependencies
- Create NodeStore Trait Abstraction Layer #462: NodeStore Trait Abstraction Layer
References
- Epic SurrealDB Migration - Hybrid Architecture (Desktop-Only) #461: SurrealDB Migration
- Architect's migration plan (backend wrapper section)
- Existing Turso implementation in codebase
Activity
Complete SurrealDB Feasibility PoC - All GO Criteria Met (#460)
Add Epic #461 Phase 1 architectural planning documentation
SurrealDB Migration - Hybrid Architecture (Desktop-Only) (#467)
docs: Add phase markers and status tracking to SurrealDB migration docs
malibio commentedon Nov 12, 2025
Issue #463 - COMPLETE ✅
TursoStore implementation is complete and tested.
Completed Work
Implementation:
packages/core/src/db/turso_store.rsTesting: 6 integration tests (lines 650-807)
Integration: NodeService refactored to use TursoStore
Commits
PR: #469
Related: Issue #462 (parent task, also closed)
Status: Implementation complete and tested. Closing this issue.
SurrealDB Migration - Hybrid Architecture (Desktop-Only) (#467)
SurrealDB Migration - Hybrid Architecture (Desktop-Only) (#467)