#![deny(warnings)]
pub mod find_enrichment_table_records;
pub mod get_enrichment_table_record;
pub mod tables;
#[cfg(test)]
mod test_util;
mod vrl_util;
use dyn_clone::DynClone;
pub use tables::{TableRegistry, TableSearch};
use vrl::compiler::Function;
use vrl::value::{ObjectMap, Value};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct IndexHandle(pub usize);
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Condition<'a> {
Equals { field: &'a str, value: Value },
BetweenDates {
field: &'a str,
from: chrono::DateTime<chrono::Utc>,
to: chrono::DateTime<chrono::Utc>,
},
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Case {
Sensitive,
Insensitive,
}
pub trait Table: DynClone {
fn find_table_row<'a>(
&self,
case: Case,
condition: &'a [Condition<'a>],
select: Option<&[String]>,
index: Option<IndexHandle>,
) -> Result<ObjectMap, String>;
fn find_table_rows<'a>(
&self,
case: Case,
condition: &'a [Condition<'a>],
select: Option<&[String]>,
index: Option<IndexHandle>,
) -> Result<Vec<ObjectMap>, String>;
fn add_index(&mut self, case: Case, fields: &[&str]) -> Result<IndexHandle, String>;
fn index_fields(&self) -> Vec<(Case, Vec<String>)>;
fn needs_reload(&self) -> bool;
}
dyn_clone::clone_trait_object!(Table);
pub fn vrl_functions() -> Vec<Box<dyn Function>> {
vec![
Box::new(get_enrichment_table_record::GetEnrichmentTableRecord) as _,
Box::new(find_enrichment_table_records::FindEnrichmentTableRecords) as _,
]
}