1#![deny(warnings)]
2
3pub mod find_enrichment_table_records;
4pub mod get_enrichment_table_record;
5pub mod tables;
6
7#[cfg(test)]
8mod test_util;
9mod vrl_util;
10
11use dyn_clone::DynClone;
12pub use tables::{TableRegistry, TableSearch};
13use vrl::compiler::Function;
14use vrl::value::{ObjectMap, Value};
15
16#[derive(Copy, Clone, Debug, PartialEq, Eq)]
17pub struct IndexHandle(pub usize);
18
19#[derive(Clone, Debug, PartialEq, Eq)]
20pub enum Condition<'a> {
21 Equals { field: &'a str, value: Value },
23 BetweenDates {
25 field: &'a str,
26 from: chrono::DateTime<chrono::Utc>,
27 to: chrono::DateTime<chrono::Utc>,
28 },
29 FromDate {
31 field: &'a str,
32 from: chrono::DateTime<chrono::Utc>,
33 },
34 ToDate {
36 field: &'a str,
37 to: chrono::DateTime<chrono::Utc>,
38 },
39}
40
41#[derive(Clone, Copy, Debug, PartialEq, Eq)]
42pub enum Case {
43 Sensitive,
44 Insensitive,
45}
46
47pub trait Table: DynClone {
50 fn find_table_row<'a>(
56 &self,
57 case: Case,
58 condition: &'a [Condition<'a>],
59 select: Option<&[String]>,
60 wildcard: Option<&Value>,
61 index: Option<IndexHandle>,
62 ) -> Result<ObjectMap, String>;
63
64 fn find_table_rows<'a>(
68 &self,
69 case: Case,
70 condition: &'a [Condition<'a>],
71 select: Option<&[String]>,
72 wildcard: Option<&Value>,
73 index: Option<IndexHandle>,
74 ) -> Result<Vec<ObjectMap>, String>;
75
76 fn add_index(&mut self, case: Case, fields: &[&str]) -> Result<IndexHandle, String>;
82
83 fn index_fields(&self) -> Vec<(Case, Vec<String>)>;
85
86 fn needs_reload(&self) -> bool;
88}
89
90dyn_clone::clone_trait_object!(Table);
91
92pub fn vrl_functions() -> Vec<Box<dyn Function>> {
93 vec![
94 Box::new(get_enrichment_table_record::GetEnrichmentTableRecord) as _,
95 Box::new(find_enrichment_table_records::FindEnrichmentTableRecords) as _,
96 ]
97}