Stroika Library 3.0d20
 
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 explicitly 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 want to have todo a lot of needless mapping/translation later. RETHINK!!!
37 */
38 static inline const FieldName kID{Database::Document::kID};
39
40 /**
41 * VariantValue like object, but explicitly 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 * @see Characters::ToString ()
58 */
59 String ToString () const;
60 };
61
62 /**
63 * \todo support a bunch more operators, like Less, and maybe arbitrary function (which obviously runs client side)
64 */
65 using Operation = variant<Equals>;
66
67 /**
68 * Call the .Matches() method of the appropriate variant.
69 */
70 bool Matches (const Operation& op, const Database::Document::Document& doc);
71
72 }
73
74 /**
75 * VERY INCOMPLETE
76 *
77 * But basic idea is conjunctive normal form.
78 *
79 * And elements are the data needed to compute filter value.
80 *
81 * And KEY ones - are ones that can be identified at query time and MAPPED to mongodb query operators, like equal {fieldname, value} - that
82 * would be mapped to a mongo filter, and the remainder computed client side if needed.
83 *
84 */
85 class Filter {
86 public:
87 /**
88 */
90
91 public:
92 /**
93 */
94 nonvirtual bool Matches (const Database::Document::Document& doc) const;
95
96 public:
97 nonvirtual Sequence<FilterElements::Operation> GetConjunctionOperations () const;
98
99 public:
100 /**
101 * @see Characters::ToString ()
102 */
103 nonvirtual String ToString () const;
104
105 private:
106 // todo list of function objects - or operator, arglist, with predefined constant functions for equals, and a few others
107 // hardwired ones can be passed to mongo, and others applied ex-post-facto
108
109 // conjunctive normal form (CNF)
111 };
112
113}
114
115/*
116 ********************************************************************************
117 ***************************** Implementation Details ***************************
118 ********************************************************************************
119 */
120#include "Filter.inl"
121
122#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...