Skip to content

Implement NodeStore Trait for Turso Backend #463

Closed

Description

@malibio

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 NodeStore trait 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

References

Activity

  1. malibio commented on Nov 12, 2025

    @malibio
    CollaboratorAuthor

    Issue #463 - COMPLETE ✅

    TursoStore implementation is complete and tested.

    Completed Work

    Implementation: packages/core/src/db/turso_store.rs

    • All 22 NodeStore trait methods implemented
    • Delegates to DatabaseService db_* methods
    • Proper error handling and type conversions
    • Row → Node model conversion

    Testing: 6 integration tests (lines 650-807)

    • ✅ test_create_and_get_node
    • ✅ test_update_node
    • ✅ test_delete_node
    • ✅ test_get_children
    • ✅ test_mentions
    • ✅ test_schema_operations

    Integration: NodeService refactored to use TursoStore

    • 15/22 methods actively using trait abstraction
    • Zero breaking changes to existing APIs
    • All 497-500 tests passing

    Commits

    • df84d38: Implement TursoStore wrapper for NodeStore trait
    • 3cb82c1: Fix TursoStore test failures
    • 529ca46: Refactor NodeService to use NodeStore trait

    PR: #469
    Related: Issue #462 (parent task, also closed)


    Status: Implementation complete and tested. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions