Tql

Struct Tql 

Source
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

Source

pub fn new() -> Self

Create a new TQL instance with default settings

Source

pub fn with_max_depth(max_depth: usize) -> Self

Create a new TQL instance with custom parser depth limit

Source

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 against
  • query - 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);
Source

pub fn query_enriched( &self, records: &[JsonValue], query: &str, ) -> Result<Vec<JsonValue>>

Execute a TQL query with enrichment (applies field mutators to results)

§Arguments
  • records - A slice of JSON values to query against
  • query - The TQL query string
§Returns

A vector of owned records with mutators applied

Source

pub fn count(&self, records: &[JsonValue], query: &str) -> Result<usize>

Count the number of records matching a query

§Arguments
  • records - A slice of JSON values to query against
  • query - The TQL query string
§Returns

The number of matching records

Source

pub fn matches(&self, record: &JsonValue, query: &str) -> Result<bool>

Evaluate a query against a single record

§Arguments
  • record - A JSON value to evaluate against
  • query - The TQL query string
§Returns

true if the record matches the query, false otherwise

Source

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

Source

pub fn is_stats_query(&self, query: &str) -> Result<bool>

Check if a query contains stats expressions

§Arguments
  • query - The TQL query string
§Returns

true if the query contains stats aggregations

Source

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 aggregate
  • query - 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§

Source§

impl Default for Tql

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,