Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
TrivialDocumentDB.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_TrivialDocumentDB_h_
5#define _Stroika_Foundation_Database_Document_TrivialDocumentDB_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <filesystem>
10#include <optional>
11
13#include "Stroika/Foundation/Common/Property.h"
14#include "Stroika/Foundation/Containers/Mapping.h"
15#include "Stroika/Foundation/Containers/Sequence.h"
26
27/**
28 * \file
29 *
30 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
31 *
32 * TrivialDocumentDB is a (typically filesystem, but can be RAM based) trivial implementation of the DocumentDB
33 * API. You can use this to debug/test, and possibly for limited, or embedded, small scale uses.
34 *
35 * Advantages:
36 * - Small, simple, easy to review code, and understand API
37 * - Very small dependency footprint
38 * - Lets you pick data format to store (when storing to disk), JSON, or BSON, or whatever you have
39 * serializers/de-serializers for.
40 *
41 * Disadvantages
42 * - Performance on larger scale
43 * - Transactions NYI
44 * - Filesystem storage NYI (as of 3.0d18) - BUT when needed - easy
45 */
46
47namespace Stroika::Foundation::Database::Document::TrivialDocumentDB {
48
49 using Characters::String;
50 using Containers::Mapping;
51 using Containers::Sequence;
52 using DataExchange::VariantValue;
53 using IO::Network::URI;
54 using Time::Duration;
55
56 using namespace Database::Document::Connection;
57
58 using Database::Document::Connection::IRep;
59
60 /**
61 * These are options used to create a database Connection::Ptr object (with Connection::New).
62 *
63 * Since this is also how you create a database, in a sense, its those options too.
64 */
65 struct Options final {
66
67 /**
68 * @todo add options like max ram, max # objects?
69 */
70 struct MemoryStorage final {};
71
72 /**
73 * add options like caching (support external process sync/flock)
74 */
75 struct FilesystemStorage final {
76 /**
77 *
78 */
79 filesystem::path fRoot;
80
81 /**
82 * Extension point so we can switch to writing files as BSON, msgpack, or some such...
83 */
84 tuple<DataExchange::Variant::Reader, DataExchange::Variant::Writer> fSerialization{DataExchange::Variant::JSON::Reader{},
86 };
87
88 /**
89 *
90 */
91 variant<MemoryStorage, FilesystemStorage> fStorage;
92 };
93
94 /**
95 * @brief &&&REWRITE
96 *
97 * Connection provides an API for accessing an SQLite database.
98 *
99 * A new Connection::Ptr is typically created SQLite::Connection::New()
100 *
101 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety-For-Envelope-Plus-Must-Externally-Synchronize-Letter">C++-Standard-Thread-Safety-For-Envelope-Plus-Must-Externally-Synchronize-Letter</a>
102 * But though each connection can only be accessed from a single thread at a time, the underlying database may be
103 * threadsafe (even if accessed across processes) - depending on its construction Options::ThreadSafety
104 *
105 * The Connection itself is standardC++ thread safety. The thread-safety of the underlying database depends on the setting
106 * of Options::fThreadingMode when the database is constructed.
107 *
108 * @see https://www.sqlite.org/threadsafe.html
109 * We set SQLITE_OPEN_NOMUTEX on open (so mode Multi-thread, but not Serialized).
110 *
111 * NOTE - two Connection::Ptr objects referring to the same underlying REP is NOT (probably) safe with SQLITE. But referring
112 * to the same database is safe.
113 *
114 */
116
117 /**
118 * \brief create an TrivialDocumentDB database (and connection) object, guided by argument Options.
119 */
120 Ptr New (const Options& options);
121
122}
123
124/*
125 ********************************************************************************
126 ***************************** Implementation Details ***************************
127 ********************************************************************************
128 */
129#include "TrivialDocumentDB.inl"
130
131#endif /*_Stroika_Foundation_Database_Document_TrivialDocumentDB_h_*/
tuple< DataExchange::Variant::Reader, DataExchange::Variant::Writer > fSerialization