Skip to content

Commit 2857e2f

Browse files
committed
Reverted some endpoints previously hidden
1 parent 64e3cdd commit 2857e2f

10 files changed

Lines changed: 552 additions & 549 deletions

File tree

lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ moka = { version = "0.12.10", features = ["sync", "future"] } # Consistent
6666
thiserror = "2.0.12" # Consistent
6767
models = { path = "../models", features = ["rocksdb-errors", "sled-errors", "bincode-errors"] } # Consistent, features enabled
6868
bcrypt = "0.15.1" # Aligned with models (highest version)
69+
regex = "1.11.1" # Consistent
6970

7071
[features]
7172
default = []

lib/src/database.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// lib/src/database.rs
22
// Corrected: 2025-07-02 - Final version ensuring correct trait usage and error handling.
3-
// Fixed models import path and conditional RocksDBStorage import.
3+
// Fixed: 2025-07-02 - Corrected import for SledStorage and RocksDBStorage, and models crate.
44

55
use std::sync::Arc;
6-
// Conditionally import RocksDBStorage
7-
#[cfg(feature = "with-rocksdb")]
8-
use crate::storage_engine::RocksDBStorage;
9-
use crate::storage_engine::{GraphStorageEngine, SledGraphStorage, StorageConfig, StorageEngineType, open_sled_db};
10-
use models::{Vertex, Edge, Identifier}; // Corrected: Removed `crate::` prefix
6+
// Corrected imports for SledStorage and RocksDBStorage to use their full paths
7+
use crate::storage_engine::{GraphStorageEngine, StorageConfig, StorageEngineType, open_sled_db};
8+
use crate::storage_engine::sled_storage::SledStorage; // Explicitly import SledStorage
9+
#[cfg(feature = "with-rocksdb")] // Apply cfg to the import itself
10+
use crate::storage_engine::rocksdb_storage::RocksDBStorage; // Explicitly import RocksDBStorage
11+
12+
// Corrected import for models crate (it's a separate crate, not a module within `crate`)
13+
use models::{Vertex, Edge, Identifier};
1114
use models::errors::{GraphError, GraphResult}; // Use GraphResult directly
1215
use uuid::Uuid;
1316
use serde_json::Value; // For query results
@@ -35,9 +38,9 @@ impl Database {
3538
pub async fn new(config: StorageConfig) -> GraphResult<Self> {
3639
let storage_engine: Arc<dyn GraphStorageEngine> = match config.engine_type {
3740
StorageEngineType::Sled => {
38-
// Open Sled DB and create SledGraphStorage
41+
// Open Sled DB and create SledStorage
3942
let db = open_sled_db(&config.data_path)?;
40-
Arc::new(SledGraphStorage::new(db)?)
43+
Arc::new(SledStorage::new(db)?)
4144
},
4245
StorageEngineType::RocksDB => {
4346
// Conditionally compile RocksDB initialization if the feature is enabled

lib/src/query_parser/query_parser.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
// lib/src/query_parser/query_parser.rs
2+
// Updated: 2025-07-02 - Re-introduced regex for Cypher and SQL query detection.
3+
14
use graphql_parser::parse_query;
25
use graphql_parser::query::Document; // Required for parse_query to compile
36
use std::fmt::Debug;
7+
use regex::Regex; // Import the regex crate
8+
use once_cell::sync::Lazy; // For lazy static regex initialization
49

510
/// Represents the type of a parsed query: Cypher, SQL, or GraphQL.
611
#[derive(Debug)]
@@ -10,20 +15,35 @@ pub enum QueryType {
1015
GraphQL,
1116
}
1217

18+
// Lazily initialized regex for Cypher and SQL keywords
19+
static CYPHER_REGEX: Lazy<Regex> = Lazy::new(|| {
20+
// Matches common Cypher keywords at the start of the query,
21+
// ignoring leading whitespace and case.
22+
Regex::new(r"^\s*(?i)(MATCH|CREATE|MERGE|RETURN|DETACH|DELETE|SET|REMOVE|WHERE|WITH|UNWIND|CALL|LOAD CSV)").unwrap()
23+
});
24+
25+
static SQL_REGEX: Lazy<Regex> = Lazy::new(|| {
26+
// Matches common SQL keywords at the start of the query,
27+
// ignoring leading whitespace and case.
28+
Regex::new(r"^\s*(?i)(SELECT|INSERT INTO|UPDATE|DELETE FROM|CREATE TABLE|ALTER TABLE|DROP TABLE|TRUNCATE TABLE)").unwrap()
29+
});
30+
31+
1332
/// Attempts to parse a query string into a known `QueryType`.
1433
pub fn parse_query_from_string(query: &str) -> Result<QueryType, String> {
1534
// Try to parse as a GraphQL query first
35+
// This is typically a more strict grammar, so it's a good first check.
1636
if parse_query::<&str>(query).is_ok() {
1737
return Ok(QueryType::GraphQL);
1838
}
1939

20-
// Try to infer Cypher
21-
if query.trim_start().starts_with("MATCH") || query.contains("RETURN") {
40+
// Try to infer Cypher using regex
41+
if CYPHER_REGEX.is_match(query) {
2242
return Ok(QueryType::Cypher);
2343
}
2444

25-
// Try to infer SQL
26-
if query.contains("SELECT") || query.contains("FROM") {
45+
// Try to infer SQL using regex
46+
if SQL_REGEX.is_match(query) {
2747
return Ok(QueryType::SQL);
2848
}
2949

lib/src/storage_engine/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ pub struct StorageConfig {
2020
/// Optional: Any specific configuration parameters for the chosen engine.
2121
/// This could be a JSON string or a more structured enum/struct later.
2222
pub engine_specific_config: Option<String>,
23+
/// Optional: Maximum number of open files for RocksDB.
24+
/// This field is specifically used by the RocksDB storage engine.
25+
#[serde(default)] // Allows this field to be optional in config files, defaulting to None
26+
pub max_open_files: Option<i32>,
2327
}
2428

2529
impl Default for StorageConfig {
@@ -28,6 +32,7 @@ impl Default for StorageConfig {
2832
engine_type: StorageEngineType::Sled, // Default to Sled
2933
data_path: "./data/graphdb_storage".to_string(), // Default data path
3034
engine_specific_config: None,
35+
max_open_files: None, // Default to None for max_open_files
3136
}
3237
}
3338
}

lib/src/storage_engine/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
// lib/src/storage_engine/mod.rs
22
// Corrected: 2025-07-02 - Fixed module re-exports to resolve import errors.
3+
// Refactored: 2025-07-02 - Added storage_utils module for common helper functions.
34

4-
pub mod storage_engine; // Declares the module defined in storage_engine.rs
5-
pub mod sled_storage;
5+
pub mod storage_engine; // Declares the module defined in storage_engine.rs (now trait-only)
6+
pub mod sled_storage; // Declares the module for Sled implementation
67
#[cfg(feature = "with-rocksdb")]
7-
pub mod rocksdb_storage;
8+
pub mod rocksdb_storage; // Declares the module for RocksDB implementation
89
pub mod config;
10+
pub mod storage_utils; // Declare the new utility module
911

1012
// Re-export key traits and structs for easier access from `crate::storage_engine::*`
1113
pub use self::storage_engine::{StorageEngine, GraphStorageEngine};
12-
pub use self::sled_storage::{SledGraphStorage, open_sled_db}; // SledGraphStorage is the actual implementation struct
14+
// Corrected: Re-export SledStorage (not SledGraphStorage)
15+
pub use self::sled_storage::{SledStorage, open_sled_db};
1316
#[cfg(feature = "with-rocksdb")]
1417
pub use self::rocksdb_storage::RocksDBStorage;
1518
pub use self::config::{StorageConfig, StorageEngineType};
19+
// No need to re-export individual functions from storage_utils here unless they are meant for direct top-level use.
20+
// They will be imported directly by sled_storage and rocksdb_storage.
1621

0 commit comments

Comments
 (0)