Atlas Game Manager
A game manager for f95 and dlsite written in c++
Loading...
Searching...
No Matches
Transaction.hpp
Go to the documentation of this file.
1//
2// Created by kj16609 on 6/23/23.
3//
4
5#pragma once
6#ifndef ATLASGAMEMANAGER_TRANSACTION_HPP
7#define ATLASGAMEMANAGER_TRANSACTION_HPP
8
9#include <tracy/Tracy.hpp>
10
11#include <exception>
12#include <mutex>
13#include <string>
14#include <string_view>
15
16#include "Binder.hpp"
17#include "Database.hpp"
19
20namespace atlas::database
21{
22
23 template < bool is_commitable = false >
25 {
27
28 TransactionBase( const TransactionBase& ) = delete;
30 TransactionBase& operator=( const TransactionBase& other ) = delete;
31
32 bool m_finished { false };
33 std::mutex self_mtx {};
34 std::lock_guard< std::mutex > guard;
35
36 inline Binder operator<<( std::string_view sql )
37 {
38 if constexpr ( is_commitable )
39 sqlite3_exec( &Database::ref(), "BEGIN TRANSACTION;", nullptr, nullptr, nullptr );
40
41 return { sql };
42 }
43
44 template < std::uint64_t size >
45 inline Binder operator<<( const char ( &raw_str )[ size - 1 ] )
46 {
47 const std::string_view str_view { std::string_view( raw_str, size - 1 ) };
48 return *this << str_view;
49 }
50
51 void commit();
52 void abort();
53
54 ~TransactionBase() noexcept( false );
55 };
56
57} // namespace atlas::database
58
59using Transaction = atlas::database::TransactionBase< true >;
60//using RapidTransaction = atlas::database::TransactionBase< false >;
61
62#endif //ATLASGAMEMANAGER_TRANSACTION_HPP
atlas::database::TransactionBase< true > Transaction
Definition Transaction.hpp:59
Definition Binder.hpp:46
static sqlite3 & ref()
Returns a ref to the sqlite DB.
Definition Database.cpp:22
Definition Column.hpp:15
Definition Column.hpp:15
~TransactionBase() noexcept(false)
std::lock_guard< std::mutex > guard
Definition Transaction.hpp:34
Binder operator<<(std::string_view sql)
Definition Transaction.hpp:36
bool m_finished
Definition Transaction.hpp:32
TransactionBase & operator=(const TransactionBase &other)=delete
TransactionBase(const TransactionBase &)=delete
TransactionBase(TransactionBase &&)=delete
Binder operator<<(const char(&raw_str)[size - 1])
Definition Transaction.hpp:45
std::mutex self_mtx
Definition Transaction.hpp:33