pub struct Tql { /* private fields */ }Expand description
Main TQL query interface
Provides a high-level API for parsing and executing TQL queries against JSON data.
§Examples
use tql::Tql;
use serde_json::json;
let tql = Tql::new();
let records = vec![
json!({"name": "Alice", "age": 30}),
json!({"name": "Bob", "age": 25}),
];
let results = tql.query(&records, "age > 25").unwrap();
assert_eq!(results.len(), 1);Implementations§
Source§impl Tql
impl Tql
Sourcepub fn with_max_depth(max_depth: usize) -> Self
pub fn with_max_depth(max_depth: usize) -> Self
Create a new TQL instance with custom parser depth limit
Sourcepub fn query<'a>(
&self,
records: &'a [JsonValue],
query: &str,
) -> Result<Vec<&'a JsonValue>>
pub fn query<'a>( &self, records: &'a [JsonValue], query: &str, ) -> Result<Vec<&'a JsonValue>>
Execute a TQL query against a list of records
§Arguments
records- A slice of JSON values to query againstquery- The TQL query string
§Returns
A vector of references to matching records
§Examples
use tql::Tql;
use serde_json::json;
let tql = Tql::new();
let records = vec![
json!({"name": "Alice", "age": 30}),
json!({"name": "Bob", "age": 20}),
];
let results = tql.query(&records, "age >= 25").unwrap();
assert_eq!(results.len(), 1);Sourcepub fn parse(&self, query: &str) -> Result<AstNode>
pub fn parse(&self, query: &str) -> Result<AstNode>
Parse a TQL query into an AST without executing it
Useful for pre-compiling queries or validating syntax
Sourcepub fn is_stats_query(&self, query: &str) -> Result<bool>
pub fn is_stats_query(&self, query: &str) -> Result<bool>
Sourcepub fn evaluate_stats(
&self,
records: &[JsonValue],
query: &str,
) -> Result<JsonValue>
pub fn evaluate_stats( &self, records: &[JsonValue], query: &str, ) -> Result<JsonValue>
Execute a stats query against a list of records
§Arguments
records- A slice of JSON values to aggregatequery- The TQL query string containing stats expression
§Returns
Aggregated results as a JSON value
§Examples
ⓘ
use tql::Tql;
use serde_json::json;
let tql = Tql::new();
let records = vec![
json!({"name": "Alice", "status": "active"}),
json!({"name": "Bob", "status": "active"}),
json!({"name": "Charlie", "status": "inactive"}),
];
let results = tql.evaluate_stats(&records, "| stats count() by status").unwrap();Trait Implementations§
Auto Trait Implementations§
impl Freeze for Tql
impl RefUnwindSafe for Tql
impl Send for Tql
impl Sync for Tql
impl Unpin for Tql
impl UnwindSafe for Tql
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more