| Flutter Impeller |

Classes | Public Member Functions | Friends | List of all members
impeller::ArchiveDatabase Class Reference

A handle to the underlying database connection for an archive. More...

`#include <archive_database.h>`

## Classes
struct | Handle

## Public Member Functions
| ArchiveDatabase (const std::string &filename)
| ~ArchiveDatabase ()
bool | IsValid () const
int64_t | GetLastInsertRowID ()
const ArchiveClassRegistration * | GetRegistrationForDefinition (const ArchiveDef &definition)
ArchiveTransaction | CreateTransaction (int64_t &transactionCount)

## Friends
class | ArchiveClassRegistration

## Detailed Description

A handle to the underlying database connection for an archive.

Definition at line 23 of file archive_database.h.

## Constructor & Destructor Documentation

## ◆ ArchiveDatabase()

impeller::ArchiveDatabase::ArchiveDatabase | ( | const std::string & | filename | ) |

Definition at line 53 of file archive_database.cc.

54 : handle_(std::make_unique<Handle>(filename)) {
55 if (!handle_->IsValid()) {
56 handle_.reset();
57 return;
58 }
59
60 begin_transaction_stmt_ = std::unique_ptr<ArchiveStatement>(
61 new ArchiveStatement(handle_->Get(), "BEGIN TRANSACTION;"));
62
63 if (!begin_transaction_stmt_->IsValid()) {
64 return;
65 }
66
67 end_transaction_stmt_ = std::unique_ptr<ArchiveStatement>(
68 new ArchiveStatement(handle_->Get(), "END TRANSACTION;"));
69
70 if (!end_transaction_stmt_->IsValid()) {
71 return;
72 }
73
74 rollback_transaction_stmt_ = std::unique_ptr<ArchiveStatement>(
75 new ArchiveStatement(handle_->Get(), "ROLLBACK TRANSACTION;"));
76
77 if (!rollback_transaction_stmt_->IsValid()) {
78 return;
79 }
80 }

## ◆ ~ArchiveDatabase()

impeller::ArchiveDatabase::~ArchiveDatabase | ( |  | ) |
| default

## Member Function Documentation

## ◆ CreateTransaction()

ArchiveTransaction impeller::ArchiveDatabase::CreateTransaction | ( | int64_t & | transactionCount | ) |

Definition at line 133 of file archive_database.cc.

134 {
135 return ArchiveTransaction{transactionCount, //
136 *begin_transaction_stmt_, //
137 *end_transaction_stmt_, //
138 *rollback_transaction_stmt_};
139 }

## ◆ GetLastInsertRowID()

int64_t impeller::ArchiveDatabase::GetLastInsertRowID | ( |  | ) |

Definition at line 88 of file archive_database.cc.

88 {
89 if (!IsValid()) {
90 return 0u;
91 }
92 return ::sqlite3_last_insert_rowid(handle_->Get());
93 }

References IsValid().

## ◆ GetRegistrationForDefinition()

const ArchiveClassRegistration * impeller::ArchiveDatabase::GetRegistrationForDefinition | ( | const ArchiveDef & | definition | ) |

Definition at line 103 of file archive_database.cc.

104 {
105 auto found = registrations_.find(definition.table_name);
106 if (found != registrations_.end()) {
107 /*
108 * This class has already been registered.
109 */
110 return RegistrationIfReady(found->second.get());
111 }
112
113 /*
114 * Initialize a new class registration for the given class definition.
115 */
116 auto registration = std::unique_ptr<ArchiveClassRegistration>(
117 new ArchiveClassRegistration(*this, definition));
118 auto res =
119 registrations_.emplace(definition.table_name, std::move(registration));
120
121 /*
122 * If the new class registration is ready, return it to the caller.
123 */
124 return res.second ? RegistrationIfReady((*(res.first)).second.get())
125 : nullptr;
126 }

References ArchiveClassRegistration, impeller::RegistrationIfReady(), and impeller::ArchiveDef::table_name.

## ◆ IsValid()

bool impeller::ArchiveDatabase::IsValid | ( |  | ) | const

Definition at line 84 of file archive_database.cc.

84 {
85 return handle_ != nullptr;
86 }

Referenced by GetLastInsertRowID().

## Friends And Related Function Documentation

## ◆ ArchiveClassRegistration

friend class ArchiveClassRegistration
| friend

Definition at line 47 of file archive_database.h.

Referenced by GetRegistrationForDefinition().

The documentation for this class was generated from the following files:

- impeller/archivist/archive_database.h
- impeller/archivist/archive_database.cc

impeller::ArchiveDatabase::ArchiveClassRegistration
friend class ArchiveClassRegistration
Definition: archive_database.h:47
impeller::RegistrationIfReady
static const ArchiveClassRegistration * RegistrationIfReady(const ArchiveClassRegistration *registration)
Definition: archive_database.cc:95
impeller::ArchiveDatabase::IsValid
bool IsValid() const
Definition: archive_database.cc:84