Skip to content

Commit

Permalink
Remove superfluous auto_key from ArchiveDef.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent 94b9bfd commit 95386ed
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
1 change: 0 additions & 1 deletion impeller/archivist/archivable.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace impeller {

struct ArchiveDef {
const std::string table_name;
const bool auto_key = true;
const std::vector<std::string> members;
};

Expand Down
13 changes: 4 additions & 9 deletions impeller/archivist/archive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
8 changes: 1 addition & 7 deletions impeller/archivist/archive_class_registration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
1 change: 0 additions & 1 deletion impeller/archivist/archivist_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class Sample : public Archivable {

const ArchiveDef Sample::kArchiveDefinition = {
.table_name = "Sample",
.auto_key = false,
.members = {"some_data"},
};

Expand Down

0 comments on commit 95386ed

Please sign in to comment.