Stroika Library
3.0d23x
Help-Home
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
12
#include "
Stroika/Foundation/Characters/String.h
"
13
#include "Stroika/Foundation/Containers/Mapping.h"
14
#include "Stroika/Foundation/Containers/Sequence.h"
15
#include "
Stroika/Foundation/DataExchange/Variant/JSON/Reader.h
"
16
#include "
Stroika/Foundation/DataExchange/Variant/JSON/Writer.h
"
17
#include "
Stroika/Foundation/DataExchange/VariantValue.h
"
18
#include "
Stroika/Foundation/Database/Document/Collection.h
"
19
#include "
Stroika/Foundation/Database/Document/Connection.h
"
20
#include "
Stroika/Foundation/Database/Document/EngineProperties.h
"
21
#include "
Stroika/Foundation/Database/Document/Transaction.h
"
22
#include "
Stroika/Foundation/Debug/AssertExternallySynchronizedMutex.h
"
23
#include "
Stroika/Foundation/Execution/Synchronized.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
44
namespace
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
{},
86
DataExchange::Variant::JSON::Writer
{}};
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
{},
102
DataExchange::Variant::JSON::Writer
{}};
103
};
104
105
/**
106
*
107
*/
108
variant<MemoryStorage, SingleFileStorage, DirectoryFileStorage> fStorage;
109
};
110
111
/**
112
*/
113
using
Database::Document::Connection::Ptr
;
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_*/
AssertExternallySynchronizedMutex.h
EngineProperties.h
Transaction.h
VariantValue.h
Connection.h
Collection.h
String.h
Synchronized.h
Reader.h
Writer.h
Stroika::Foundation::DataExchange::Variant::JSON::Reader
Definition
Variant/JSON/Reader.h:83
Stroika::Foundation::DataExchange::Variant::JSON::Writer
Definition
Variant/JSON/Writer.h:63
Stroika::Foundation::Database::Document::Connection::Ptr
Definition
Foundation/Database/Document/Connection.h:69
Stroika::Foundation::Execution::InternallySynchronized
InternallySynchronized
Definition
Synchronized.h:54
Stroika::Foundation::Database::Document::LocalDocumentDB::Options::DirectoryFileStorage
Definition
LocalDocumentDB.h:92
Stroika::Foundation::Database::Document::LocalDocumentDB::Options::DirectoryFileStorage::fRoot
filesystem::path fRoot
Definition
LocalDocumentDB.h:96
Stroika::Foundation::Database::Document::LocalDocumentDB::Options::DirectoryFileStorage::fSerialization
tuple< DataExchange::Variant::Reader, DataExchange::Variant::Writer > fSerialization
Definition
LocalDocumentDB.h:101
Stroika::Foundation::Database::Document::LocalDocumentDB::Options::MemoryStorage
Definition
LocalDocumentDB.h:71
Stroika::Foundation::Database::Document::LocalDocumentDB::Options::SingleFileStorage
Definition
LocalDocumentDB.h:76
Stroika::Foundation::Database::Document::LocalDocumentDB::Options::SingleFileStorage::fSerialization
tuple< DataExchange::Variant::Reader, DataExchange::Variant::Writer > fSerialization
Definition
LocalDocumentDB.h:85
Stroika::Foundation::Database::Document::LocalDocumentDB::Options::SingleFileStorage::fFile
filesystem::path fFile
Definition
LocalDocumentDB.h:80
Stroika::Foundation::Database::Document::LocalDocumentDB::Options::fInternallySynchronizedLetter
Execution::InternallySynchronized fInternallySynchronizedLetter
use eInternallySynchronized to make envelope internally synchronized
Definition
LocalDocumentDB.h:66
Library
Sources
Stroika
Foundation
Database
Document
LocalDocumentDB.h
Generated by
1.9.8