Skip to content

Commit

Permalink
Implement function to upsert and get graph operation time
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishad-M-I-M committed Aug 21, 2024
1 parent c007d63 commit abec10b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ddl/metadb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,10 @@ create table graph_operation_time
(
idgraph INTEGER NOT NULL,
idoperation INTEGER NOT NULL,
time INTEGER
time INTEGER,
primary key (idgraph, idoperation)
);

create index graph_operation_time_index
on graph_operation_time (idgraph, idoperation);

INSERT INTO graph_status (idgraph_status, description)
VALUES (1, 'LOADING'),
(2, 'OPERATIONAL'),
Expand Down
15 changes: 15 additions & 0 deletions src/metadb/SQLiteDBInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@ int SQLiteDBInterface::init() {
db_logger.info("Database opened successfully :" + this->databaseLocation);
return 0;
}


int SQLiteDBInterface::upsertGraphOperationTime(int graphId, int graphOpId, int opTime) {
return ((DBInterface *) this)->runInsert("INSERT OR REPLACE INTO graph_operation_time (idgraph, idoperation, time) VALUES "
"(" + to_string(graphId) + ", " + to_string(graphOpId) + ", " +
to_string(opTime) + ")");
}

int SQLiteDBInterface::getGraphOperationTime(int graphId, int graphOpId) {
vector<vector<pair<basic_string<char>, basic_string<char>>>> result =
((DBInterface *) this)->runSelect(
"SELECT time FROM graph_operation_time WHERE idgraph=" + to_string(graphId) +
" AND idoperation=" + to_string(graphOpId));
return stoi(result[0][0].second);
}
4 changes: 4 additions & 0 deletions src/metadb/SQLiteDBInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class SQLiteDBInterface : public DBInterface {
int init() override;

SQLiteDBInterface();

int upsertGraphOperationTime(int graphId, int graphOpId, int opTime);

int getGraphOperationTime(int graphId, int graphOpId);
};

#endif // JASMINEGRAPH_SQLITEDBINTERFACE_H
11 changes: 11 additions & 0 deletions tests/unit/metadb/SQLiteDBInterface_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,14 @@ TEST_F(SQLiteDBInterfaceTest, TestRunInsertAndUpdate) {
ASSERT_EQ(data[0][2].second, "127.0.0.1");
ASSERT_EQ(data[0][3].second, "false");
}

TEST_F(SQLiteDBInterfaceTest, TestUpsertGraphOperationTimeAndGetGraphOperationTime) {
auto result = dbInterface->upsertGraphOperationTime(1, 1, 123);
ASSERT_EQ(result, 1);
auto time = dbInterface->getGraphOperationTime(1, 1);
ASSERT_EQ(time, 123);
result = dbInterface->upsertGraphOperationTime(1, 1, 456);
ASSERT_EQ(result, 1);
time = dbInterface->getGraphOperationTime(1, 1);
ASSERT_EQ(time, 456);
}

0 comments on commit abec10b

Please sign in to comment.