libpqxx 7.8.1
transaction.hxx
1/* Definition of the pqxx::transaction class.
2 * pqxx::transaction represents a standard database transaction.
3 *
4 * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/transaction instead.
5 *
6 * Copyright (c) 2000-2023, Jeroen T. Vermeulen.
7 *
8 * See COPYING for copyright license. If you did not receive a file called
9 * COPYING with this source code, please notify the distributor of this
10 * mistake, or contact the author.
11 */
12#ifndef PQXX_H_TRANSACTION
13#define PQXX_H_TRANSACTION
14
15#if !defined(PQXX_HEADER_PRE)
16# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
17#endif
18
19#include "pqxx/dbtransaction.hxx"
20
21namespace pqxx::internal
22{
24class PQXX_LIBEXPORT basic_transaction : public dbtransaction
25{
26protected:
28 connection &c, zview begin_command, std::string_view tname);
29 basic_transaction(connection &c, zview begin_command, std::string &&tname);
30 basic_transaction(connection &c, zview begin_command);
31
32 virtual ~basic_transaction() noexcept override = 0;
33
34private:
35 virtual void do_commit() override;
36};
37} // namespace pqxx::internal
38
39
40namespace pqxx
41{
46
48
68template<
69 isolation_level ISOLATION = isolation_level::read_committed,
70 write_policy READWRITE = write_policy::read_write>
71class transaction final : public internal::basic_transaction
72{
73public:
75
80 transaction(connection &c, std::string_view tname) :
82 c, internal::begin_cmd<ISOLATION, READWRITE>, tname}
83 {}
84
86
90 explicit transaction(connection &c) :
92 c, internal::begin_cmd<ISOLATION, READWRITE>}
93 {}
94
95 virtual ~transaction() noexcept override { close(); }
96};
97
98
100using work = transaction<>;
101
103using read_transaction =
104 transaction<isolation_level::read_committed, write_policy::read_only>;
105
107} // namespace pqxx
108#endif
The home of all libpqxx classes, functions, templates, etc.
Definition array.hxx:33
write_policy
Should a transaction be read-only, or read-write?
Definition isolation.hxx:27
isolation_level
Transaction isolation levels.
Definition isolation.hxx:66
Internal items for libpqxx' own use. Do not use these yourself.
Definition composite.hxx:84
Connection to a database.
Definition connection.hxx:253
Abstract transaction base class: bracket transactions on the database.
Definition dbtransaction.hxx:54
Helper base class for the transaction class template.
Definition transaction.hxx:25
virtual ~basic_transaction() noexcept override=0
Marker-type wrapper: zero-terminated std::string_view.
Definition zview.hxx:38