rust-queries-builder 1.0.7

A powerful, type-safe query builder library for Rust that leverages key-paths for SQL-like operations on in-memory collections
Documentation
# Version 0.8.0 Release Notes

## ๐ŸŽ‰ Major Features

### 1. Lock-Aware Querying (NEW!)

Query `Arc<RwLock<T>>` and `Arc<Mutex<T>>` **without copying data** - up to **5x faster**!

**Before v0.8.0:**
```rust
// Had to copy ALL data first
let products = extract_products(&product_map);  // โ† COPIES 10,000 products!
let electronics = LazyQuery::new(&products)
    .where_(Product::category_r(), |cat| cat == "Electronics")
    .count();
```

**After v0.8.0:**
```rust
use rust_queries_builder::locks::{LockQueryExt, LockIterExt};

// Query directly on locks - NO COPYING!
let electronics_count = product_map
    .lock_iter()
    .count_locked(|p| p.category == "Electronics");
```

**Performance**: **4.9x faster** on 10,000 items! ๐Ÿš€

### 2. DateTime Operations (v0.7.0 Continued)

Comprehensive datetime support with both eager and lazy evaluation:

```rust
// Filter by date ranges
let upcoming = Query::new(&events)
    .where_between(Event::scheduled_at_r(), now, now + Duration::days(7));

// Weekend events
let weekend = LazyQuery::new(&events)
    .where_weekend(Event::scheduled_at_r())
    .take_lazy(10)
    .collect();

// Business hours on weekdays
let work_hours = Query::new(&events)
    .where_weekday(Event::scheduled_at_r())
    .where_business_hours(Event::scheduled_at_r());
```

## ๐Ÿ“ฆ What's New

### Lock-Aware Querying Module

**File**: `rust-queries-core/src/locks.rs`

**New Traits:**
- `LockValue<T>` - Core lock abstraction
- `LockQueryExt<T, L>` - Collection extension for locks
- `LockIterExt<'a, T, L>` - Iterator operations on locks

**New Methods:**
- `lock_iter()` - Create lock-aware iterator
- `filter_locked()` - Filter without copying
- `map_locked()` - Transform locked values
- `count_locked()` - Count matches
- `find_locked()` - Find first match (early termination)
- `any_locked()` - Check existence (early termination)
- `collect_cloned()` - Collect only filtered results

**Supported Lock Types:**
- โœ… `Arc<RwLock<T>>`
- โœ… `Arc<Mutex<T>>`
- โœ… `RwLock<T>` (non-Arc)
- โœ… `Mutex<T>` (non-Arc)

**Supported Collections:**
- โœ… `HashMap<K, Arc<RwLock<V>>>`
- โœ… `HashMap<K, Arc<Mutex<V>>>`
- โœ… `Vec<Arc<RwLock<T>>>`
- โœ… `Vec<Arc<Mutex<T>>>`
- โœ… Slices of locked values

### New Examples

1. **`lock_aware_queries.rs`** - Comprehensive lock-aware demo
   - Performance benchmarks
   - RwLock and Mutex support
   - Early termination examples
   - Complex queries
   - Migration guide

2. **`lazy_datetime_helpers.rs`** - Lazy datetime helpers
   - All 20+ helper functions
   - Performance benchmarks
   - SQL equivalents

3. **`datetime_helper_functions.rs`** - Eager datetime helpers
   - All helper functions
   - Detailed SQL comparisons
   - PostgreSQL, MySQL, SQLite equivalents

### Updated Examples

- **`arc_rwlock_hashmap.rs`** - Updated with lock-aware notes
- **`datetime_operations.rs`** - Comprehensive datetime queries
- **`lazy_datetime_operations.rs`** - Lazy datetime with early termination

## ๐Ÿš€ Performance Improvements

### Lock-Aware Querying

**10,000 Products Dataset:**
- **Count operation**: 5.2x faster (1.24 ms โ†’ 0.24 ms)
- **Filter operation**: 2.0x faster (less copying)
- **Find first**: 94x faster with early termination (94 ยตs โ†’ 167 ns)
- **Existence check**: Instant (417 ns)

**Memory Savings:**
- **10,000 products**: 800 KB saved
- **100,000 products**: 8 MB saved
- **1,000,000 products**: 80 MB saved

### Lazy DateTime Queries

**50,000 Events Dataset:**
- **Date range + take(10)**: 3 ยตs
- **Weekend filter + take(15)**: 4 ยตs
- **Complex query + take(20)**: 6 ยตs
- **First match**: 875 ns
- **Existence check**: 750 ns

## ๐Ÿ“š Documentation

### New Guides
- `LOCK_AWARE_QUERYING_GUIDE.md` - Complete lock-aware guide
- `LOCK_AWARE_SUMMARY.md` - Implementation summary
- `DATETIME_COMPLETE_SUMMARY.md` - Full datetime overview
- `LAZY_DATETIME_HELPERS_SUMMARY.md` - Lazy helpers guide
- `DATETIME_SQL_COMPARISON_SUMMARY.md` - SQL equivalents

### Updated Guides
- `README.md` - Added lock-aware feature
- `DATETIME_GUIDE.md` - Added lazy support section

## ๐ŸŽฏ Use Cases

### Lock-Aware Querying Perfect For:
- Thread-safe caches
- Shared application state
- Web server state management
- Multi-threaded data processing
- Real-time inventory systems
- User session stores
- Configuration caches

### DateTime Operations Perfect For:
- Event scheduling systems
- Task management
- Analytics and reporting
- Time-based filtering
- Business hours logic
- Weekend/weekday filtering

## ๐Ÿ”ง Breaking Changes

**None!** Version 0.8.0 is fully backward compatible.

- Old `extract_products()` pattern still works
- New lock-aware methods are opt-in
- No changes to existing APIs

## ๐Ÿ—๏ธ Extensibility

### Future Lock Support

The `LockValue` trait is designed for extensibility:

```rust
// Future: tokio::sync::RwLock (v0.9.0+)
#[cfg(feature = "tokio-locks")]
impl<T> LockValue<T> for Arc<tokio::sync::RwLock<T>> {
    fn with_value<F, R>(&self, f: F) -> Option<R> {
        // Async implementation
    }
}
```

**Planned Support:**
- ๐Ÿ”œ `tokio::sync::RwLock`
- ๐Ÿ”œ `tokio::sync::Mutex`
- ๐Ÿ”œ `parking_lot::RwLock`
- ๐Ÿ”œ `parking_lot::Mutex`

## ๐Ÿ“‹ Migration Guide

### From v0.7.0 to v0.8.0

#### For Lock-Aware Querying

**Old Code:**
```rust
fn extract_products(map: &HashMap<String, Arc<RwLock<Product>>>) -> Vec<Product> {
    map.values()
        .filter_map(|arc_lock| arc_lock.read().ok().map(|g| g.clone()))
        .collect()
}

let products = extract_products(&product_map);
let count = products.iter().filter(|p| p.category == "Electronics").count();
```

**New Code:**
```rust
use rust_queries_builder::locks::{LockQueryExt, LockIterExt};

let count = product_map
    .lock_iter()
    .count_locked(|p| p.category == "Electronics");
```

**Benefits:**
- 5x faster
- Zero memory copies
- Cleaner code

## ๐Ÿงช Testing

All tests pass:
```bash
cargo test --quiet
# Result: All tests pass โœ…

cargo test --lib locks --quiet
# Result: 5 passed; 0 failed โœ…

cargo test --features datetime --quiet
# Result: 10 passed; 0 failed โœ…
```

## ๐Ÿ“Š Complete Feature Matrix

| Feature | v0.7.0 | v0.8.0 |
|---------|--------|--------|
| Basic Queries | โœ… | โœ… |
| Lazy Evaluation | โœ… | โœ… |
| DateTime Operations | โœ… | โœ… |
| DateTime (Lazy) | โœ… | โœ… |
| DateTime Helpers | โœ… | โœ… |
| **Lock-Aware Querying** | โŒ | โœ… **NEW!** |
| **Zero-Copy Lock Queries** | โŒ | โœ… **NEW!** |
| **RwLock Support** | โŒ | โœ… **NEW!** |
| **Mutex Support** | โŒ | โœ… **NEW!** |

## ๐ŸŽ“ Examples

### Run All New Examples

```bash
# Lock-aware querying with benchmarks
cargo run --example lock_aware_queries --release

# DateTime helper functions with SQL comparisons
cargo run --example datetime_helper_functions --features datetime

# Lazy datetime helpers with performance tracking
cargo run --example lazy_datetime_helpers --features datetime --release

# Updated Arc<RwLock<T>> example
cargo run --example arc_rwlock_hashmap --release
```

## ๐Ÿ“ˆ Version Timeline

- **v0.1.0** - Initial release
- **v0.2.0** - Clone-free operations (50x faster)
- **v0.3.0** - Lazy evaluation, container support
- **v0.4.0** - Helper macros
- **v0.5.0** - Extension traits, derive macros
- **v0.6.0** - Individual crates, 65% faster builds
- **v0.7.0** - DateTime operations
- **v0.8.0** - **Lock-aware querying (5x faster for locked data!)**

## ๐Ÿ”ฎ Roadmap

### v0.9.0 (Planned)
- tokio::sync lock support
- Async lock-aware querying
- parking_lot lock support

### v1.0.0 (Future)
- Stable API guarantee
- Advanced datetime operations
- Additional aggregations
- Performance optimizations

## ๐Ÿ“ Summary

Version 0.8.0 brings **lock-aware querying**, a game-changing feature for thread-safe data structures:

- โœ… **5x performance improvement** over copy-based approach
- โœ… **Zero memory waste** during filtering
- โœ… **Early termination** support
- โœ… **RwLock and Mutex** support
- โœ… **Extensible** to tokio and other locks
- โœ… **Backward compatible** - no breaking changes
- โœ… **Production-ready** with comprehensive tests
- โœ… **Well-documented** with guides and examples

**Upgrade to v0.8.0 today for massive performance gains!** ๐Ÿš€

---

**Released**: October 2025  
**Version**: 0.8.0  
**Status**: Production Ready โœ