@@ -20,7 +20,7 @@ namespace react = facebook::react;
2020void DBHostObject::flush_pending_reactive_queries (
2121 const std::shared_ptr<jsi::Value> &resolve) {
2222 invoker->invokeAsync (
23- [this , resolve]() { resolve->asObject (rt).asFunction (rt).call (rt, {}); });
23+ [resolve](jsi::Runtime &rt ) { resolve->asObject (rt).asFunction (rt).call (rt, {}); });
2424}
2525#else
2626void DBHostObject::flush_pending_reactive_queries (
@@ -36,8 +36,8 @@ void DBHostObject::flush_pending_reactive_queries(
3636 metadata);
3737
3838 invoker->invokeAsync (
39- [this , results = std::make_shared<std::vector<DumbHostObject>>(results),
40- callback = query->callback , metadata, status = std::move (status)] {
39+ [results = std::make_shared<std::vector<DumbHostObject>>(results),
40+ callback = query->callback , metadata, status = std::move (status)](jsi::Runtime &rt) {
4141 auto jsiResult = create_result (rt, status, results.get (), metadata);
4242 callback->asObject (rt).asFunction (rt).call (rt, jsiResult);
4343 });
@@ -46,24 +46,24 @@ void DBHostObject::flush_pending_reactive_queries(
4646 pending_reactive_queries.clear ();
4747
4848 invoker->invokeAsync (
49- [this , resolve]() { resolve->asObject (rt).asFunction (rt).call (rt, {}); });
49+ [resolve](jsi::Runtime &rt ) { resolve->asObject (rt).asFunction (rt).call (rt, {}); });
5050}
5151
5252void DBHostObject::on_commit () {
5353 invoker->invokeAsync (
54- [this ] { commit_hook_callback->asObject (rt).asFunction (rt).call (rt); });
54+ [this ](jsi::Runtime &rt) { commit_hook_callback->asObject (rt).asFunction (rt).call (rt); });
5555}
5656
5757void DBHostObject::on_rollback () {
5858 invoker->invokeAsync (
59- [this ] { rollback_hook_callback->asObject (rt).asFunction (rt).call (rt); });
59+ [this ](jsi::Runtime &rt) { rollback_hook_callback->asObject (rt).asFunction (rt).call (rt); });
6060}
6161
6262void DBHostObject::on_update (const std::string &table,
6363 const std::string &operation, long long row_id) {
6464 if (update_hook_callback != nullptr ) {
6565 invoker->invokeAsync (
66- [this , callback = update_hook_callback, table, operation, row_id] {
66+ [callback = update_hook_callback, table, operation, row_id](jsi::Runtime &rt) {
6767 auto res = jsi::Object (rt);
6868 res.setProperty (rt, " table" , jsi::String::createFromUtf8 (rt, table));
6969 res.setProperty (rt, " operation" ,
@@ -143,11 +143,11 @@ void DBHostObject::auto_register_update_hook() {
143143// Remote connection constructor
144144DBHostObject::DBHostObject (jsi::Runtime &rt, std::string &url,
145145 std::string &auth_token)
146- : db_name(url), rt(rt) {
146+ : db_name(url) {
147147 _thread_pool = std::make_shared<ThreadPool>();
148148 db = opsqlite_libsql_open_remote (url, auth_token);
149149
150- create_jsi_functions ();
150+ create_jsi_functions (rt );
151151}
152152
153153// Sync connection constructor
@@ -156,15 +156,15 @@ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &db_name,
156156 std::string &auth_token, int sync_interval,
157157 bool offline, std::string &encryption_key,
158158 std::string &remote_encryption_key)
159- : db_name(db_name), rt(rt) {
159+ : db_name(db_name) {
160160
161161 _thread_pool = std::make_shared<ThreadPool>();
162162
163163 db =
164164 opsqlite_libsql_open_sync (db_name, path, url, auth_token, sync_interval,
165165 offline, encryption_key, remote_encryption_key);
166166
167- create_jsi_functions ();
167+ create_jsi_functions (rt );
168168}
169169
170170#endif
@@ -174,7 +174,7 @@ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &base_path,
174174 std::string &crsqlite_path,
175175 std::string &sqlite_vec_path,
176176 std::string &encryption_key)
177- : base_path(base_path), db_name(db_name), rt(rt) {
177+ : base_path(base_path), db_name(db_name) {
178178 _thread_pool = std::make_shared<ThreadPool>();
179179
180180#ifdef OP_SQLITE_USE_SQLCIPHER
@@ -185,10 +185,10 @@ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &base_path,
185185#else
186186 db = opsqlite_open (db_name, path, crsqlite_path, sqlite_vec_path);
187187#endif
188- create_jsi_functions ();
188+ create_jsi_functions (rt );
189189};
190190
191- void DBHostObject::create_jsi_functions () {
191+ void DBHostObject::create_jsi_functions (jsi::Runtime &rt ) {
192192 function_map[" attach" ] = HFN (this ) {
193193 std::string secondary_db_path = std::string (base_path);
194194
@@ -427,19 +427,19 @@ void DBHostObject::create_jsi_functions() {
427427 });
428428
429429#ifdef OP_SQLITE_USE_LIBSQL
430- function_map[" sync" ] = HOSTFN ( " sync " ) {
430+ function_map[" sync" ] = HFN ( this ) {
431431 opsqlite_libsql_sync (db);
432432 return {};
433433 });
434434
435- function_map[" setReservedBytes" ] = HOSTFN ( " setReservedBytes " ) {
436- int32_t reserved_bytes = static_cast <int32_t >(args[0 ].asNumber ());
435+ function_map[" setReservedBytes" ] =HFN ( this ) {
436+ auto reserved_bytes = static_cast <int32_t >(args[0 ].asNumber ());
437437 opsqlite_libsql_set_reserved_bytes (db, reserved_bytes);
438438 return {};
439439 });
440440
441- function_map[" getReservedBytes" ] = HOSTFN ( " getReservedBytes " ) {
442- return jsi::Value ( opsqlite_libsql_get_reserved_bytes (db)) ;
441+ function_map[" getReservedBytes" ] = HFN ( this ) {
442+ return { opsqlite_libsql_get_reserved_bytes (db)} ;
443443 });
444444#else
445445 function_map[" loadFile" ] = HFN (this ) {
@@ -461,7 +461,7 @@ void DBHostObject::create_jsi_functions() {
461461 });
462462 });
463463
464- function_map[" updateHook" ] = HOSTFN ( " updateHook " ) {
464+ function_map[" updateHook" ] = HFN ( this ) {
465465 auto callback = std::make_shared<jsi::Value>(rt, args[0 ]);
466466
467467 if (callback->isUndefined () || callback->isNull ()) {
@@ -474,7 +474,7 @@ void DBHostObject::create_jsi_functions() {
474474 return {};
475475 });
476476
477- function_map[" commitHook" ] = HOSTFN ( " commitHook " ) {
477+ function_map[" commitHook" ] = HFN ( this ) {
478478 if (count < 1 ) {
479479 throw std::runtime_error (" [op-sqlite][commitHook] callback needed" );
480480 }
@@ -490,7 +490,7 @@ void DBHostObject::create_jsi_functions() {
490490 return {};
491491 });
492492
493- function_map[" rollbackHook" ] = HOSTFN ( " rollbackHook " ) {
493+ function_map[" rollbackHook" ] = HFN ( this ) {
494494 if (count < 1 ) {
495495 throw std::runtime_error (" [op-sqlite][rollbackHook] callback needed" );
496496 }
@@ -507,7 +507,7 @@ void DBHostObject::create_jsi_functions() {
507507 return {};
508508 });
509509
510- function_map[" loadExtension" ] = HOSTFN ( " loadExtension " ) {
510+ function_map[" loadExtension" ] = HFN ( this ) {
511511 auto path = args[0 ].asString (rt).utf8 (rt);
512512 std::string entry_point;
513513 if (count > 1 && args[1 ].isString ()) {
@@ -518,7 +518,7 @@ void DBHostObject::create_jsi_functions() {
518518 return {};
519519 });
520520
521- function_map[" reactiveExecute" ] = HOSTFN ( " reactiveExecute " ) {
521+ function_map[" reactiveExecute" ] = HFN ( this ) {
522522 auto query = args[0 ].asObject (rt);
523523
524524 const std::string query_str =
@@ -561,7 +561,7 @@ void DBHostObject::create_jsi_functions() {
561561
562562 auto_register_update_hook ();
563563
564- auto unsubscribe = HOSTFN ( " unsubscribe " ) {
564+ auto unsubscribe = HFN2 ( this , reactiveQuery ) {
565565 auto it = std::find (reactive_queries.begin (), reactive_queries.end (),
566566 reactiveQuery);
567567 if (it != reactive_queries.end ()) {
@@ -575,7 +575,7 @@ void DBHostObject::create_jsi_functions() {
575575 });
576576#endif
577577
578- function_map[" prepareStatement" ] = HOSTFN ( " prepareStatement " ) {
578+ function_map[" prepareStatement" ] = HFN ( this ) {
579579 auto query = args[0 ].asString (rt).utf8 (rt);
580580#ifdef OP_SQLITE_USE_LIBSQL
581581 libsql_stmt_t statement = opsqlite_libsql_prepare_statement (db, query);
@@ -588,7 +588,7 @@ void DBHostObject::create_jsi_functions() {
588588 return jsi::Object::createFromHostObject (rt, preparedStatementHostObject);
589589 });
590590
591- function_map[" getDbPath" ] = HOSTFN ( " getDbPath " ) {
591+ function_map[" getDbPath" ] = HFN ( this ) {
592592 std::string path = std::string (base_path);
593593
594594 if (count == 1 ) {
@@ -639,11 +639,11 @@ std::vector<jsi::PropNameID> DBHostObject::getPropertyNames(jsi::Runtime &_rt) {
639639 return keys;
640640}
641641
642- jsi::Value DBHostObject::get (jsi::Runtime &_rt ,
642+ jsi::Value DBHostObject::get (jsi::Runtime &rt ,
643643 const jsi::PropNameID &propNameID) {
644644 auto name = propNameID.utf8 (rt);
645645 if (function_map.count (name) != 1 ) {
646- return HOST_STATIC_FN (name. c_str () ) {
646+ return HFN (name) {
647647 throw std::runtime_error (
648648 " [op-sqlite] Function " + name +
649649 " not implemented for current backend (libsql or sqlcipher)" );
0 commit comments