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::{
14 compiler::Function,
15 value::{ObjectMap, Value},
16};
17
18#[derive(Copy, Clone, Debug, PartialEq, Eq)]
19pub struct IndexHandle(pub usize);
20
21#[derive(Clone, Debug, PartialEq, Eq)]
22pub enum Condition<'a> {
23 Equals { field: &'a str, value: Value },
25 BetweenDates {
27 field: &'a str,
28 from: chrono::DateTime<chrono::Utc>,
29 to: chrono::DateTime<chrono::Utc>,
30 },
31 FromDate {
33 field: &'a str,
34 from: chrono::DateTime<chrono::Utc>,
35 },
36 ToDate {
38 field: &'a str,
39 to: chrono::DateTime<chrono::Utc>,
40 },
41}
42
43#[derive(Clone, Copy, Debug, PartialEq, Eq)]
44pub enum Case {
45 Sensitive,
46 Insensitive,
47}
48
49pub trait Table: DynClone {
52 fn find_table_row<'a>(
58 &self,
59 case: Case,
60 condition: &'a [Condition<'a>],
61 select: Option<&[String]>,
62 wildcard: Option<&Value>,
63 index: Option<IndexHandle>,
64 ) -> Result<ObjectMap, String>;
65
66 fn find_table_rows<'a>(
70 &self,
71 case: Case,
72 condition: &'a [Condition<'a>],
73 select: Option<&[String]>,
74 wildcard: Option<&Value>,
75 index: Option<IndexHandle>,
76 ) -> Result<Vec<ObjectMap>, String>;
77
78 fn add_index(&mut self, case: Case, fields: &[&str]) -> Result<IndexHandle, String>;
84
85 fn index_fields(&self) -> Vec<(Case, Vec<String>)>;
87
88 fn needs_reload(&self) -> bool;
90}
91
92dyn_clone::clone_trait_object!(Table);
93
94pub fn vrl_functions() -> Vec<Box<dyn Function>> {
95 vec![
96 Box::new(get_enrichment_table_record::GetEnrichmentTableRecord) as _,
97 Box::new(find_enrichment_table_records::FindEnrichmentTableRecords) as _,
98 ]
99}