Stroika Library 3.0d23x
 
Loading...
Searching...
No Matches
LocalDocumentDB.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Database_Document_LocalDocumentDB_h_
5#define _Stroika_Foundation_Database_Document_LocalDocumentDB_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <filesystem>
10#include <optional>
11
13#include "Stroika/Foundation/Containers/Mapping.h"
14#include "Stroika/Foundation/Containers/Sequence.h"
24
25/**
26 * \file
27 *
28 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
29 *
30 * LocalDocumentDB is a (typically filesystem, but can be RAM based) simple implementation of the DocumentDB
31 * API. You can use this to debug/test, and possibly for limited, or embedded, small scale uses.
32 *
33 * Advantages:
34 * - Small, simple, easy to review code, and understand API
35 * - Very small dependency footprint
36 * - Lets you pick data format to store (when storing to disk), JSON, or BSON, or whatever you have
37 * serializers/de-serializers for.
38 *
39 * Disadvantages
40 * - Performance on larger scale
41 * - Transactions NYI
42 */
43
44namespace Stroika::Foundation::Database::Document::LocalDocumentDB {
45
46 using namespace Database::Document::Connection;
47
48 using Database::Document::Connection::IRep;
49
50 /**
51 * These are options used to create a database Connection::Ptr object (with Connection::New).
52 *
53 * Since this is also how you create a database, in a sense, its those options too.
54 */
55 struct Options final : Database::Document::Connection::Options {
56
57 /**
58 * \brief use eInternallySynchronized to make envelope internally synchronized
59 *
60 * \note - as of 2026-01-28, all the implementations are actually eInternallySynchronized, but
61 * easy to fix so they are not (so they will be more performant in that case).
62 *
63 * \note this refers to in-process syncrhonization. Future flags/fields/options will be needed
64 * in other impls to assure cross-process syncrhonization (not sure if even appropriate for this impl but maybe something simple with flock).
65 */
66 Execution::InternallySynchronized fInternallySynchronizedLetter{Execution::eNotKnownInternallySynchronized};
67
68 /**
69 * @todo add options like max ram, max # objects?
70 */
71 struct MemoryStorage final {};
72
73 /**
74 * @todo add options like caching (support external process sync/flock)
75 */
76 struct SingleFileStorage final {
77 /**
78 * Where the file is stored.
79 */
80 filesystem::path fFile;
81
82 /**
83 * Extension point so we can switch to writing files as BSON, msgpack, or some such...
84 */
85 tuple<DataExchange::Variant::Reader, DataExchange::Variant::Writer> fSerialization{DataExchange::Variant::JSON::Reader{},
87 };
88
89 /**
90 * @todo add options like caching (support external process sync/flock)
91 */
92 struct DirectoryFileStorage final {
93 /**
94 * The directory where the files are stored.
95 */
96 filesystem::path fRoot;
97
98 /**
99 * Extension point so we can switch to writing files as BSON, msgpack, or some such...
100 */
101 tuple<DataExchange::Variant::Reader, DataExchange::Variant::Writer> fSerialization{DataExchange::Variant::JSON::Reader{},
103 };
104
105 /**
106 *
107 */
108 variant<MemoryStorage, SingleFileStorage, DirectoryFileStorage> fStorage;
109 };
110
111 /**
112 */
114
115 /**
116 * \brief create an LocalDocumentDB database (and connection) object, guided by argument Options.
117 *
118 * \note
119 *
120 * \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>
121 * the internal synchronization of the resulting letter object is controlled by Options::fInternallySynchronizedLetter
122 *
123 */
124 Ptr New (const Options& options);
125
126}
127
128/*
129 ********************************************************************************
130 ***************************** Implementation Details ***************************
131 ********************************************************************************
132 */
133#include "LocalDocumentDB.inl"
134
135#endif /*_Stroika_Foundation_Database_Document_LocalDocumentDB_h_*/
tuple< DataExchange::Variant::Reader, DataExchange::Variant::Writer > fSerialization
tuple< DataExchange::Variant::Reader, DataExchange::Variant::Writer > fSerialization
Execution::InternallySynchronized fInternallySynchronizedLetter
use eInternallySynchronized to make envelope internally synchronized