react-native-nitro-sqlite 9.1.5 → 9.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@
5
5
  #include <cmath>
6
6
  #include <ctime>
7
7
  #include <iostream>
8
+ #include <optional>
8
9
  #include <map>
9
10
  #include <sqlite3.h>
10
11
  #include <sstream>
@@ -143,8 +144,8 @@ SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::str
143
144
  std::string column_name;
144
145
  ColumnType column_declared_type;
145
146
  SQLiteQueryResultRow row;
146
- auto results = std::make_unique<SQLiteQueryResults>();
147
- auto metadata = new SQLiteQueryTableMetadata();
147
+ SQLiteQueryResults results;
148
+ std::optional<SQLiteQueryTableMetadata> metadata = std::nullopt;
148
149
 
149
150
  while (isConsuming) {
150
151
  result = sqlite3_step(statement);
@@ -192,7 +193,7 @@ SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::str
192
193
  }
193
194
  i++;
194
195
  }
195
- results->push_back(std::move(row));
196
+ results.push_back(std::move(row));
196
197
  break;
197
198
  case SQLITE_DONE:
198
199
  i = 0;
@@ -202,6 +203,10 @@ SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::str
202
203
  const char* tp = sqlite3_column_decltype(statement, i);
203
204
  column_declared_type = mapSQLiteTypeToColumnType(tp);
204
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
+ }
205
210
  metadata->insert({column_name, columnMeta});
206
211
  i++;
207
212
  }
@@ -221,16 +226,11 @@ SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::str
221
226
 
222
227
  int rowsAffected = sqlite3_changes(db);
223
228
  long long latestInsertRowId = sqlite3_last_insert_rowid(db);
224
- auto meta = std::make_unique<std::optional<SQLiteQueryTableMetadata>>(
225
- metadata && metadata->size() > 0
226
- ? std::make_optional(std::move(*metadata))
227
- : std::nullopt
228
- );
229
229
  return {
230
230
  .rowsAffected = rowsAffected,
231
231
  .insertId = static_cast<double>(latestInsertRowId),
232
232
  .results = std::move(results),
233
- .metadata = std::move(meta)
233
+ .metadata = std::move(metadata)
234
234
  };
235
235
  }
236
236
 
@@ -3,19 +3,19 @@
3
3
  namespace margelo::nitro::rnnitrosqlite {
4
4
 
5
5
  std::optional<double> HybridNativeQueryResult::getInsertId() {
6
- return this->_insertId;
6
+ return _result.insertId;
7
7
  }
8
8
 
9
9
  double HybridNativeQueryResult::getRowsAffected() {
10
- return this->_rowsAffected;
10
+ return _result.rowsAffected;
11
11
  }
12
12
 
13
13
  SQLiteQueryResults HybridNativeQueryResult::getResults() {
14
- return this->_results;
14
+ return _result.results;
15
15
  };
16
16
 
17
17
  std::optional<SQLiteQueryTableMetadata> HybridNativeQueryResult::getMetadata() {
18
- return this->_metadata;
18
+ return _result.metadata;
19
19
  }
20
20
 
21
21
  } // namespace margelo::nitro::rnnitrosqlite
@@ -11,27 +11,16 @@ namespace margelo::nitro::rnnitrosqlite {
11
11
  class HybridNativeQueryResult : public HybridNativeQueryResultSpec {
12
12
  public:
13
13
  HybridNativeQueryResult() : HybridObject(TAG) {}
14
- HybridNativeQueryResult(std::optional<double> insertId, int rowsAffected, SQLiteQueryResults& results, std::optional<SQLiteQueryTableMetadata>& metadata)
15
- : HybridObject(TAG),
16
- _insertId(insertId),
17
- _rowsAffected(rowsAffected),
18
- _results(std::move(results)),
19
- _metadata(std::move(metadata)) {}
14
+ HybridNativeQueryResult(SQLiteExecuteQueryResult&& result): HybridObject(TAG), _result(std::move(result)) {}
20
15
 
21
16
  private:
22
- std::optional<double> _insertId;
23
- int _rowsAffected;
24
- SQLiteQueryResults _results;
25
- std::optional<SQLiteQueryTableMetadata> _metadata;
17
+ SQLiteExecuteQueryResult _result;
26
18
 
27
19
  public:
28
20
  // Properties
29
21
  std::optional<double> getInsertId() override;
30
-
31
22
  double getRowsAffected() override;
32
-
33
23
  SQLiteQueryResults getResults() override;
34
-
35
24
  std::optional<SQLiteQueryTableMetadata> getMetadata() override;
36
25
  };
37
26
 
@@ -54,8 +54,8 @@ using ExecuteQueryResult = std::shared_ptr<HybridNativeQueryResultSpec>;
54
54
 
55
55
  ExecuteQueryResult HybridNitroSQLite::execute(const std::string& dbName, const std::string& query,
56
56
  const std::optional<SQLiteQueryParams>& params) {
57
- auto result = sqliteExecute(dbName, query, params);
58
- return std::make_shared<HybridNativeQueryResult>(result.insertId, result.rowsAffected, *result.results, *result.metadata);
57
+ SQLiteExecuteQueryResult result = sqliteExecute(dbName, query, params);
58
+ return std::make_shared<HybridNativeQueryResult>(std::move(result));
59
59
  };
60
60
 
61
61
  std::shared_ptr<Promise<std::shared_ptr<HybridNativeQueryResultSpec>>> HybridNitroSQLite::executeAsync(const std::string& dbName, const std::string& query,
@@ -19,13 +19,13 @@ std::vector<BatchQuery> batchParamsToCommands(const std::vector<BatchQueryComman
19
19
  if (std::holds_alternative<NestedParamsVec>(*command.params)) {
20
20
  // This arguments is an array of arrays, like a batch update of a single sql command.
21
21
  for (const auto& params : std::get<NestedParamsVec>(*command.params)) {
22
- commands.push_back(BatchQuery{command.query, std::make_shared<ParamsVec>(params)});
22
+ commands.push_back(BatchQuery{command.query, ParamsVec(params)});
23
23
  }
24
24
  } else {
25
- commands.push_back(BatchQuery{command.query, std::make_shared<ParamsVec>(std::move(std::get<ParamsVec>(*command.params)))});
25
+ commands.push_back(BatchQuery{command.query, std::move(std::get<ParamsVec>(*command.params))});
26
26
  }
27
27
  } else {
28
- commands.push_back(BatchQuery{command.query, NULL});
28
+ commands.push_back(BatchQuery{command.query, std::nullopt});
29
29
  }
30
30
  }
31
31
 
@@ -48,7 +48,7 @@ SQLiteOperationResult sqliteExecuteBatch(const std::string& dbName, const std::v
48
48
  auto results = SQLiteQueryResults();
49
49
  auto metadata = std::optional<SQLiteQueryTableMetadata>(std::nullopt);
50
50
  try {
51
- auto result = sqliteExecute(dbName, command.sql, *command.params.get());
51
+ auto result = sqliteExecute(dbName, command.sql, command.params);
52
52
  rowsAffected += result.rowsAffected;
53
53
  } catch (NitroSQLiteException& e) {
54
54
  sqliteExecuteLiteral(dbName, "ROLLBACK");
@@ -13,7 +13,7 @@ namespace margelo::rnnitrosqlite {
13
13
 
14
14
  struct BatchQuery {
15
15
  std::string sql;
16
- std::shared_ptr<SQLiteQueryParams> params;
16
+ std::optional<SQLiteQueryParams> params;
17
17
  };
18
18
 
19
19
  /**
package/cpp/types.hpp CHANGED
@@ -27,8 +27,8 @@ struct SQLiteExecuteQueryResult {
27
27
  int rowsAffected;
28
28
  double insertId;
29
29
 
30
- std::unique_ptr<SQLiteQueryResults> results;
31
- std::unique_ptr<std::optional<SQLiteQueryTableMetadata>> metadata;
30
+ SQLiteQueryResults results;
31
+ std::optional<SQLiteQueryTableMetadata> metadata;
32
32
  };
33
33
 
34
34
  // constexpr function that maps SQLiteColumnType to string literals
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-sqlite",
3
- "version": "9.1.5",
3
+ "version": "9.1.6",
4
4
  "description": "Fast SQLite library for React Native built using Nitro Modules",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/commonjs/index",