5#include "Stroika/Foundation/Execution/Activity.h"
8namespace Stroika::Foundation::Database::Document::Collection {
15 inline Ptr::Ptr (
const shared_ptr<IRep>& src)
19 inline Ptr& Ptr::operator= (
const Ptr& src)
21 inherited::operator= (src);
24 inline Ptr& Ptr::operator= (Ptr&& src)
noexcept
26 inherited::operator= (src);
29 inline auto Ptr::operator== (
const Ptr& rhs)
const
31 return get () == rhs.get ();
33 inline bool Ptr::operator== (nullptr_t)
const noexcept
35 return this->get () ==
nullptr;
39 using namespace Characters;
40 return this->get ()->GetName ();
44 using namespace Characters;
45 return Format (
"{}"_f,
static_cast<const void*
> (this->get ()));
49 return this->get ()->Add (v);
51 inline optional<Document> Ptr::Get (
const IDType&
id,
const optional<Projection>& projection)
const
53 using namespace Characters::Literals;
57 return this->get ()->Get (
id, projection);
59 inline optional<Document> Ptr::Get (
const Filter& filter,
const optional<Projection>& projection)
const
61 auto r = this->GetAll (filter, projection);
64 Execution::Throw (kTooManyResultsException_);
71 inline Document Ptr::GetOrThrow (
const IDType&
id,
const optional<Projection>& projection)
const
74 return Memory::ValueOfOrThrow (Get (
id, projection), kExcept_);
76 inline Document Ptr::GetOrThrow (
const Filter& filter,
const optional<Projection>& projection)
const
78 static const auto kExcept_ = Execution::RuntimeErrorException{
"no such document"sv};
79 return Memory::ValueOfOrThrow (Get (filter, projection), kExcept_);
81 inline Sequence<Document> Ptr::GetAll (
const optional<Filter>& filter,
const optional<Projection>& projection)
const
83 using namespace Characters::Literals;
85 [&] () ->
String {
return "getting all matching documents from database collection '{}'"_f(GetName ()); }};
87 return this->get ()->GetAll (filter, projection);
93 return d.LookupChecked (kID, kExcept_).
As<
String> ();
96 inline void Ptr::Replace (
const Document& newV)
const
98 Replace (Memory::ValueOf (newV.
Lookup (kID)).As<
String> (), newV);
100 inline void Ptr::Replace (
const IDType&
id,
const Document& newV)
const
102 using namespace Characters::Literals;
106 this->get ()->Update (
id, newV, nullopt);
108 inline void Ptr::Update (
const Document& newV)
const
114 Update (Memory::ValueOf (newV.
Lookup (kID)).As<
String> (), newV, onlyTheseFields);
116 inline void Ptr::Update (
const IDType&
id,
const Document& newV)
const
118 using namespace Characters::Literals;
122 this->get ()->Update (
id, newV, Set<String>{newV.
Keys ()});
124 inline void Ptr::Update (
const IDType&
id,
const Document& newV,
const Set<String>& onlyTheseFields)
const
126 using namespace Characters::Literals;
127 auto activity = Execution::LazyEvalActivity{[&] () -> String {
return "updating document in database collection {}"_f(GetName ()); }};
128 Execution::DeclareActivity da{&activity};
129 this->get ()->Update (
id, newV, onlyTheseFields);
131 inline void Ptr::Remove (
const IDType&
id)
const
133 using namespace Characters::Literals;
137 this->get ()->Remove (
id);
141 if (
auto oid = v.
Lookup (kID)) {
142 if (Get (oid->As<
String> ())) {
144 return oid->As<
String> ();
Mapping< String, VariantValue > Document
String is like std::u32string, except it is much easier to use, often much more space efficient,...
nonvirtual optional< mapped_type > Lookup(ArgByValueType< key_type > key) const
nonvirtual Iterable< key_type > Keys() const
A generalization of a vector: a container whose elements are keyed by the natural numbers.
nonvirtual RESULT_CONTAINER Map(ELEMENT_MAPPER &&elementMapper) const
'override' Iterable<>::Map () function so RESULT_CONTAINER defaults to Sequence, and improve that cas...
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.