| 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 | ) |
| explicit

Definition at line 55 of file archive_database.cc.

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

## ◆ ~ArchiveDatabase()

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

## Member Function Documentation

## ◆ CreateTransaction()

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

Definition at line 135 of file archive_database.cc.

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

## ◆ GetLastInsertRowID()

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

Definition at line 90 of file archive_database.cc.

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

References IsValid().

## ◆ GetRegistrationForDefinition()

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

Definition at line 105 of file archive_database.cc.

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

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

## ◆ IsValid()

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

Definition at line 86 of file archive_database.cc.

86 {
87 return handle_ != nullptr;
88 }

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:97
impeller::ArchiveDatabase::IsValid
bool IsValid() const
Definition: archive_database.cc:86