Skip to content

Commit f09395a

Browse files
authored
style: Fix C++ code linting (#228)
* fix: invalid cpp folder path in `clang-format.sh` script * fix: add sqlite source files to `.clang-format-ignore` * style: run `lint-cpp`
1 parent 207ce3f commit f09395a

12 files changed

+73
-70
lines changed

.clang-format-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package/cpp/sqlite/*

package/cpp/NitroSQLiteException.hpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

3-
#include <string>
4-
#include <iostream>
53
#include <exception>
4+
#include <iostream>
5+
#include <string>
66

77
enum NitroSQLiteExceptionType {
88
UnknownError,
@@ -15,26 +15,25 @@ enum NitroSQLiteExceptionType {
1515
};
1616

1717
inline std::unordered_map<NitroSQLiteExceptionType, std::string> exceptionTypeStrings = {
18-
{UnknownError, "UnknownError"},
19-
{DatabaseCannotBeOpened, "DatabaseCannotBeOpened"},
20-
{DatabaseNotOpen, "DatabaseNotOpen"},
21-
{UnableToAttachToDatabase, "UnableToAttachToDatabase"},
22-
{SqlExecutionError, "SqlExecutionError"},
23-
{CouldNotLoadFile, "CouldNotLoadFile"},
24-
{NoBatchCommandsProvided, "NoBatchCommandsProvided"}
25-
};
18+
{UnknownError, "UnknownError"},
19+
{DatabaseCannotBeOpened, "DatabaseCannotBeOpened"},
20+
{DatabaseNotOpen, "DatabaseNotOpen"},
21+
{UnableToAttachToDatabase, "UnableToAttachToDatabase"},
22+
{SqlExecutionError, "SqlExecutionError"},
23+
{CouldNotLoadFile, "CouldNotLoadFile"},
24+
{NoBatchCommandsProvided, "NoBatchCommandsProvided"}};
2625

2726
inline std::string typeToString(NitroSQLiteExceptionType type) {
2827
return exceptionTypeStrings[type];
2928
}
3029

3130
class NitroSQLiteException : public std::exception {
3231
public:
33-
explicit NitroSQLiteException(const char* message): NitroSQLiteException(NitroSQLiteExceptionType::UnknownError, message) {}
34-
explicit NitroSQLiteException(const std::string& message): NitroSQLiteException(NitroSQLiteExceptionType::UnknownError, message) {}
32+
explicit NitroSQLiteException(const char* message) : NitroSQLiteException(NitroSQLiteExceptionType::UnknownError, message) {}
33+
explicit NitroSQLiteException(const std::string& message) : NitroSQLiteException(NitroSQLiteExceptionType::UnknownError, message) {}
3534
NitroSQLiteException(const NitroSQLiteExceptionType& type, const char* message) : NitroSQLiteException(type, std::string(message)) {}
3635
NitroSQLiteException(const NitroSQLiteExceptionType& type, const std::string& message)
37-
: _exceptionString("[" + typeToString(type) + "] " + message) {}
36+
: _exceptionString("[" + typeToString(type) + "] " + message) {}
3837

3938
private:
4039
const std::string _exceptionString;

package/cpp/importSqlFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
*/
44

55
#include "importSqlFile.hpp"
6-
#include <fstream>
7-
#include <iostream>
86
#include "NitroSQLiteException.hpp"
97
#include "operations.hpp"
8+
#include <fstream>
9+
#include <iostream>
1010

1111
namespace margelo::rnnitrosqlite {
1212

package/cpp/operations.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#include "operations.hpp"
2+
#include "NitroSQLiteException.hpp"
23
#include "logs.hpp"
34
#include "utils.hpp"
45
#include <NitroModules/ArrayBuffer.hpp>
56
#include <cmath>
67
#include <ctime>
78
#include <iostream>
8-
#include <optional>
99
#include <map>
10+
#include <optional>
1011
#include <sqlite3.h>
1112
#include <sstream>
1213
#include <unistd.h>
13-
#include "NitroSQLiteException.hpp"
1414

1515
using namespace facebook;
1616
using namespace margelo::nitro;
@@ -59,7 +59,7 @@ void sqliteCloseAll() {
5959
}
6060

6161
void sqliteAttachDb(const std::string& mainDBName, const std::string& docPath, const std::string& databaseToAttach,
62-
const std::string& alias) {
62+
const std::string& alias) {
6363
/**
6464
* There is no need to check if mainDBName is opened because sqliteExecuteLiteral will do that.
6565
* */
@@ -69,7 +69,8 @@ void sqliteAttachDb(const std::string& mainDBName, const std::string& docPath, c
6969
try {
7070
sqliteExecuteLiteral(mainDBName, statement);
7171
} catch (NitroSQLiteException& e) {
72-
throw NitroSQLiteException(NitroSQLiteExceptionType::UnableToAttachToDatabase, mainDBName + " was unable to attach another database: " + std::string(e.what()));
72+
throw NitroSQLiteException(NitroSQLiteExceptionType::UnableToAttachToDatabase,
73+
mainDBName + " was unable to attach another database: " + std::string(e.what()));
7374
}
7475
}
7576

@@ -82,7 +83,8 @@ void sqliteDetachDb(const std::string& mainDBName, const std::string& alias) {
8283
try {
8384
sqliteExecuteLiteral(mainDBName, statement);
8485
} catch (NitroSQLiteException& e) {
85-
throw NitroSQLiteException(NitroSQLiteExceptionType::UnableToAttachToDatabase, mainDBName + " was unable to detach database: " + std::string(e.what()));
86+
throw NitroSQLiteException(NitroSQLiteExceptionType::UnableToAttachToDatabase,
87+
mainDBName + " was unable to detach database: " + std::string(e.what()));
8688
}
8789
}
8890

@@ -101,7 +103,7 @@ void sqliteRemoveDb(const std::string& dbName, const std::string& docPath) {
101103

102104
void bindStatement(sqlite3_stmt* statement, const SQLiteQueryParams& values) {
103105
for (int valueIndex = 0; valueIndex < values.size(); valueIndex++) {
104-
int sqliteIndex = valueIndex+1;
106+
int sqliteIndex = valueIndex + 1;
105107
SQLiteValue value = values.at(valueIndex);
106108
if (std::holds_alternative<SQLiteNullValue>(value)) {
107109
sqlite3_bind_null(statement, sqliteIndex);
@@ -119,7 +121,8 @@ void bindStatement(sqlite3_stmt* statement, const SQLiteQueryParams& values) {
119121
}
120122
}
121123

122-
SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::string& query, const std::optional<SQLiteQueryParams>& params) {
124+
SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::string& query,
125+
const std::optional<SQLiteQueryParams>& params) {
123126
if (dbMap.count(dbName) == 0) {
124127
throw NitroSQLiteException::DatabaseNotOpen(dbName);
125128
}
@@ -196,21 +199,21 @@ SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::str
196199
results.push_back(std::move(row));
197200
break;
198201
case SQLITE_DONE:
199-
i = 0;
200-
count = sqlite3_column_count(statement);
201-
while (i < count) {
202-
column_name = sqlite3_column_name(statement, i);
203-
const char* tp = sqlite3_column_decltype(statement, i);
204-
column_declared_type = mapSQLiteTypeToColumnType(tp);
205-
auto columnMeta = SQLiteQueryColumnMetadata(std::move(column_name), std::move(column_declared_type), i);
206-
207-
if (!metadata) {
208-
metadata = std::make_optional<SQLiteQueryTableMetadata>();
209-
}
210-
metadata->insert({column_name, columnMeta});
211-
i++;
202+
i = 0;
203+
count = sqlite3_column_count(statement);
204+
while (i < count) {
205+
column_name = sqlite3_column_name(statement, i);
206+
const char* tp = sqlite3_column_decltype(statement, i);
207+
column_declared_type = mapSQLiteTypeToColumnType(tp);
208+
auto columnMeta = SQLiteQueryColumnMetadata(std::move(column_name), std::move(column_declared_type), i);
209+
210+
if (!metadata) {
211+
metadata = std::make_optional<SQLiteQueryTableMetadata>();
212212
}
213-
isConsuming = false;
213+
metadata->insert({column_name, columnMeta});
214+
i++;
215+
}
216+
isConsuming = false;
214217
break;
215218
default:
216219
isFailed = true;
@@ -226,12 +229,10 @@ SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::str
226229

227230
int rowsAffected = sqlite3_changes(db);
228231
long long latestInsertRowId = sqlite3_last_insert_rowid(db);
229-
return {
230-
.rowsAffected = rowsAffected,
231-
.insertId = static_cast<double>(latestInsertRowId),
232-
.results = std::move(results),
233-
.metadata = std::move(metadata)
234-
};
232+
return {.rowsAffected = rowsAffected,
233+
.insertId = static_cast<double>(latestInsertRowId),
234+
.results = std::move(results),
235+
.metadata = std::move(metadata)};
235236
}
236237

237238
SQLiteOperationResult sqliteExecuteLiteral(const std::string& dbName, const std::string& query) {

package/cpp/operations.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void sqliteCloseDb(const std::string& dbName);
1111
void sqliteRemoveDb(const std::string& dbName, const std::string& docPath);
1212

1313
void sqliteAttachDb(const std::string& mainDBName, const std::string& docPath, const std::string& databaseToAttach,
14-
const std::string& alias);
14+
const std::string& alias);
1515

1616
void sqliteDetachDb(const std::string& mainDBName, const std::string& alias);
1717

package/cpp/specs/HybridNativeQueryResult.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace margelo::nitro::rnnitrosqlite {
1111
class HybridNativeQueryResult : public HybridNativeQueryResultSpec {
1212
public:
1313
HybridNativeQueryResult() : HybridObject(TAG) {}
14-
HybridNativeQueryResult(SQLiteExecuteQueryResult&& result): HybridObject(TAG), _result(std::move(result)) {}
14+
HybridNativeQueryResult(SQLiteExecuteQueryResult&& result) : HybridObject(TAG), _result(std::move(result)) {}
1515

1616
private:
1717
SQLiteExecuteQueryResult _result;

package/cpp/specs/HybridNitroSQLite.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "HybridNitroSQLite.hpp"
22
#include "HybridNativeQueryResult.hpp"
33
#include "NitroSQLiteException.hpp"
4+
#include "importSqlFile.hpp"
45
#include "logs.hpp"
56
#include "macros.hpp"
6-
#include "sqliteExecuteBatch.hpp"
7-
#include "importSqlFile.hpp"
87
#include "operations.hpp"
8+
#include "sqliteExecuteBatch.hpp"
99
#include <iostream>
1010
#include <map>
1111
#include <string>
@@ -53,13 +53,13 @@ void HybridNitroSQLite::detach(const std::string& mainDbName, const std::string&
5353
using ExecuteQueryResult = std::shared_ptr<HybridNativeQueryResultSpec>;
5454

5555
ExecuteQueryResult HybridNitroSQLite::execute(const std::string& dbName, const std::string& query,
56-
const std::optional<SQLiteQueryParams>& params) {
56+
const std::optional<SQLiteQueryParams>& params) {
5757
SQLiteExecuteQueryResult result = sqliteExecute(dbName, query, params);
5858
return std::make_shared<HybridNativeQueryResult>(std::move(result));
5959
};
6060

61-
std::shared_ptr<Promise<std::shared_ptr<HybridNativeQueryResultSpec>>> HybridNitroSQLite::executeAsync(const std::string& dbName, const std::string& query,
62-
const std::optional<SQLiteQueryParams>& params) {
61+
std::shared_ptr<Promise<std::shared_ptr<HybridNativeQueryResultSpec>>>
62+
HybridNitroSQLite::executeAsync(const std::string& dbName, const std::string& query, const std::optional<SQLiteQueryParams>& params) {
6363
return Promise<std::shared_ptr<HybridNativeQueryResultSpec>>::async([=, this]() -> std::shared_ptr<HybridNativeQueryResultSpec> {
6464
auto result = execute(dbName, query, params);
6565
return result;

package/cpp/specs/HybridNitroSQLite.hpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include "HybridNitroSQLiteSpec.hpp"
43
#include "HybridNativeQueryResultSpec.hpp"
4+
#include "HybridNitroSQLiteSpec.hpp"
55
#include "types.hpp"
66

77
using namespace margelo::rnnitrosqlite;
@@ -13,28 +13,31 @@ class HybridNitroSQLite : public HybridNitroSQLiteSpec {
1313
HybridNitroSQLite() : HybridObject(TAG) {}
1414

1515
public:
16-
static std::string docPath;
16+
static std::string docPath;
1717

1818
public:
1919
// Methods
2020
void open(const std::string& dbName, const std::optional<std::string>& location) override;
21-
21+
2222
void close(const std::string& dbName) override;
23-
23+
2424
void drop(const std::string& dbName, const std::optional<std::string>& location) override;
25-
25+
2626
void attach(const std::string& mainDbName, const std::string& dbNameToAttach, const std::string& alias,
2727
const std::optional<std::string>& location) override;
28-
28+
2929
void detach(const std::string& mainDbName, const std::string& alias) override;
30-
31-
std::shared_ptr<HybridNativeQueryResultSpec> execute(const std::string& dbName, const std::string& query, const std::optional<SQLiteQueryParams>& params) override;
32-
33-
std::shared_ptr<Promise<std::shared_ptr<HybridNativeQueryResultSpec>>> executeAsync(const std::string& dbName, const std::string& query, const std::optional<SQLiteQueryParams>& params) override;
34-
30+
31+
std::shared_ptr<HybridNativeQueryResultSpec> execute(const std::string& dbName, const std::string& query,
32+
const std::optional<SQLiteQueryParams>& params) override;
33+
34+
std::shared_ptr<Promise<std::shared_ptr<HybridNativeQueryResultSpec>>>
35+
executeAsync(const std::string& dbName, const std::string& query, const std::optional<SQLiteQueryParams>& params) override;
36+
3537
BatchQueryResult executeBatch(const std::string& dbName, const std::vector<NativeBatchQueryCommand>& commands) override;
36-
std::shared_ptr<Promise<BatchQueryResult>> executeBatchAsync(const std::string& dbName, const std::vector<NativeBatchQueryCommand>& commands) override;
37-
38+
std::shared_ptr<Promise<BatchQueryResult>> executeBatchAsync(const std::string& dbName,
39+
const std::vector<NativeBatchQueryCommand>& commands) override;
40+
3841
FileLoadResult loadFile(const std::string& dbName, const std::string& location) override;
3942
std::shared_ptr<Promise<FileLoadResult>> loadFileAsync(const std::string& dbName, const std::string& location) override;
4043
};

package/cpp/sqliteExecuteBatch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* SQL Batch execution implementation using default sqliteBridge implementation
33
*/
44
#include "sqliteExecuteBatch.hpp"
5+
#include "NitroSQLiteException.hpp"
56
#include "operations.hpp"
67
#include <utility>
7-
#include "NitroSQLiteException.hpp"
88

99
namespace margelo::rnnitrosqlite {
1010

package/cpp/types.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#pragma once
22

3-
#include <string>
4-
#include <NitroModules/ArrayBuffer.hpp>
5-
#include "SQLiteQueryColumnMetadata.hpp"
63
#include "ColumnType.hpp"
74
#include "SQLiteNullValue.hpp"
5+
#include "SQLiteQueryColumnMetadata.hpp"
6+
#include <NitroModules/ArrayBuffer.hpp>
7+
#include <string>
88

99
using namespace margelo::nitro;
1010
using namespace margelo::nitro::rnnitrosqlite;

0 commit comments

Comments
 (0)