Oyelowo / oyestack

Foundation for highly scalable distributed web application with `Rustlang` for apps, `Typescript` and Kubernetes for Infra
https://codebreather.com
Apache License 2.0
0 stars 0 forks source link

524 surreal orm implement cond macro for idiomatic expressive conditional #525

Closed Oyelowo closed 1 year ago

Oyelowo commented 1 year ago

Purposes

    #[test]
    fn test_filter_bracketed_with_cond_macro_nested() {
        let age = Field::new("age");
        let title = Field::new("title");

        let filter = cond!((age OR cond!(age >= 18)) OR (title = "Professor") AND (age < 100));

        let bracketed_filter = filter.bracketed();
        assert_eq!(
            bracketed_filter.to_raw().build(),
            "((age OR age >= 18) OR (title = 'Professor') AND (age < 100))"
        );
    }

    #[test]
    fn test_filter_bracketed_with_cond_macro_mixed() {
        let age = Field::new("age");
        let title = Field::new("title");

        let filter = cond!((age.or(4).or(545).or(232)) OR (title = "Professor") AND (age < 100));

        let bracketed_filter = filter.bracketed();
        assert_eq!(
            bracketed_filter.fine_tune_params(),
            "((age OR $_param_00000001 OR $_param_00000002 OR $_param_00000003) OR (title = $_param_00000004) AND (age < $_param_00000005))"
        );

        assert_eq!(
            bracketed_filter.to_raw().build(),
            "((age OR 4 OR 545 OR 232) OR (title = 'Professor') AND (age < 100))"
        );
    }