@op-engineering/op-sqlite 11.2.14 → 11.2.15

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.
@@ -19,79 +19,80 @@ namespace jsi = facebook::jsi;
19
19
  namespace react = facebook::react;
20
20
 
21
21
  struct PendingReactiveInvocation {
22
- std::string db_name;
23
- std::string table;
24
- std::string rowid;
22
+ std::string db_name;
23
+ std::string table;
24
+ std::string rowid;
25
25
  };
26
26
 
27
27
  struct TableRowDiscriminator {
28
- std::string table;
29
- std::vector<int> ids;
28
+ std::string table;
29
+ std::vector<int> ids;
30
30
  };
31
31
 
32
32
  struct ReactiveQuery {
33
33
  #ifndef OP_SQLITE_USE_LIBSQL
34
- sqlite3_stmt *stmt;
34
+ sqlite3_stmt *stmt;
35
35
  #endif
36
- std::vector<TableRowDiscriminator> discriminators;
37
- std::shared_ptr<jsi::Value> callback;
36
+ std::vector<TableRowDiscriminator> discriminators;
37
+ std::shared_ptr<jsi::Value> callback;
38
38
  };
39
39
 
40
40
  class JSI_EXPORT DBHostObject : public jsi::HostObject {
41
- public:
42
- // Normal constructor shared between all backends
43
- DBHostObject(jsi::Runtime &rt, std::string &base_path,
44
- std::shared_ptr<react::CallInvoker> invoker,
45
- std::string &db_name, std::string &path,
46
- std::string &crsqlite_path, std::string &sqlite_vec_path,
47
- std::string &encryption_key);
41
+ public:
42
+ // Normal constructor shared between all backends
43
+ DBHostObject(jsi::Runtime &rt, std::string &base_path,
44
+ std::shared_ptr<react::CallInvoker> invoker,
45
+ std::string &db_name, std::string &path,
46
+ std::string &crsqlite_path, std::string &sqlite_vec_path,
47
+ std::string &encryption_key);
48
48
 
49
49
  #ifdef OP_SQLITE_USE_LIBSQL
50
- // Constructor for remoteOpen, purely for remote databases
51
- DBHostObject(jsi::Runtime &rt, std::string &url, std::string &auth_token,
52
- std::shared_ptr<react::CallInvoker> invoker);
50
+ // Constructor for remoteOpen, purely for remote databases
51
+ DBHostObject(jsi::Runtime &rt, std::string &url, std::string &auth_token,
52
+ std::shared_ptr<react::CallInvoker> invoker);
53
53
 
54
- // Constructor for a local database with remote sync
55
- DBHostObject(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
56
- std::string &db_name, std::string &path, std::string &url,
57
- std::string &auth_token, int sync_interval);
54
+ // Constructor for a local database with remote sync
55
+ DBHostObject(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
56
+ std::string &db_name, std::string &path, std::string &url,
57
+ std::string &auth_token, int sync_interval);
58
58
  #endif
59
59
 
60
- std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
61
- jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) override;
62
- void set(jsi::Runtime &rt, const jsi::PropNameID &name,
63
- const jsi::Value &value) override;
64
- void on_update(const std::string &table, const std::string &operation,
65
- long long row_id);
66
- void on_commit();
67
- void on_rollback();
68
- void invalidate();
69
- ~DBHostObject() override;
60
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
61
+ jsi::Value get(jsi::Runtime &rt,
62
+ const jsi::PropNameID &propNameID) override;
63
+ void set(jsi::Runtime &rt, const jsi::PropNameID &name,
64
+ const jsi::Value &value) override;
65
+ void on_update(const std::string &table, const std::string &operation,
66
+ long long row_id);
67
+ void on_commit();
68
+ void on_rollback();
69
+ void invalidate();
70
+ ~DBHostObject() override;
70
71
 
71
- private:
72
- std::set<std::shared_ptr<ReactiveQuery>> pending_reactive_queries;
73
- void auto_register_update_hook();
74
- void create_jsi_functions();
75
- void
76
- flush_pending_reactive_queries(const std::shared_ptr<jsi::Value> &resolve);
72
+ private:
73
+ std::set<std::shared_ptr<ReactiveQuery>> pending_reactive_queries;
74
+ void auto_register_update_hook();
75
+ void create_jsi_functions();
76
+ void
77
+ flush_pending_reactive_queries(const std::shared_ptr<jsi::Value> &resolve);
77
78
 
78
- std::unordered_map<std::string, jsi::Value> function_map;
79
- std::string base_path;
80
- std::shared_ptr<react::CallInvoker> invoker;
81
- std::shared_ptr<ThreadPool> _thread_pool;
82
- std::string db_name;
83
- std::shared_ptr<jsi::Value> update_hook_callback;
84
- std::shared_ptr<jsi::Value> commit_hook_callback;
85
- std::shared_ptr<jsi::Value> rollback_hook_callback;
86
- jsi::Runtime &rt;
87
- std::vector<std::shared_ptr<ReactiveQuery>> reactive_queries;
88
- std::vector<PendingReactiveInvocation> pending_reactive_invocations;
89
- bool is_update_hook_registered = false;
90
- bool invalidated = false;
79
+ std::unordered_map<std::string, jsi::Value> function_map;
80
+ std::string base_path;
81
+ std::shared_ptr<react::CallInvoker> invoker;
82
+ std::shared_ptr<ThreadPool> _thread_pool;
83
+ std::string db_name;
84
+ std::shared_ptr<jsi::Value> update_hook_callback;
85
+ std::shared_ptr<jsi::Value> commit_hook_callback;
86
+ std::shared_ptr<jsi::Value> rollback_hook_callback;
87
+ jsi::Runtime &rt;
88
+ std::vector<std::shared_ptr<ReactiveQuery>> reactive_queries;
89
+ std::vector<PendingReactiveInvocation> pending_reactive_invocations;
90
+ bool is_update_hook_registered = false;
91
+ bool invalidated = false;
91
92
  #ifdef OP_SQLITE_USE_LIBSQL
92
- DB db;
93
+ DB db;
93
94
  #else
94
- sqlite3 *db;
95
+ sqlite3 *db;
95
96
  #endif
96
97
  };
97
98
 
@@ -9,63 +9,64 @@ namespace jsi = facebook::jsi;
9
9
 
10
10
  DumbHostObject::DumbHostObject(
11
11
  std::shared_ptr<std::vector<SmartHostObject>> metadata) {
12
- this->metadata = metadata;
12
+ this->metadata = metadata;
13
13
  };
14
14
 
15
15
  std::vector<jsi::PropNameID>
16
16
  DumbHostObject::getPropertyNames(jsi::Runtime &rt) {
17
- std::vector<jsi::PropNameID> keys;
17
+ std::vector<jsi::PropNameID> keys;
18
18
 
19
- for (auto field : *metadata) {
20
- // TODO improve this by generating the propName once on metadata creation
21
- keys.push_back(jsi::PropNameID::forAscii(
22
- rt, std::get<std::string>(field.fields[0].second)));
23
- }
19
+ for (auto field : *metadata) {
20
+ // TODO improve this by generating the propName once on metadata
21
+ // creation
22
+ keys.push_back(jsi::PropNameID::forAscii(
23
+ rt, std::get<std::string>(field.fields[0].second)));
24
+ }
24
25
 
25
- return keys;
26
+ return keys;
26
27
  }
27
28
 
28
29
  jsi::Value DumbHostObject::get(jsi::Runtime &rt,
29
30
  const jsi::PropNameID &propNameID) {
30
31
 
31
- auto name = propNameID.utf8(rt);
32
- auto fields = metadata.get();
33
- for (int i = 0; i < fields->size(); i++) {
34
- auto fieldName = std::get<std::string>(fields->at(i).fields[0].second);
35
- if (fieldName == name) {
36
- return to_jsi(rt, values.at(i));
32
+ auto name = propNameID.utf8(rt);
33
+ auto fields = metadata.get();
34
+ for (int i = 0; i < fields->size(); i++) {
35
+ auto fieldName = std::get<std::string>(fields->at(i).fields[0].second);
36
+ if (fieldName == name) {
37
+ return to_jsi(rt, values.at(i));
38
+ }
37
39
  }
38
- }
39
40
 
40
- for (auto pairField : ownValues) {
41
- if (name == pairField.first) {
42
- return to_jsi(rt, pairField.second);
41
+ for (auto pairField : ownValues) {
42
+ if (name == pairField.first) {
43
+ return to_jsi(rt, pairField.second);
44
+ }
43
45
  }
44
- }
45
46
 
46
- return {};
47
+ return {};
47
48
  }
48
49
 
49
50
  void DumbHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name,
50
51
  const jsi::Value &value) {
51
- auto key = name.utf8(rt);
52
- auto fields = metadata.get();
53
- for (int i = 0; i < fields->size(); i++) {
54
- auto fieldName = std::get<std::string>(fields->at(i).fields[0].second);
55
- if (fieldName == key) {
56
- values[i] = to_variant(rt, value);
57
- return;
52
+ auto key = name.utf8(rt);
53
+ auto fields = metadata.get();
54
+ for (int i = 0; i < fields->size(); i++) {
55
+ auto fieldName = std::get<std::string>(fields->at(i).fields[0].second);
56
+ if (fieldName == key) {
57
+ values[i] = to_variant(rt, value);
58
+ return;
59
+ }
58
60
  }
59
- }
60
61
 
61
- for (auto pairField : ownValues) {
62
- if (key == pairField.first) {
63
- pairField.second = to_variant(rt, value);
64
- return;
62
+ for (auto pairField : ownValues) {
63
+ if (key == pairField.first) {
64
+ pairField.second = to_variant(rt, value);
65
+ return;
66
+ }
65
67
  }
66
- }
67
68
 
68
- ownValues.push_back(std::make_pair(key, to_variant(rt, value)));
69
+ ownValues.push_back(std::make_pair(key, to_variant(rt, value)));
69
70
  }
70
71
 
71
72
  } // namespace opsqlite
@@ -12,24 +12,25 @@ namespace opsqlite {
12
12
  namespace jsi = facebook::jsi;
13
13
 
14
14
  class JSI_EXPORT DumbHostObject : public jsi::HostObject {
15
- public:
16
- DumbHostObject() = default;
15
+ public:
16
+ DumbHostObject() = default;
17
17
 
18
- explicit DumbHostObject(
19
- std::shared_ptr<std::vector<SmartHostObject>> metadata);
18
+ explicit DumbHostObject(
19
+ std::shared_ptr<std::vector<SmartHostObject>> metadata);
20
20
 
21
- std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
21
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
22
22
 
23
- jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) override;
23
+ jsi::Value get(jsi::Runtime &rt,
24
+ const jsi::PropNameID &propNameID) override;
24
25
 
25
- void set(jsi::Runtime &rt, const jsi::PropNameID &name,
26
- const jsi::Value &value) override;
26
+ void set(jsi::Runtime &rt, const jsi::PropNameID &name,
27
+ const jsi::Value &value) override;
27
28
 
28
- std::vector<JSVariant> values;
29
+ std::vector<JSVariant> values;
29
30
 
30
- std::shared_ptr<std::vector<SmartHostObject>> metadata;
31
+ std::shared_ptr<std::vector<SmartHostObject>> metadata;
31
32
 
32
- std::vector<std::pair<std::string, JSVariant>> ownValues;
33
+ std::vector<std::pair<std::string, JSVariant>> ownValues;
33
34
  };
34
35
 
35
36
  } // namespace opsqlite
@@ -13,132 +13,138 @@ namespace jsi = facebook::jsi;
13
13
 
14
14
  std::vector<jsi::PropNameID>
15
15
  PreparedStatementHostObject::getPropertyNames(jsi::Runtime &rt) {
16
- std::vector<jsi::PropNameID> keys;
16
+ std::vector<jsi::PropNameID> keys;
17
17
 
18
- return keys;
18
+ return keys;
19
19
  }
20
20
 
21
21
  jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
22
22
  const jsi::PropNameID &propNameID) {
23
- auto name = propNameID.utf8(rt);
23
+ auto name = propNameID.utf8(rt);
24
24
 
25
- if (name == "bind") {
26
- return HOSTFN("bind") {
27
- if (_stmt == nullptr) {
28
- throw std::runtime_error("statement has been freed");
29
- }
25
+ if (name == "bind") {
26
+ return HOSTFN("bind") {
27
+ if (_stmt == nullptr) {
28
+ throw std::runtime_error("statement has been freed");
29
+ }
30
30
 
31
- const jsi::Value &js_params = args[0];
32
- std::vector<JSVariant> params = to_variant_vec(rt, js_params);
31
+ const jsi::Value &js_params = args[0];
32
+ std::vector<JSVariant> params = to_variant_vec(rt, js_params);
33
33
 
34
- auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
34
+ auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
35
35
  auto promise = promiseCtr.callAsConstructor(
36
36
  rt, HOSTFN("executor") {
37
- auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
38
- auto reject = std::make_shared<jsi::Value>(rt, args[1]);
39
- auto task = [&rt, this, resolve, reject,
40
- invoker = this->_js_call_invoker, params]() {
41
- try {
37
+ auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
38
+ auto reject = std::make_shared<jsi::Value>(rt, args[1]);
39
+ auto task = [&rt, this, resolve, reject,
40
+ invoker = this->_js_call_invoker, params]() {
41
+ try {
42
42
  #ifdef OP_SQLITE_USE_LIBSQL
43
- opsqlite_libsql_bind_statement(_stmt, &params);
43
+ opsqlite_libsql_bind_statement(_stmt, &params);
44
44
  #else
45
- opsqlite_bind_statement(_stmt, &params);
45
+ opsqlite_bind_statement(_stmt, &params);
46
46
  #endif
47
- invoker->invokeAsync([&rt, resolve] {
48
- resolve->asObject(rt).asFunction(rt).call(rt, {});
49
- });
50
- } catch (const std::runtime_error &e) {
51
- invoker->invokeAsync([&rt, e, reject] {
52
- auto errorCtr = rt.global().getPropertyAsFunction(rt, "Error");
53
- auto error = errorCtr.callAsConstructor(
54
- rt, jsi::String::createFromUtf8(rt, e.what()));
55
- reject->asObject(rt).asFunction(rt).call(rt, error);
56
- });
57
- } catch (const std::exception &e) {
58
- invoker->invokeAsync([&rt, e, reject] {
59
- auto errorCtr = rt.global().getPropertyAsFunction(rt, "Error");
60
- auto error = errorCtr.callAsConstructor(
61
- rt, jsi::String::createFromUtf8(rt, e.what()));
62
- reject->asObject(rt).asFunction(rt).call(rt, error);
63
- });
64
- }
65
- };
66
-
67
- _thread_pool->queueWork(task);
68
-
69
- return {};
47
+ invoker->invokeAsync([&rt, resolve] {
48
+ resolve->asObject(rt).asFunction(rt).call(rt, {});
49
+ });
50
+ } catch (const std::runtime_error &e) {
51
+ invoker->invokeAsync([&rt, e, reject] {
52
+ auto errorCtr =
53
+ rt.global().getPropertyAsFunction(rt, "Error");
54
+ auto error = errorCtr.callAsConstructor(
55
+ rt, jsi::String::createFromUtf8(rt, e.what()));
56
+ reject->asObject(rt).asFunction(rt).call(rt, error);
57
+ });
58
+ } catch (const std::exception &e) {
59
+ invoker->invokeAsync([&rt, e, reject] {
60
+ auto errorCtr =
61
+ rt.global().getPropertyAsFunction(rt, "Error");
62
+ auto error = errorCtr.callAsConstructor(
63
+ rt, jsi::String::createFromUtf8(rt, e.what()));
64
+ reject->asObject(rt).asFunction(rt).call(rt, error);
65
+ });
66
+ }
67
+ };
68
+
69
+ _thread_pool->queueWork(task);
70
+
71
+ return {};
70
72
  }));
71
73
  return promise;
72
- });
73
- }
74
+ });
75
+ }
74
76
 
75
- if (name == "execute") {
76
- return HOSTFN("execute") {
77
- if (_stmt == nullptr) {
78
- throw std::runtime_error("statement has been freed");
79
- }
77
+ if (name == "execute") {
78
+ return HOSTFN("execute") {
79
+ if (_stmt == nullptr) {
80
+ throw std::runtime_error("statement has been freed");
81
+ }
80
82
 
81
- auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
83
+ auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
82
84
  auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor") {
83
- auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
84
- auto reject = std::make_shared<jsi::Value>(rt, args[1]);
85
-
86
- auto task = [&rt, this, resolve, reject,
87
- invoker = this->_js_call_invoker]() {
88
- std::vector<DumbHostObject> results;
89
- std::shared_ptr<std::vector<SmartHostObject>> metadata =
90
- std::make_shared<std::vector<SmartHostObject>>();
91
- try {
85
+ auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
86
+ auto reject = std::make_shared<jsi::Value>(rt, args[1]);
87
+
88
+ auto task = [&rt, this, resolve, reject,
89
+ invoker = this->_js_call_invoker]() {
90
+ std::vector<DumbHostObject> results;
91
+ std::shared_ptr<std::vector<SmartHostObject>> metadata =
92
+ std::make_shared<std::vector<SmartHostObject>>();
93
+ try {
92
94
  #ifdef OP_SQLITE_USE_LIBSQL
93
- auto status = opsqlite_libsql_execute_prepared_statement(
94
- _db, _stmt, &results, metadata);
95
+ auto status =
96
+ opsqlite_libsql_execute_prepared_statement(
97
+ _db, _stmt, &results, metadata);
95
98
  #else
96
- auto status = opsqlite_execute_prepared_statement(
97
- _db, _stmt, &results, metadata);
99
+ auto status = opsqlite_execute_prepared_statement(
100
+ _db, _stmt, &results, metadata);
98
101
  #endif
99
- invoker->invokeAsync(
100
- [&rt, status = std::move(status),
101
- results =
102
- std::make_shared<std::vector<DumbHostObject>>(results),
103
- metadata, resolve] {
104
- auto jsiResult =
105
- create_result(rt, status, results.get(), metadata);
106
- resolve->asObject(rt).asFunction(rt).call(
107
- rt, std::move(jsiResult));
108
- });
109
- } catch (std::exception &exc) {
110
- invoker->invokeAsync([&rt, &exc, reject] {
111
- auto errorCtr = rt.global().getPropertyAsFunction(rt, "Error");
112
- auto error = errorCtr.callAsConstructor(
113
- rt, jsi::String::createFromUtf8(rt, exc.what()));
114
- reject->asObject(rt).asFunction(rt).call(rt, error);
115
- });
116
- }
117
- };
118
-
119
- _thread_pool->queueWork(task);
120
-
121
- return {};
102
+ invoker->invokeAsync(
103
+ [&rt, status = std::move(status),
104
+ results =
105
+ std::make_shared<std::vector<DumbHostObject>>(
106
+ results),
107
+ metadata, resolve] {
108
+ auto jsiResult = create_result(
109
+ rt, status, results.get(), metadata);
110
+ resolve->asObject(rt).asFunction(rt).call(
111
+ rt, std::move(jsiResult));
112
+ });
113
+ } catch (std::exception &exc) {
114
+ invoker->invokeAsync([&rt, &exc, reject] {
115
+ auto errorCtr =
116
+ rt.global().getPropertyAsFunction(rt, "Error");
117
+ auto error = errorCtr.callAsConstructor(
118
+ rt,
119
+ jsi::String::createFromUtf8(rt, exc.what()));
120
+ reject->asObject(rt).asFunction(rt).call(rt, error);
121
+ });
122
+ }
123
+ };
124
+
125
+ _thread_pool->queueWork(task);
126
+
127
+ return {};
122
128
  }));
123
129
 
124
130
  return promise;
125
- });
126
- }
131
+ });
132
+ }
127
133
 
128
- return {};
134
+ return {};
129
135
  }
130
136
 
131
137
  PreparedStatementHostObject::~PreparedStatementHostObject() {
132
138
  #ifdef OP_SQLITE_USE_LIBSQL
133
- if (_stmt != nullptr) {
134
- libsql_free_stmt(_stmt);
135
- _stmt = nullptr;
136
- }
139
+ if (_stmt != nullptr) {
140
+ libsql_free_stmt(_stmt);
141
+ _stmt = nullptr;
142
+ }
137
143
  #else
138
- if (_stmt != nullptr) {
139
- // sqlite3_finalize(_stmt);
140
- _stmt = nullptr;
141
- }
144
+ if (_stmt != nullptr) {
145
+ // sqlite3_finalize(_stmt);
146
+ _stmt = nullptr;
147
+ }
142
148
  #endif
143
149
  }
144
150
 
@@ -4,8 +4,8 @@
4
4
  #include <jsi/jsi.h>
5
5
  #include <memory>
6
6
  #ifdef OP_SQLITE_USE_LIBSQL
7
- #include "libsql/bridge.h"
8
7
  #include "libsql.h"
8
+ #include "libsql/bridge.h"
9
9
  #else
10
10
  #include <sqlite3.h>
11
11
  #endif
@@ -18,40 +18,42 @@ namespace jsi = facebook::jsi;
18
18
  namespace react = facebook::react;
19
19
 
20
20
  class PreparedStatementHostObject : public jsi::HostObject {
21
- public:
21
+ public:
22
22
  #ifdef OP_SQLITE_USE_LIBSQL
23
- PreparedStatementHostObject(
24
- DB const &db, std::string name, libsql_stmt_t stmt,
25
- std::shared_ptr<react::CallInvoker> js_call_invoker,
26
- std::shared_ptr<ThreadPool> thread_pool)
27
- : _db(db), _name(std::move(name)), _stmt(stmt), _js_call_invoker(js_call_invoker),
28
- _thread_pool(thread_pool) {};
23
+ PreparedStatementHostObject(
24
+ DB const &db, std::string name, libsql_stmt_t stmt,
25
+ std::shared_ptr<react::CallInvoker> js_call_invoker,
26
+ std::shared_ptr<ThreadPool> thread_pool)
27
+ : _db(db), _name(std::move(name)), _stmt(stmt),
28
+ _js_call_invoker(js_call_invoker), _thread_pool(thread_pool) {};
29
29
  #else
30
- PreparedStatementHostObject(
31
- sqlite3 *db, std::string name, sqlite3_stmt *stmt,
32
- std::shared_ptr<react::CallInvoker> js_call_invoker,
33
- std::shared_ptr<ThreadPool> thread_pool)
34
- : _db(db), _name(std::move(name)), _stmt(stmt), _js_call_invoker(std::move(js_call_invoker)),
35
- _thread_pool(std::move(thread_pool)) {};
30
+ PreparedStatementHostObject(
31
+ sqlite3 *db, std::string name, sqlite3_stmt *stmt,
32
+ std::shared_ptr<react::CallInvoker> js_call_invoker,
33
+ std::shared_ptr<ThreadPool> thread_pool)
34
+ : _db(db), _name(std::move(name)), _stmt(stmt),
35
+ _js_call_invoker(std::move(js_call_invoker)),
36
+ _thread_pool(std::move(thread_pool)) {};
36
37
  #endif
37
- ~PreparedStatementHostObject() override;
38
+ ~PreparedStatementHostObject() override;
38
39
 
39
- std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
40
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
40
41
 
41
- jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) override;
42
+ jsi::Value get(jsi::Runtime &rt,
43
+ const jsi::PropNameID &propNameID) override;
42
44
 
43
- private:
44
- std::string _name;
45
+ private:
46
+ std::string _name;
45
47
  #ifdef OP_SQLITE_USE_LIBSQL
46
- DB _db;
47
- libsql_stmt_t _stmt;
48
+ DB _db;
49
+ libsql_stmt_t _stmt;
48
50
  #else
49
- sqlite3 *_db;
50
- // This shouldn't be de-allocated until sqlite3_finalize is called on it
51
- sqlite3_stmt *_stmt;
51
+ sqlite3 *_db;
52
+ // This shouldn't be de-allocated until sqlite3_finalize is called on it
53
+ sqlite3_stmt *_stmt;
52
54
  #endif
53
- std::shared_ptr<react::CallInvoker> _js_call_invoker;
54
- std::shared_ptr<ThreadPool> _thread_pool;
55
+ std::shared_ptr<react::CallInvoker> _js_call_invoker;
56
+ std::shared_ptr<ThreadPool> _thread_pool;
55
57
  };
56
58
 
57
59
  } // namespace opsqlite
@@ -7,28 +7,28 @@ namespace jsi = facebook::jsi;
7
7
 
8
8
  std::vector<jsi::PropNameID>
9
9
  SmartHostObject::getPropertyNames(jsi::Runtime &rt) {
10
- std::vector<jsi::PropNameID> keys;
10
+ std::vector<jsi::PropNameID> keys;
11
11
 
12
- keys.reserve(fields.size());
13
- for (const auto& field : fields) {
14
- keys.emplace_back(jsi::PropNameID::forAscii(rt, field.first));
15
- }
12
+ keys.reserve(fields.size());
13
+ for (const auto &field : fields) {
14
+ keys.emplace_back(jsi::PropNameID::forAscii(rt, field.first));
15
+ }
16
16
 
17
- return keys;
17
+ return keys;
18
18
  }
19
19
 
20
20
  jsi::Value SmartHostObject::get(jsi::Runtime &rt,
21
21
  const jsi::PropNameID &propNameID) {
22
- auto name = propNameID.utf8(rt);
22
+ auto name = propNameID.utf8(rt);
23
23
 
24
- for (const auto& field : fields) {
25
- auto fieldName = field.first;
26
- if (fieldName == name) {
27
- return to_jsi(rt, field.second);
24
+ for (const auto &field : fields) {
25
+ auto fieldName = field.first;
26
+ if (fieldName == name) {
27
+ return to_jsi(rt, field.second);
28
+ }
28
29
  }
29
- }
30
30
 
31
- return {};
31
+ return {};
32
32
  }
33
33
 
34
34
  } // namespace opsqlite
@@ -10,14 +10,15 @@ namespace opsqlite {
10
10
  namespace jsi = facebook::jsi;
11
11
 
12
12
  class JSI_EXPORT SmartHostObject : public jsi::HostObject {
13
- public:
14
- SmartHostObject() = default;
13
+ public:
14
+ SmartHostObject() = default;
15
15
 
16
- std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
16
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
17
17
 
18
- jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) override;
18
+ jsi::Value get(jsi::Runtime &rt,
19
+ const jsi::PropNameID &propNameID) override;
19
20
 
20
- std::vector<std::pair<std::string, JSVariant>> fields;
21
+ std::vector<std::pair<std::string, JSVariant>> fields;
21
22
  };
22
23
 
23
24
  } // namespace opsqlite