Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
Filter.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Database_Document_Filter_h_
5#define _Stroika_Foundation_Database_Document_Filter_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
10#include "Stroika/Foundation/Containers/Sequence.h"
13
14/**
15 * \file
16 *
17 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
18 */
19
20namespace Stroika::Foundation::Database::Document {
21
22 using Containers::Sequence;
23
24 namespace FilterElements {
25
26 /**
27 * String like object, but explciitly different type
28 */
29 struct FieldName : String {
30 using String::String;
31 bool operator== (const FieldName&) const = default;
32 };
33
34 /**
35 * \note this special value kID is used to identify the ID field in a document. Its value is "_id" (in mongodb, but in this API, its "id")
36 * ?????? dont want to hardwire queer choice of mongodb, but dont wnat to have todo alot of needless mapping/translation later. RETHINK!!!
37 */
38 static inline const FieldName kID{Database::Document::kID};
39
40 /**
41 * VariantValue like object, but explciitly different type
42 */
45
46 bool operator== (const Value&) const = default;
47 };
48
49 struct Equals { // equals operator
50 FieldName fLHS;
51 variant<FieldName, Value> fRHS;
52 bool Matches (const Database::Document::Document& doc) const;
53
54 bool operator== (const Equals&) const = default;
55 };
56
57 /**
58 * \todo support a bunch more operators, like Less, and maybe arbitrary function (which obviously runs client side)
59 */
60 using Operation = variant<Equals>;
61
62 /**
63 * Call the .Matches() method of the appropriate variant.
64 */
65 bool Matches (const Operation& op, const Database::Document::Document& doc);
66
67 }
68
69 /**
70 * VERY INCOMPLETE
71 *
72 * But basic idea is conjunctive normal form.
73 *
74 * And elements are the data needed to compute filter value.
75 *
76 * And KEY ones - are ones that can be identified at query time and MAPPED to mongodb query operators, like equal {fieldname, value} - that
77 * would be mapped to a mongo filter, and the remainder computed client side if needed.
78 *
79 */
80 class Filter {
81 public:
82 /**
83 */
84 Filter (const Sequence<FilterElements::Operation>& andedOperations);
85
86 public:
87 /**
88 */
89 nonvirtual bool Matches (const Database::Document::Document& doc) const;
90
91 public:
92 nonvirtual Sequence<FilterElements::Operation> GetConjunctionOperations () const;
93
94 private:
95 // todo list of function objects - or operator, arglist, with predefined constant functions for equals, and a few others
96 // hardwired ones can be passed to mongo, and others applied ex-post-facto
97
98 // conjunctive normal form (CNF)
100 };
101
102}
103
104/*
105 ********************************************************************************
106 ***************************** Implementation Details ***************************
107 ********************************************************************************
108 */
109#include "Filter.inl"
110
111#endif /*_Stroika_Foundation_Database_Document_Filter_h_*/
bool Matches(const Operation &op, const Database::Document::Document &doc)
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
A generalization of a vector: a container whose elements are keyed by the natural numbers.
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
VariantValue()=default
construct a VariantValue from most any 'basic type' you would expect to find in a weakly typed langua...