Stroika Library
3.0d20
Help-Home
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
12
#include "
Stroika/Foundation/Characters/String.h
"
13
#include "Stroika/Foundation/Common/Property.h"
14
#include "Stroika/Foundation/Containers/Mapping.h"
15
#include "Stroika/Foundation/Containers/Sequence.h"
16
#include "
Stroika/Foundation/DataExchange/Variant/JSON/Reader.h
"
17
#include "
Stroika/Foundation/DataExchange/Variant/JSON/Writer.h
"
18
#include "
Stroika/Foundation/DataExchange/VariantValue.h
"
19
#include "
Stroika/Foundation/Database/Document/Collection.h
"
20
#include "
Stroika/Foundation/Database/Document/Connection.h
"
21
#include "
Stroika/Foundation/Database/Document/EngineProperties.h
"
22
#include "
Stroika/Foundation/Database/Document/Transaction.h
"
23
#include "
Stroika/Foundation/Debug/AssertExternallySynchronizedMutex.h
"
24
#include "
Stroika/Foundation/IO/Network/URI.h
"
25
#include "
Stroika/Foundation/Time/Duration.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
47
namespace
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
* \note NYI, but easy to add
75
*/
76
struct
FilesystemStorage
final {
77
/**
78
*
79
*/
80
filesystem::path fRoot;
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
*
91
*/
92
variant<MemoryStorage, FilesystemStorage> fStorage;
93
};
94
95
/**
96
* @brief &&&REWRITE
97
*
98
* Connection provides an API for accessing an SQLite database.
99
*
100
* A new Connection::Ptr is typically created SQLite::Connection::New()
101
*
102
* \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>
103
* But though each connection can only be accessed from a single thread at a time, the underlying database may be
104
* threadsafe (even if accessed across processes) - depending on its construction Options::ThreadSafety
105
*
106
* The Connection itself is standardC++ thread safety. The thread-safety of the underlying database depends on the setting
107
* of Options::fThreadingMode when the database is constructed.
108
*
109
* @see https://www.sqlite.org/threadsafe.html
110
* We set SQLITE_OPEN_NOMUTEX on open (so mode Multi-thread, but not Serialized).
111
*
112
* NOTE - two Connection::Ptr objects referring to the same underlying REP is NOT (probably) safe with SQLITE. But referring
113
* to the same database is safe.
114
*
115
*/
116
using
Database::Document::Connection::Ptr
;
117
118
/**
119
* \brief create an TrivialDocumentDB database (and connection) object, guided by argument Options.
120
*/
121
Ptr New (
const
Options& options);
122
123
}
124
125
/*
126
********************************************************************************
127
***************************** Implementation Details ***************************
128
********************************************************************************
129
*/
130
#include "TrivialDocumentDB.inl"
131
132
#endif
/*_Stroika_Foundation_Database_Document_TrivialDocumentDB_h_*/
AssertExternallySynchronizedMutex.h
EngineProperties.h
Transaction.h
Duration.h
VariantValue.h
Connection.h
Collection.h
String.h
URI.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:51
Stroika::Foundation::Database::Document::TrivialDocumentDB::Options::FilesystemStorage
Definition
TrivialDocumentDB.h:76
Stroika::Foundation::Database::Document::TrivialDocumentDB::Options::FilesystemStorage::fSerialization
tuple< DataExchange::Variant::Reader, DataExchange::Variant::Writer > fSerialization
Definition
TrivialDocumentDB.h:85
Stroika::Foundation::Database::Document::TrivialDocumentDB::Options::MemoryStorage
Definition
TrivialDocumentDB.h:70
Stroika::Foundation::Database::Document::TrivialDocumentDB::Options
Definition
TrivialDocumentDB.h:65
Library
Sources
Stroika
Foundation
Database
Document
TrivialDocumentDB.h
Generated by
1.9.8