Remove superfluous auto_key from ArchiveDef.

This commit is contained in:
Chinmay Garde
2021-12-12 14:00:35 -08:00
committed by Dan Field
parent 53823d0f27
commit 3ee16754eb
4 changed files with 5 additions and 18 deletions

View File

@@ -13,7 +13,6 @@ namespace impeller {
struct ArchiveDef {
const std::string table_name;
const bool auto_key = true;
const std::vector<std::string> members;
};

View File

@@ -53,12 +53,6 @@ std::optional<int64_t /* row id */> Archive::ArchiveInstance(
auto primary_key = archivable.GetPrimaryKey();
if (!definition.auto_key && !primary_key.has_value()) {
VALIDATION_LOG << "Archive definition specified that primary keys will be "
"explicitly specified but none was provided when asked.";
return std::nullopt;
}
/*
* The lifecycle of the archive item is tied to this scope and there is no
* way for the user to create an instance of an archive item. So its safe
@@ -68,9 +62,10 @@ std::optional<int64_t /* row id */> Archive::ArchiveInstance(
ArchiveLocation item(*this, statement, *registration, primary_key);
/*
* We need to bind the primary key only if the item does not provide its own
* If the item provides its own primary key, we need to bind it now.
* Otherwise, one will be automatically assigned to it.
*/
if (!definition.auto_key &&
if (primary_key.has_value() &&
!statement.WriteValue(ArchiveClassRegistration::kPrimaryKeyIndex,
primary_key.value())) {
return std::nullopt;
@@ -86,7 +81,7 @@ std::optional<int64_t /* row id */> Archive::ArchiveInstance(
int64_t lastInsert = database_->GetLastInsertRowID();
if (!definition.auto_key &&
if (primary_key.has_value() &&
lastInsert != static_cast<int64_t>(primary_key.value())) {
return std::nullopt;
}

View File

@@ -60,13 +60,7 @@ bool ArchiveClassRegistration::CreateTable() {
* a statement and check its validity before running.
*/
stream << "CREATE TABLE IF NOT EXISTS " << definition_.table_name << " ("
<< kArchivePrimaryKeyColumnName;
if (definition_.auto_key) {
stream << " INTEGER PRIMARY KEY AUTOINCREMENT, ";
} else {
stream << " INTEGER PRIMARY KEY, ";
}
<< kArchivePrimaryKeyColumnName << " INTEGER PRIMARY KEY, ";
for (size_t i = 0, columns = definition_.members.size(); i < columns; i++) {
stream << definition_.members[i];

View File

@@ -49,7 +49,6 @@ class Sample : public Archivable {
const ArchiveDef Sample::kArchiveDefinition = {
.table_name = "Sample",
.auto_key = false,
.members = {"some_data"},
};