Skip to content

Move RusqliteExecutor and SQLite functions to common crate#2486

Open
findolor wants to merge 3 commits intomainfrom
2026-02-27-rust-local-db-syncing
Open

Move RusqliteExecutor and SQLite functions to common crate#2486
findolor wants to merge 3 commits intomainfrom
2026-02-27-rust-local-db-syncing

Conversation

@findolor
Copy link
Collaborator

@findolor findolor commented Feb 27, 2026

Motivation

The RusqliteExecutor and custom SQLite functions (float_is_zero, float_negate, float_sum, float_zero_hex) were previously confined to the CLI crate, making them inaccessible to other consumers in the workspace. Moving them to the common crate enables reuse across crates that need direct SQLite access with custom functions.

Solution

  • Relocated RusqliteExecutor and all custom SQLite function modules from crates/cli/src/commands/local_db/ to crates/common/src/local_db/.
  • The CLI executor now re-exports RusqliteExecutor from common, preserving backwards compatibility.
  • Added rusqlite (with functions feature) as a regular dependency in common; switched rusqlite dev-dependency to tempfile.
  • Made LocalDb and its constructor public so external consumers can construct a LocalDb from a RusqliteExecutor.
  • Added a non-wasm set_local_db method on RaindexClient for injecting the database at runtime.
  • Both new modules are gated with #[cfg(not(target_family = "wasm"))].

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • New Features

    • SQLite-backed local database with batch execution, transactional safety, and JSON query results
    • RaindexClient can be configured with a local database (non-WASM)
  • Refactor

    • Consolidated local DB implementation and exposure into shared common code for non-WASM targets
  • Chores

    • Bumped SQLite dependency and updated related dev-dependencies and test utilities

Relocate the executor and custom SQLite functions modules into
crates/common/src/local_db so they can be reused outside the CLI.
The CLI executor now re-exports from common. Also adds rusqlite
with the functions feature as a regular dependency and switches
the dev-dependency to tempfile.
Expose LocalDb and its constructor so external consumers can
construct a LocalDb from a RusqliteExecutor. Add a non-wasm
set_local_db method on RaindexClient for injecting the database.
@findolor findolor self-assigned this Feb 27, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

Walkthrough

Moved the Rusqlite-backed local DB executor into the common crate, re-exported it from the CLI, exposed LocalDb and a setter on RaindexClient for non‑WASM, added rusqlite/tempfile dependencies, and adjusted module exports and small comment removals.

Changes

Cohort / File(s) Summary
Executor relocation & re-export
crates/common/src/local_db/executor.rs, crates/cli/src/commands/local_db/executor.rs
Introduced full RusqliteExecutor implementation in crates/common (connection setup, value conversion, async LocalDbQueryExecutor impl, tests); replaced CLI-local implementation with pub use ...::RusqliteExecutor re-export in CLI.
Local DB module exports
crates/common/src/local_db/mod.rs, crates/cli/src/commands/local_db/mod.rs
Added executor and functions modules to crates/common behind #[cfg(not(target_family = "wasm"))]; removed pub mod functions export from the CLI local_db module.
RaindexClient / LocalDb visibility
crates/common/src/raindex_client/local_db/mod.rs, crates/common/src/raindex_client/mod.rs
Made LocalDb and its new constructor pub; added non‑WASM pub fn set_local_db(&self, db: LocalDb) to RaindexClient.
Dependency updates
crates/common/Cargo.toml, crates/cli/Cargo.toml
Updated rusqlite to 0.32 with functions feature in common and CLI; moved rusqlite from dev to main for non‑WASM in crates/common; added tempfile = "3" to non‑WASM dev‑dependencies.
SQLite function comments cleanup
crates/common/src/local_db/functions/mod.rs, crates/common/src/local_db/functions/float_sum.rs, crates/common/src/local_db/functions/float_negate.rs
Removed several doc/inline comments from SQLite function modules/tests; no behavioral changes.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the primary change: moving RusqliteExecutor and SQLite functions from the CLI crate to the common crate for broader reuse.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2026-02-27-rust-local-db-syncing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@findolor findolor requested a review from hardyjosh February 27, 2026 12:22
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/common/Cargo.toml`:
- Line 81: Replace the direct version pin "tempfile = \"3\"" with a workspace
reference to match other crates; change the dependency entry so it uses
tempfile.workspace = true (i.e., convert the current tempfile dependency line to
the workspace-style declaration) to centralize version management and ensure
consistency with the CLI crate's tempfile.workspace = true usage.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d33f419 and f3bc380.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • crates/cli/Cargo.toml
  • crates/common/Cargo.toml

httpmock = "0.7.0"
rain_orderbook_test_fixtures = { workspace = true }
rusqlite = "0.31.0"
tempfile = "3"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Use workspace reference for tempfile dependency.

The CLI crate uses tempfile.workspace = true (line 53 in crates/cli/Cargo.toml), but here a direct version is specified. For consistency and centralized version management, use the workspace reference.

♻️ Proposed fix
-tempfile = "3"
+tempfile = { workspace = true }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
tempfile = "3"
tempfile = { workspace = true }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/common/Cargo.toml` at line 81, Replace the direct version pin
"tempfile = \"3\"" with a workspace reference to match other crates; change the
dependency entry so it uses tempfile.workspace = true (i.e., convert the current
tempfile dependency line to the workspace-style declaration) to centralize
version management and ensure consistency with the CLI crate's
tempfile.workspace = true usage.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant