Moved Query into separate actions.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s

This commit is contained in:
2026-02-06 12:06:51 -05:00
parent 7f7e10a373
commit 5ffb79b7f2
12 changed files with 164 additions and 105 deletions

View File

@@ -1,8 +1,10 @@
use crate::{
action::Query,
document::definition::DocDef,
message::wrapper::{Addition, Delete, Query, Records, Reply, Update},
message::wrapper::{Addition, Delete, Records, Reply, Update},
mtterror::MTTError,
queue::data_director::Register,
UserAction,
};
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
@@ -123,6 +125,15 @@ impl From<Update> for MsgAction {
}
}
impl From<UserAction> for MsgAction {
fn from(value: UserAction) -> Self {
match value {
UserAction::CreateDocument(data) => Self::Create(data),
UserAction::Query(data) => Self::Query(data),
}
}
}
#[cfg(test)]
mod msgactions {
use super::*;

View File

@@ -1,4 +1,5 @@
use crate::{
action::Query,
document::field::{Field, FieldType},
message::action::MsgAction,
mtterror::MTTError,
@@ -1008,84 +1009,6 @@ impl From<HashSet<Oid>> for QueryType {
}
}
#[derive(Clone, Debug)]
pub struct Query {
data: HashMap<NameType, Calculation>,
}
impl Query {
pub fn new() -> Self {
Self {
data: HashMap::new(),
}
}
pub fn add<NT>(&mut self, name: NT, operation: Calculation)
where
NT: Into<NameType>,
{
self.data.insert(name.into(), operation);
}
#[allow(dead_code)]
fn get<NT>(&self, name: NT) -> Option<Calculation>
where
NT: Into<NameType>,
{
match self.data.get(&name.into()) {
Some(calc) => Some(calc.clone()),
None => None,
}
}
#[allow(dead_code)]
fn field_ids(&self) -> HashSet<&NameType> {
self.data.keys().collect()
}
pub fn iter(&self) -> impl Iterator<Item = (&NameType, &Calculation)> {
self.data.iter()
}
}
#[cfg(test)]
mod queries {
use super::*;
use crate::name::Name;
#[test]
fn holds_calculation_to_run_query() {
let name = Name::english(Uuid::new_v4().to_string().as_str());
let data = Uuid::new_v4();
let mut bad_data = data.clone();
while bad_data == data {
bad_data = Uuid::new_v4();
}
let mut query = Query::new();
let mut calc = Calculation::new(Operand::Equal);
calc.add_value(data.clone()).unwrap();
query.add(name.clone(), calc);
match query.get(&name) {
Some(op) => {
let expected: Field = true.into();
let mut holder = op.clone();
holder.add_value(data).unwrap();
assert_eq!(holder.calculate(&Field::None), expected);
}
None => unreachable!("should have returned a calculation"),
}
match query.get(&name) {
Some(op) => {
let expected: Field = false.into();
let mut holder = op.clone();
holder.add_value(bad_data).unwrap();
assert_eq!(holder.calculate(&Field::None), expected);
}
None => unreachable!("should have returned a calculation"),
}
}
}
#[allow(dead_code)]
#[derive(Clone, Debug)]
pub struct Reply {