react-native-nitro-sqlite 9.3.0 → 9.5.0

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.
Files changed (50) hide show
  1. package/android/CMakeLists.txt +1 -1
  2. package/cpp/NitroSQLiteException.hpp +1 -2
  3. package/cpp/{specs → hybridObjects}/HybridNitroSQLite.cpp +56 -9
  4. package/cpp/hybridObjects/HybridNitroSQLiteQueryResult.cpp +93 -0
  5. package/cpp/hybridObjects/HybridNitroSQLiteQueryResult.hpp +47 -0
  6. package/cpp/operations.cpp +13 -9
  7. package/cpp/operations.hpp +3 -1
  8. package/cpp/sqliteExecuteBatch.cpp +1 -1
  9. package/cpp/types.hpp +1 -10
  10. package/ios/NitroSQLite.xcodeproj/project.pbxproj +2 -2
  11. package/lib/commonjs/index.js +0 -4
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/commonjs/operations/execute.js +19 -15
  14. package/lib/commonjs/operations/execute.js.map +1 -1
  15. package/lib/commonjs/types.js.map +1 -1
  16. package/lib/module/index.js +0 -3
  17. package/lib/module/index.js.map +1 -1
  18. package/lib/module/operations/execute.js +19 -15
  19. package/lib/module/operations/execute.js.map +1 -1
  20. package/lib/module/types.js.map +1 -1
  21. package/lib/typescript/commonjs/index.d.ts +0 -2
  22. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  23. package/lib/typescript/commonjs/operations/execute.d.ts.map +1 -1
  24. package/lib/typescript/commonjs/specs/NitroSQLiteQueryResult.nitro.d.ts +0 -13
  25. package/lib/typescript/commonjs/specs/NitroSQLiteQueryResult.nitro.d.ts.map +1 -1
  26. package/lib/typescript/commonjs/types.d.ts +13 -8
  27. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  28. package/lib/typescript/module/index.d.ts +0 -2
  29. package/lib/typescript/module/index.d.ts.map +1 -1
  30. package/lib/typescript/module/operations/execute.d.ts.map +1 -1
  31. package/lib/typescript/module/specs/NitroSQLiteQueryResult.nitro.d.ts +0 -13
  32. package/lib/typescript/module/specs/NitroSQLiteQueryResult.nitro.d.ts.map +1 -1
  33. package/lib/typescript/module/types.d.ts +13 -8
  34. package/lib/typescript/module/types.d.ts.map +1 -1
  35. package/nitrogen/generated/android/RNNitroSQLiteOnLoad.cpp +35 -25
  36. package/nitrogen/generated/android/RNNitroSQLiteOnLoad.hpp +13 -4
  37. package/nitrogen/generated/android/c++/JHybridNitroSQLiteOnLoadSpec.cpp +19 -25
  38. package/nitrogen/generated/android/c++/JHybridNitroSQLiteOnLoadSpec.hpp +19 -22
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rnnitrosqlite/HybridNitroSQLiteOnLoadSpec.kt +14 -17
  40. package/nitrogen/generated/shared/c++/HybridNitroSQLiteQueryResultSpec.cpp +0 -1
  41. package/nitrogen/generated/shared/c++/HybridNitroSQLiteQueryResultSpec.hpp +0 -4
  42. package/package.json +10 -7
  43. package/src/index.ts +0 -3
  44. package/src/operations/execute.ts +26 -17
  45. package/src/specs/NitroSQLiteQueryResult.nitro.ts +0 -17
  46. package/src/types.ts +17 -14
  47. package/cpp/specs/HybridNitroSQLiteQueryResult.cpp +0 -49
  48. package/cpp/specs/HybridNitroSQLiteQueryResult.hpp +0 -28
  49. package/nitrogen/generated/shared/c++/NitroSQLiteQueryResultRows.hpp +0 -99
  50. /package/cpp/{specs → hybridObjects}/HybridNitroSQLite.hpp +0 -0
package/src/types.ts CHANGED
@@ -1,8 +1,4 @@
1
- import type {
2
- NitroSQLiteQueryColumnMetadata,
3
- NitroSQLiteQueryResult,
4
- NitroSQLiteQueryResultRows,
5
- } from './specs/NitroSQLiteQueryResult.nitro'
1
+ import type { NitroSQLiteQueryResult } from './specs/NitroSQLiteQueryResult.nitro'
6
2
 
7
3
  export interface NitroSQLiteConnectionOptions {
8
4
  name: string
@@ -42,18 +38,25 @@ export type QueryResultRow = Record<string, SQLiteValue>
42
38
 
43
39
  export type QueryResult<Row extends QueryResultRow = QueryResultRow> =
44
40
  NitroSQLiteQueryResult & {
45
- readonly rowsAffected: number
46
- readonly insertId?: number
41
+ /** Query results in a row format for TypeORM compatibility */
42
+ rows: NitroSQLiteQueryResultRows<Row>
43
+ }
47
44
 
48
- /** Query results */
49
- readonly results: Row[]
45
+ export type NitroSQLiteQueryResultRows<
46
+ Row extends Record<string, SQLiteValue> = Record<string, SQLiteValue>,
47
+ > = {
48
+ /** Raw array with all dataset */
49
+ _array: Row[]
50
50
 
51
- /** Query results in a row format for TypeORM compatibility */
52
- readonly rows?: NitroSQLiteQueryResultRows<Row>
51
+ /** The lengh of the dataset */
52
+ length: number
53
53
 
54
- /** Table metadata */
55
- readonly metadata?: Record<string, NitroSQLiteQueryColumnMetadata>
56
- }
54
+ /** A convenience function to acess the index based the row object
55
+ * @param idx the row index
56
+ * @returns the row structure identified by column names
57
+ */
58
+ item: (idx: number) => Row | undefined
59
+ }
57
60
 
58
61
  export type ExecuteQuery = <Row extends QueryResultRow = QueryResultRow>(
59
62
  query: string,
@@ -1,49 +0,0 @@
1
- #include "HybridNitroSQLiteQueryResult.hpp"
2
- #include <NitroModules/ArrayBuffer.hpp>
3
- #include <NitroModules/Null.hpp>
4
- #include <NitroModules/Promise.hpp>
5
- #include <unordered_map>
6
- #include <variant>
7
- #include <vector>
8
-
9
- namespace margelo::nitro::rnnitrosqlite {
10
-
11
- std::optional<double> HybridNitroSQLiteQueryResult::getInsertId() {
12
- return _result.insertId;
13
- }
14
-
15
- double HybridNitroSQLiteQueryResult::getRowsAffected() {
16
- return _result.rowsAffected;
17
- }
18
-
19
- SQLiteQueryResults HybridNitroSQLiteQueryResult::getResults() {
20
- return _result.results;
21
- };
22
-
23
- std::optional<NitroSQLiteQueryResultRows> HybridNitroSQLiteQueryResult::getRows() {
24
- if (_result.results.empty()) {
25
- return std::nullopt;
26
- }
27
-
28
- auto rows = _result.results;
29
-
30
- // Create the item function that returns a Promise
31
- auto itemFunction = [rows](double idx) -> std::shared_ptr<Promise<std::optional<SQLiteQueryResultRow>>> {
32
- return Promise<std::optional<SQLiteQueryResultRow>>::async([rows, idx]() -> std::optional<SQLiteQueryResultRow> {
33
- const auto index = static_cast<size_t>(idx);
34
- if (index >= rows.size()) {
35
- return std::nullopt;
36
- }
37
- return rows[index];
38
- });
39
- };
40
-
41
- const auto length = static_cast<double>(rows.size());
42
- return NitroSQLiteQueryResultRows(std::move(rows), length, itemFunction);
43
- }
44
-
45
- std::optional<SQLiteQueryTableMetadata> HybridNitroSQLiteQueryResult::getMetadata() {
46
- return _result.metadata;
47
- }
48
-
49
- } // namespace margelo::nitro::rnnitrosqlite
@@ -1,28 +0,0 @@
1
- #pragma once
2
-
3
- #include "HybridNitroSQLiteQueryResultSpec.hpp"
4
- #include "types.hpp"
5
- #include <map>
6
-
7
- using namespace margelo::rnnitrosqlite;
8
-
9
- namespace margelo::nitro::rnnitrosqlite {
10
-
11
- class HybridNitroSQLiteQueryResult : public HybridNitroSQLiteQueryResultSpec {
12
- public:
13
- HybridNitroSQLiteQueryResult() : HybridObject(TAG) {}
14
- HybridNitroSQLiteQueryResult(SQLiteExecuteQueryResult&& result) : HybridObject(TAG), _result(std::move(result)) {}
15
-
16
- private:
17
- SQLiteExecuteQueryResult _result;
18
-
19
- public:
20
- // Properties
21
- std::optional<double> getInsertId() override;
22
- double getRowsAffected() override;
23
- SQLiteQueryResults getResults() override;
24
- std::optional<NitroSQLiteQueryResultRows> getRows() override;
25
- std::optional<SQLiteQueryTableMetadata> getMetadata() override;
26
- };
27
-
28
- } // namespace margelo::nitro::rnnitrosqlite
@@ -1,99 +0,0 @@
1
- ///
2
- /// NitroSQLiteQueryResultRows.hpp
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © Marc Rousavy @ Margelo
6
- ///
7
-
8
- #pragma once
9
-
10
- #if __has_include(<NitroModules/JSIConverter.hpp>)
11
- #include <NitroModules/JSIConverter.hpp>
12
- #else
13
- #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
- #endif
15
- #if __has_include(<NitroModules/NitroDefines.hpp>)
16
- #include <NitroModules/NitroDefines.hpp>
17
- #else
18
- #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
- #endif
20
- #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
- #include <NitroModules/JSIHelpers.hpp>
22
- #else
23
- #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
- #endif
25
- #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
- #include <NitroModules/PropNameIDCache.hpp>
27
- #else
28
- #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
- #endif
30
-
31
-
32
-
33
- #include <string>
34
- #include <NitroModules/Null.hpp>
35
- #include <NitroModules/ArrayBuffer.hpp>
36
- #include <variant>
37
- #include <unordered_map>
38
- #include <vector>
39
- #include <optional>
40
- #include <NitroModules/Promise.hpp>
41
- #include <functional>
42
-
43
- namespace margelo::nitro::rnnitrosqlite {
44
-
45
- /**
46
- * A struct which can be represented as a JavaScript object (NitroSQLiteQueryResultRows).
47
- */
48
- struct NitroSQLiteQueryResultRows final {
49
- public:
50
- std::vector<std::unordered_map<std::string, std::variant<nitro::NullType, bool, std::shared_ptr<ArrayBuffer>, std::string, double>>> _array SWIFT_PRIVATE;
51
- double length SWIFT_PRIVATE;
52
- std::function<std::shared_ptr<Promise<std::optional<std::unordered_map<std::string, std::variant<nitro::NullType, bool, std::shared_ptr<ArrayBuffer>, std::string, double>>>>>(double /* idx */)> item SWIFT_PRIVATE;
53
-
54
- public:
55
- NitroSQLiteQueryResultRows() = default;
56
- explicit NitroSQLiteQueryResultRows(std::vector<std::unordered_map<std::string, std::variant<nitro::NullType, bool, std::shared_ptr<ArrayBuffer>, std::string, double>>> _array, double length, std::function<std::shared_ptr<Promise<std::optional<std::unordered_map<std::string, std::variant<nitro::NullType, bool, std::shared_ptr<ArrayBuffer>, std::string, double>>>>>(double /* idx */)> item): _array(_array), length(length), item(item) {}
57
-
58
- public:
59
- // NitroSQLiteQueryResultRows is not equatable because these properties are not equatable: item
60
- };
61
-
62
- } // namespace margelo::nitro::rnnitrosqlite
63
-
64
- namespace margelo::nitro {
65
-
66
- // C++ NitroSQLiteQueryResultRows <> JS NitroSQLiteQueryResultRows (object)
67
- template <>
68
- struct JSIConverter<margelo::nitro::rnnitrosqlite::NitroSQLiteQueryResultRows> final {
69
- static inline margelo::nitro::rnnitrosqlite::NitroSQLiteQueryResultRows fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
70
- jsi::Object obj = arg.asObject(runtime);
71
- return margelo::nitro::rnnitrosqlite::NitroSQLiteQueryResultRows(
72
- JSIConverter<std::vector<std::unordered_map<std::string, std::variant<nitro::NullType, bool, std::shared_ptr<ArrayBuffer>, std::string, double>>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "_array"))),
73
- JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "length"))),
74
- JSIConverter<std::function<std::shared_ptr<Promise<std::optional<std::unordered_map<std::string, std::variant<nitro::NullType, bool, std::shared_ptr<ArrayBuffer>, std::string, double>>>>>(double)>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "item")))
75
- );
76
- }
77
- static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rnnitrosqlite::NitroSQLiteQueryResultRows& arg) {
78
- jsi::Object obj(runtime);
79
- obj.setProperty(runtime, PropNameIDCache::get(runtime, "_array"), JSIConverter<std::vector<std::unordered_map<std::string, std::variant<nitro::NullType, bool, std::shared_ptr<ArrayBuffer>, std::string, double>>>>::toJSI(runtime, arg._array));
80
- obj.setProperty(runtime, PropNameIDCache::get(runtime, "length"), JSIConverter<double>::toJSI(runtime, arg.length));
81
- obj.setProperty(runtime, PropNameIDCache::get(runtime, "item"), JSIConverter<std::function<std::shared_ptr<Promise<std::optional<std::unordered_map<std::string, std::variant<nitro::NullType, bool, std::shared_ptr<ArrayBuffer>, std::string, double>>>>>(double)>>::toJSI(runtime, arg.item));
82
- return obj;
83
- }
84
- static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
85
- if (!value.isObject()) {
86
- return false;
87
- }
88
- jsi::Object obj = value.getObject(runtime);
89
- if (!nitro::isPlainObject(runtime, obj)) {
90
- return false;
91
- }
92
- if (!JSIConverter<std::vector<std::unordered_map<std::string, std::variant<nitro::NullType, bool, std::shared_ptr<ArrayBuffer>, std::string, double>>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "_array")))) return false;
93
- if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "length")))) return false;
94
- if (!JSIConverter<std::function<std::shared_ptr<Promise<std::optional<std::unordered_map<std::string, std::variant<nitro::NullType, bool, std::shared_ptr<ArrayBuffer>, std::string, double>>>>>(double)>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "item")))) return false;
95
- return true;
96
- }
97
- };
98
-
99
- } // namespace margelo::nitro