Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f286d95
Corrected error handling for errors when opening the DB
trueqbit Feb 2, 2025
b8a832b
Threadsafe database connection holder
trueqbit Feb 2, 2025
8285dab
Simplified logic of connection holders 'retain' function
trueqbit Feb 5, 2025
c3dfa76
Merge branch 'upstream/dev' into upstream/experimental/threadsafe_con…
trueqbit Feb 6, 2025
458ec11
Set up the database under the same synchronization lock as opening it
trueqbit Feb 7, 2025
cbb81ac
Unqualified use of member variables beginning with an underscore
trueqbit Feb 7, 2025
23f66e0
Reordered connection holder's members for the purpose of L1 cache line
trueqbit Feb 10, 2025
14a2aa0
Ability to specify connection control options when making 'storage'
trueqbit Feb 10, 2025
de7cee0
Corrected a pre-processor condition
trueqbit Feb 11, 2025
9f5654f
Added another static unit test for `create_from_tuple()`
trueqbit Feb 13, 2025
ef12ae4
Corrected UT for tuple transformation
trueqbit Feb 16, 2025
3ed7507
Renamed public-facing connection control member variable
trueqbit Feb 16, 2025
78bd3ff
Merge branch 'upstream/dev' into upstream/experimental/threadsafe_con…
trueqbit Feb 19, 2025
9158a26
Merge branch upstream/dev into upstream/experimental/threadsafe_conne…
trueqbit Feb 19, 2025
1cd81b4
Merge branch 'upstream/dev' into upstream/experimental/threadsafe_con…
trueqbit Mar 20, 2025
e186657
Maximum efficient result row stepping loop with `goto`
trueqbit Mar 21, 2025
4adb678
Enabled SQLite extended error codes
trueqbit Mar 21, 2025
4df56f1
Maximum efficient result row stepping loop
trueqbit Mar 22, 2025
4ff1aff
Removed superfluous value cast to char
trueqbit Mar 22, 2025
815bec4
Used C API for strings from `std` namespace in unit tests
trueqbit Mar 23, 2025
f41c81a
Merge branch 'upstream/dev' into upstream/experimental/threadsafe_con…
trueqbit Aug 26, 2025
14dd6b4
Suppressed warning about over aligned structs
trueqbit Aug 26, 2025
9b5b28c
Merge branch 'dev' into experimental/threadsafe_connection
trueqbit Oct 23, 2025
722e7e4
Restore "open forever" hint
trueqbit Oct 23, 2025
987ff78
Updated comment on `open_forever()` method
trueqbit Oct 23, 2025
368f3c0
Guarded connection lock against recursion
trueqbit Oct 23, 2025
fe6db25
Updated recursive counter check
trueqbit Oct 24, 2025
a03b2b1
Encapsulate connection control and database arguments
trueqbit Oct 24, 2025
5fb2e3c
Required C++17 support for deduction guides and `__has_include`
trueqbit Oct 24, 2025
dd96a11
Unit test for connection holder internals
trueqbit Oct 24, 2025
6df9efd
Merge branch 'dev' into experimental/threadsafe_connection
trueqbit Oct 24, 2025
44cbb1c
Thread-safe connection holder for C++17
trueqbit Oct 26, 2025
f0f7026
Added DB handle to the connection reference improving cache-friendliness
trueqbit Oct 26, 2025
84e5f09
Optimized version of a thread-safe connection holder
trueqbit Oct 27, 2025
76309d1
Less connection reference counting for transactions
trueqbit Oct 27, 2025
85df81c
Corrected recursively retaining a connection and lazy connection hand…
trueqbit Oct 27, 2025
0ea634b
Enabled configuring database limits without active connection
trueqbit Oct 27, 2025
b05aeb8
Internal documentation for connection reference and pointer
trueqbit Oct 27, 2025
5c8dc08
Removed now unused feature macro test for semaphore
trueqbit Oct 27, 2025
547d330
Updated connection reference doco and added missing newline
trueqbit Oct 27, 2025
0db6041
Updated const-qualification of db arguments
trueqbit Oct 29, 2025
289abe2
Simplified serialization of dynamically set values
trueqbit Oct 29, 2025
eea8d27
Updated retaining connections after testing contention
trueqbit Oct 29, 2025
84d342e
Updated scope guard with spelled out member variable
trueqbit Nov 1, 2025
1e4957e
Corrected space characters in some comments
trueqbit Nov 1, 2025
2890044
Catch2's `GENERATE` introduces a virtual section
trueqbit Nov 1, 2025
e9da7ef
Started markdown documentation in a `docs` folder
trueqbit Nov 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# SQLite ORM
SQLite ORM light header only library for modern C++. Please read the license precisely. The project has AGPL license for open source project and MIT license after purchasing it for 50$ (using [PayPal](https://paypal.me/fnc12) or any different way (contact using email [email protected])).

Documentation is found in [docs](docs/home.md).

# Status
| Branch | Travis | Appveyor |
| :----- | :----- | :------- |
Expand Down
6 changes: 3 additions & 3 deletions dev/backup.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ namespace sqlite_orm {
const std::string& zSourceName,
std::unique_ptr<connection_holder> holder_) :
handle(sqlite3_backup_init(to_.get(), zDestName.c_str(), from_.get(), zSourceName.c_str())),
holder(std::move(holder_)), to(to_), from(from_) {
holder(std::move(holder_)), to(std::move(to_)), from(std::move(from_)) {
if (!this->handle) {
throw std::system_error{orm_error_code::failed_to_init_a_backup};
}
}

backup_t(backup_t&& other) :
handle(std::exchange(other.handle, nullptr)), holder(std::move(other.holder)), to(other.to),
from(other.from) {}
handle(std::exchange(other.handle, nullptr)), holder(std::move(other.holder)), to(std::move(other.to)),
from(std::move(other.from)) {}

~backup_t() {
if (this->handle) {
Expand Down
306 changes: 243 additions & 63 deletions dev/connection_holder.h

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions dev/functional/cxx_new.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#ifdef SQLITE_ORM_IMPORT_STD_MODULE
#include <version>
#else
#include <new>
#endif

namespace sqlite_orm {
namespace internal {
namespace polyfill {
#if __cpp_lib_hardware_interference_size >= 201703L
using std::hardware_constructive_interference_size;
using std::hardware_destructive_interference_size;
#else
constexpr size_t hardware_constructive_interference_size = 64;
constexpr size_t hardware_destructive_interference_size = 64;
#endif
}
}

namespace polyfill = internal::polyfill;
}
23 changes: 23 additions & 0 deletions dev/functional/cxx_scope_guard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <utility> // std::forward
#endif

namespace sqlite_orm::internal {
/*
Poor-man's scope (exit) guard until C++29 finally comes with proper standard facilities [Draft D3610].
*/
template<class F>
class scope_guard {
public:
explicit scope_guard(F&& exitFunction) : _exitFunction{std::forward<F>(exitFunction)} {}

~scope_guard() {
_exitFunction();
}

private:
F _exitFunction;
};
}
17 changes: 8 additions & 9 deletions dev/limit_accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <sqlite3.h>
#ifndef SQLITE_ORM_IMPORT_STD_MODULE
#include <map> // std::map
#include <functional> // std::function
#include <memory> // std::shared_ptr
#include <functional> // std::function, std::reference_wrapper
#include <utility> // std::move
#endif

#include "connection_holder.h"
Expand All @@ -14,9 +14,7 @@ namespace sqlite_orm {
namespace internal {

struct limit_accessor {
using get_connection_t = std::function<connection_ref()>;

limit_accessor(get_connection_t get_connection_) : get_connection(std::move(get_connection_)) {}
limit_accessor(std::unique_ptr<connection_holder>& connection) : connection{connection} {}

int length() {
return this->get(SQLITE_LIMIT_LENGTH);
Expand Down Expand Up @@ -117,7 +115,7 @@ namespace sqlite_orm {
#endif

protected:
get_connection_t get_connection;
std::reference_wrapper<std::unique_ptr<connection_holder>> connection;

friend struct storage_base;

Expand All @@ -127,14 +125,15 @@ namespace sqlite_orm {
std::map<int, int> limits;

int get(int id) {
auto connection = this->get_connection();
connection_ref connection = *this->connection.get();
return sqlite3_limit(connection.get(), id, -1);
}

void set(int id, int newValue) {
this->limits[id] = newValue;
auto connection = this->get_connection();
sqlite3_limit(connection.get(), id, newValue);
if (connection_ptr maybeConnection = *this->connection.get()) {
sqlite3_limit(maybeConnection.get(), id, newValue);
}
}
};
}
Expand Down
7 changes: 7 additions & 0 deletions dev/statement_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <memory>
#include <array>
#include <list> // std::list
#ifdef SQLITE_ORM_CPP20_RANGES_SUPPORTED
#include <ranges> // std::views::transform
#endif
#endif
#include "functional/cxx_string_view.h"
#include "functional/cxx_optional.h"
Expand Down Expand Up @@ -1501,6 +1504,9 @@ namespace sqlite_orm {
const Ctx&) SQLITE_ORM_OR_CONST_CALLOP {
std::stringstream ss;
ss << "SET ";
#ifdef SQLITE_ORM_CPP20_RANGES_SUPPORTED
ss << streaming_serialized(statement | std::views::transform(&dynamic_set_entry::serialized_value));
#else
int index = 0;
for (const dynamic_set_entry& entry: statement) {
if (index > 0) {
Expand All @@ -1509,6 +1515,7 @@ namespace sqlite_orm {
ss << entry.serialized_value;
++index;
}
#endif
return ss.str();
}
};
Expand Down
28 changes: 14 additions & 14 deletions dev/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace sqlite_orm {
context_t context{this->db_objects};
statement_serializer<Table, void> serializer;
const std::string sql = serializer.serialize(table, context, tableName);
this->executor.perform_void_exec(db, sql.data());
this->executor.perform_void_exec(db, sql.c_str());
}

/**
Expand All @@ -169,7 +169,7 @@ namespace sqlite_orm {
<< streaming_identifier(columnName) << std::flush;
sql = ss.str();
}
this->executor.perform_void_exec(db, sql.data());
this->executor.perform_void_exec(db, sql.c_str());
}
#endif

Expand Down Expand Up @@ -278,8 +278,8 @@ namespace sqlite_orm {
mapped_view<O, self_type, Args...> iterate(Args&&... args) {
this->assert_mapped_type<O>();

auto connection = this->get_connection();
return {*this, std::move(connection), std::forward<Args>(args)...};
auto conRef = this->get_connection();
return {*this, std::move(conRef), std::forward<Args>(args)...};
}

#ifdef SQLITE_ORM_WITH_CPP20_ALIASES
Expand Down Expand Up @@ -313,8 +313,8 @@ namespace sqlite_orm {
if constexpr (is_select_v<Select>) {
expression.highest_level = true;
}
auto con = this->get_connection();
return {this->db_objects, std::move(con), std::move(expression)};
auto conRef = this->get_connection();
return {this->db_objects, std::move(conRef), std::move(expression)};
}

#ifdef SQLITE_ORM_CPP23_GENERATOR_SUPPORTED
Expand Down Expand Up @@ -1235,7 +1235,7 @@ namespace sqlite_orm {
<< serialize(column, context) << std::flush;
sql = ss.str();
}
this->executor.perform_void_exec(db, sql.data());
this->executor.perform_void_exec(db, sql.c_str());
}

template<class ColResult, class S>
Expand Down Expand Up @@ -1286,10 +1286,10 @@ namespace sqlite_orm {
context.omit_table_name = false;
context.replace_bindable_with_question = true;

auto conection = this->get_connection();
const std::string sql = serialize(statement, context);
sqlite3_stmt* stmt = prepare_stmt(conection.get(), sql);
return prepared_statement_t<S>{std::forward<S>(statement), stmt, std::move(conection)};
auto conRef = this->get_connection();
sqlite3_stmt* stmt = prepare_stmt(conRef.get(), sql);
return prepared_statement_t<S>{std::forward<S>(statement), stmt, std::move(conRef)};
}

public:
Expand Down Expand Up @@ -1321,9 +1321,9 @@ namespace sqlite_orm {
* can be printed out on std::ostream with `operator<<`.
*/
std::map<std::string, sync_schema_result> sync_schema(bool preserve = false) {
auto con = this->get_connection();
auto conRef = this->get_connection();
std::map<std::string, sync_schema_result> result;
iterate_tuple<true>(this->db_objects, [this, db = con.get(), preserve, &result](auto& schemaObject) {
iterate_tuple<true>(this->db_objects, [this, db = conRef.get(), preserve, &result](auto& schemaObject) {
sync_schema_result status = this->sync_dbo(schemaObject, db, preserve);
result.emplace(schemaObject.name, status);
});
Expand All @@ -1336,9 +1336,9 @@ namespace sqlite_orm {
* what will happen if you sync your schema.
*/
std::map<std::string, sync_schema_result> sync_schema_simulate(bool preserve = false) {
auto con = this->get_connection();
auto conRef = this->get_connection();
std::map<std::string, sync_schema_result> result;
iterate_tuple<true>(this->db_objects, [this, db = con.get(), preserve, &result](auto& schemaObject) {
iterate_tuple<true>(this->db_objects, [this, db = conRef.get(), preserve, &result](auto& schemaObject) {
sync_schema_result status = this->schema_status(schemaObject, db, preserve, nullptr);
result.emplace(schemaObject.name, status);
});
Expand Down
Loading