4#ifndef _Stroika_Foundation_Database_SQL_SQLite_h_
5#define _Stroika_Foundation_Database_SQL_SQLite_h_ 1
7#include "Stroika/Foundation/StroikaPreComp.h"
12#if qStroika_HasComponent_sqlite
13#include <sqlite/sqlite3.h>
17#include "Stroika/Foundation/Common/Property.h"
18#include "Stroika/Foundation/Containers/Mapping.h"
19#include "Stroika/Foundation/Containers/Sequence.h"
38namespace Stroika::Foundation::Database::SQL::SQLite {
40 using Characters::String;
41 using Containers::Mapping;
42 using Containers::Sequence;
43 using DataExchange::VariantValue;
44 using IO::Network::URI;
47#if qStroika_HasComponent_sqlite
65 class CompiledOptions final {
70 bool ENABLE_NORMALIZE;
85 static const CompiledOptions kThe;
96 enum JournalModeType {
111 namespace Connection {
113 using namespace SQL::Connection;
122 struct Options final {
131 optional<filesystem::path> fDBPath;
137 bool fCreateDBPathIfDoesNotExist{
true};
145 optional<String> fTemporaryDB;
156 optional<String> fInMemoryDB;
164 enum class ThreadingMode {
196 optional<ThreadingMode> fThreadingMode;
202 static inline constexpr auto kDefault_ThreadingMode = ThreadingMode::eMultiThread;
208 optional<String> fVFS;
213 bool fReadOnly{
false};
221 bool fImmutable{
false};
234 optional<Duration> fBusyTimeout;
239 optional<JournalModeType> fJournalMode;
261 class Ptr :
public SQL::Connection::Ptr {
263 using inherited = SQL::Connection::Ptr;
268 Ptr (
const Ptr& src);
269 Ptr (
const shared_ptr<IRep>& src =
nullptr);
277 nonvirtual Ptr& operator= (
const Ptr& src);
278 nonvirtual Ptr& operator= (Ptr&& src)
noexcept;
283 nonvirtual IRep* operator->() const noexcept;
289 nonvirtual ::sqlite3* Peek () const;
296 Common::Property<Duration> busyTimeout;
302 Common::Property<JournalModeType> journalMode;
305 friend class Statement;
311 Ptr New (const Options& options);
332 class IRep : public SQL::Connection::IRep {
337 virtual ::sqlite3* Peek () = 0;
343 virtual Duration GetBusyTimeout ()
const = 0;
349 virtual void SetBusyTimeout (
const Duration& timeout) = 0;
354 virtual JournalModeType GetJournalMode ()
const = 0;
359 virtual void SetJournalMode (JournalModeType journalMode) = 0;
362 [[no_unique_address]] Debug::AssertExternallySynchronizedMutex fAssertExternallySynchronizedMutex;
374 class Statement :
public SQL::Statement {
376 using inherited = SQL::Statement;
381 Statement () =
delete;
382 Statement (
const Connection::Ptr& db,
const String& query);
383 Statement (
const Statement&) =
delete;
399 class Transaction :
public SQL::Transaction {
401 using inherited = SQL::Transaction;
428 Transaction () =
delete;
429 Transaction (
const Connection::Ptr& db, Flag f = Flag::eDEFAULT);
430 Transaction (
const Transaction&) =
delete;