Rust

operator

Module

[Operator]: atomic update operators against the attributes they update.

Contents

use utopia_database::Operator;
Rust
pub struct Operator

An operator valid for the attribute it updates: an existing attribute of a type the method applies to (numbers for arithmetic, arrays or many-side relationships for array methods, strings, booleans, dates), with well-formed values; with the current document, an integer result within 32-bit range, a string result within the attribute's size, and an insert index within the array.

Rust
use utopia_database::Document;
use utopia_database::operator::{Operator, OperatorMethod};
use utopia_database::validator::operator::Operator as OperatorValidator;
use utopia_database::value::{Value, list, string};

let count = Document::from_pairs([("$id", string("count")), ("key", string("count")), ("type", string("integer"))]).unwrap();
let collection = Document::from_pairs([("$id", string("c")), ("attributes", list([count.into()]))]).unwrap();
let validator = OperatorValidator::new(&collection, None);
assert!(validator.check(&Operator::new(OperatorMethod::Increment, "count", vec![Value::Int(1)])).unwrap());
assert!(!validator.check(&Operator::new(OperatorMethod::Toggle, "count", vec![])).unwrap());
assert_eq!(validator.description(), "Cannot apply toggle operator to non-boolean field 'count'");
Rust
pub const ARRAY_FILTER_CONDITIONS: [&str; 8] = ["equal", "notEqual", "greaterThan", "greaterThanEqual", "lessThan", "lessThanEqual", "isNull", "isNotNull"]

Operator::ARRAY_FILTER_CONDITIONS: the conditions of arrayFilter.

Rust
pub const MAX_ARRAY_OPERATOR_SIZE: usize = 10000

Operator::MAX_ARRAY_OPERATOR_SIZE: the most items an array operator may carry.