1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Query Builder API for type-safe programmatic query construction
//!
//! This module provides a fluent builder API for constructing queries programmatically
//! without parsing string queries. It offers compile-time safety for field names and
//! operators, with runtime validation against the [`FieldRegistry`](crate::query::FieldRegistry).
//!
//! # Features
//!
//! - **Type-safe construction**: Methods for all core fields prevent typos
//! - **Fluent API**: Method chaining for readable query construction
//! - **Validation**: Field, operator, value type, and enum constraint validation
//! - **Error accumulation**: All errors reported at `build()` time, not per-method
//! - **Zero-copy optimization**: Uses `Cow<'static, str>` for static field names
//!
//! # Example
//!
//! ```ignore
//! use sqry_core::query::builder::QueryBuilder;
//!
//! // Simple condition
//! let query = QueryBuilder::kind("function")
//! .build()?;
//!
//! // Combined conditions
//! let query = QueryBuilder::kind("function")
//! .and(QueryBuilder::lang("rust"))
//! .and_not(QueryBuilder::name_matches("test.*"))
//! .build()?;
//!
//! // OR conditions using static constructor
//! let query = QueryBuilder::any(vec![
//! QueryBuilder::kind("function"),
//! QueryBuilder::kind("method"),
//! ])
//! .and(QueryBuilder::lang("rust"))
//! .build()?;
//!
//! // Regex with custom flags
//! let query = QueryBuilder::name_matches_with("Test.*", |rb| rb.case_insensitive())
//! .build()?;
//! ```
//!
//! # Architecture
//!
//! The builder is a thin layer over the existing Query AST types. It provides:
//!
//! 1. **Type-safe construction** of [`Expr`](crate::query::Expr) nodes
//! 2. **Validation** against [`FieldRegistry`](crate::query::FieldRegistry)
//! 3. **Conversion** to executable [`QueryAST`](crate::query::QueryAST) structures
//!
//! # Validation
//!
//! Validation is performed lazily at `build()` time:
//!
//! - Field existence (with alias resolution)
//! - Operator compatibility with field type
//! - Value type matching
//! - Enum value validation (for `kind`, `scope`, `scope.type`)
//! - Regex pattern syntax validation
pub use ConditionBuilder;
pub use BuildError;
pub use QueryBuilder;
pub use RegexBuilder;