Skip to content

Commit 95386ed

Browse files
chinmaygardednfield
authored andcommitted
Remove superfluous auto_key from ArchiveDef.
1 parent 94b9bfd commit 95386ed

File tree

4 files changed

+5
-18
lines changed

4 files changed

+5
-18
lines changed

impeller/archivist/archivable.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace impeller {
1313

1414
struct ArchiveDef {
1515
const std::string table_name;
16-
const bool auto_key = true;
1716
const std::vector<std::string> members;
1817
};
1918

impeller/archivist/archive.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ std::optional<int64_t /* row id */> Archive::ArchiveInstance(
5353

5454
auto primary_key = archivable.GetPrimaryKey();
5555

56-
if (!definition.auto_key && !primary_key.has_value()) {
57-
VALIDATION_LOG << "Archive definition specified that primary keys will be "
58-
"explicitly specified but none was provided when asked.";
59-
return std::nullopt;
60-
}
61-
6256
/*
6357
* The lifecycle of the archive item is tied to this scope and there is no
6458
* 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(
6862
ArchiveLocation item(*this, statement, *registration, primary_key);
6963

7064
/*
71-
* We need to bind the primary key only if the item does not provide its own
65+
* If the item provides its own primary key, we need to bind it now.
66+
* Otherwise, one will be automatically assigned to it.
7267
*/
73-
if (!definition.auto_key &&
68+
if (primary_key.has_value() &&
7469
!statement.WriteValue(ArchiveClassRegistration::kPrimaryKeyIndex,
7570
primary_key.value())) {
7671
return std::nullopt;
@@ -86,7 +81,7 @@ std::optional<int64_t /* row id */> Archive::ArchiveInstance(
8681

8782
int64_t lastInsert = database_->GetLastInsertRowID();
8883

89-
if (!definition.auto_key &&
84+
if (primary_key.has_value() &&
9085
lastInsert != static_cast<int64_t>(primary_key.value())) {
9186
return std::nullopt;
9287
}

impeller/archivist/archive_class_registration.cc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,7 @@ bool ArchiveClassRegistration::CreateTable() {
6060
* a statement and check its validity before running.
6161
*/
6262
stream << "CREATE TABLE IF NOT EXISTS " << definition_.table_name << " ("
63-
<< kArchivePrimaryKeyColumnName;
64-
65-
if (definition_.auto_key) {
66-
stream << " INTEGER PRIMARY KEY AUTOINCREMENT, ";
67-
} else {
68-
stream << " INTEGER PRIMARY KEY, ";
69-
}
63+
<< kArchivePrimaryKeyColumnName << " INTEGER PRIMARY KEY, ";
7064

7165
for (size_t i = 0, columns = definition_.members.size(); i < columns; i++) {
7266
stream << definition_.members[i];

impeller/archivist/archivist_unittests.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class Sample : public Archivable {
4949

5050
const ArchiveDef Sample::kArchiveDefinition = {
5151
.table_name = "Sample",
52-
.auto_key = false,
5352
.members = {"some_data"},
5453
};
5554

0 commit comments

Comments
 (0)