Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
Foundation/Database/Document/Connection.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_Connection_h_
5#define _Stroika_Foundation_Database_Document_Connection_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <optional>
10
12#include "Stroika/Foundation/Containers/Set.h"
15
16/**
17 * \file
18 *
19 * The point of this module is to define a Connection abstraction that can be used for different kinds
20 * of connections (e.g. SQLite local database object, and mongoDB remote database object). This generic API
21 * can then be used in places where either backend database might be in use.
22 *
23 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
24 */
25
26namespace Stroika::Foundation::Database::Document {
27
28 using Characters::String;
29 using Containers::Set;
30
31 class Transaction;
32 class EngineProperties;
33
34}
35namespace Stroika::Foundation::Database::Document::Connection {
36
37 class IRep;
38
39 /**
40 * Connection::Ptr provides an API for accessing a document database.
41 *
42 * A new Connection::Ptr is typically created with SOME_SERVICE::Connection::New () (e.g. SQLite::Connection::New() or MongoDBClient::Connection::New ())
43 *
44 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety-For-Envelope-But-Ambiguous-Thread-Safety-For-Letter">C++-Standard-Thread-Safety-For-Envelope-But-Ambiguous-Thread-Safety-For-Letter/a>
45 * But though each connection can only be accessed from a single thread at a time, the underlying database may be
46 * threadsafe (even if accessed across processes).
47 *
48 * The Connection::Ptr itself is standardC++ thread safety. The thread-safety of the underlying database depends on how the underlying
49 * shared_ptr<IRep> was created.
50 */
51 class Ptr : public shared_ptr<IRep> {
52 private:
53 using inherited = shared_ptr<IRep>;
54
55 public:
56 /**
57 */
58 Ptr (const Ptr& src) = default;
59 Ptr (Ptr&& src) noexcept = default;
60 using inherited::inherited;
61
62 public:
63 ~Ptr () = default;
64
65 public:
66 /**
67 */
68 nonvirtual Ptr& operator= (const Ptr& src) = default;
69 nonvirtual Ptr& operator= (Ptr&& src) noexcept = default;
70
71 public:
72 /**
73 */
74 nonvirtual Set<String> GetCollections ();
75
76 public:
77 /**
78 * Creates the (named) collection (aka table), and does nothing if the table/collection already exists.
79 */
80 nonvirtual void CreateCollection (const String& name);
81
82 public:
83 /**
84 */
85 nonvirtual void DropCollection (const String& name);
86
87 public:
88 /**
89 */
90 nonvirtual Collection::Ptr GetCollection (const String& name);
91
92 public:
93 /**
94 * Transaction object factory
95 *
96 * The reason you might use this instead of SQLite::Transaction{} - is in writing generic code
97 * that doesn't depend on the particular kind of SQL database you are connected to (e.g. that
98 * might be used for ODBC or SQLite).
99 */
100 nonvirtual Transaction mkTransaction ();
101
102 public:
103 /**
104 * @see Characters::ToString ()
105 */
106 nonvirtual String ToString () const;
107
108 public:
109 nonvirtual bool operator== (const Ptr& rhs) const noexcept;
110 nonvirtual bool operator== (nullptr_t) const noexcept;
111
112 protected:
113 [[no_unique_address]] Debug::AssertExternallySynchronizedMutex _fAssertExternallySynchronizedMutex;
114 };
115
116 /**
117 * Connection::IRep provides an (abstract) API for accessing a Document database.
118 *
119 * \note \em Thread-Safety <a href="Thread-Safety.md#Thread-Safety-Rules-Depends-On-Subtype">Thread-Safety-Rules-Depends-On-Subtype</a>
120 */
121 class IRep : public enable_shared_from_this<IRep> {
122 public:
123 /**
124 */
125 virtual ~IRep () = default;
126
127 public:
128 /**
129 */
130 virtual shared_ptr<const EngineProperties> GetEngineProperties () const = 0;
131
132 public:
133 /**
134 */
135 virtual Set<String> GetCollections () = 0;
136
137 public:
138 /**
139 * Creates the (named) collection (aka table), and does nothing if the table/collection already exists.
140 */
141 virtual void CreateCollection (const String& name) = 0;
142
143 public:
144 /**
145 */
146 virtual void DropCollection (const String& name) = 0;
147
148 public:
149 /**
150 */
151 virtual Collection::Ptr GetCollection (const String& name) = 0;
152
153 public:
154 /**
155 * Transaction object factory
156 */
158 };
159
160}
161
162/*
163 ********************************************************************************
164 ***************************** Implementation Details ***************************
165 ********************************************************************************
166 */
167#include "Connection.inl"
168
169#endif /*_Stroika_Foundation_Database_Document_Connection_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
virtual void CreateCollection(const String &name)=0
NOT a real mutex - just a debugging infrastructure support tool so in debug builds can be assured thr...