@@ -19,8 +19,9 @@ namespace react = facebook::react;
1919#ifdef OP_SQLITE_USE_LIBSQL
2020void DBHostObject::flush_pending_reactive_queries (
2121 const std::shared_ptr<jsi::Value> &resolve) {
22- invoker->invokeAsync (
23- [resolve](jsi::Runtime &rt) { resolve->asObject (rt).asFunction (rt).call (rt, {}); });
22+ invoker->invokeAsync ([resolve](jsi::Runtime &rt) {
23+ resolve->asObject (rt).asFunction (rt).call (rt, {});
24+ });
2425}
2526#else
2627void DBHostObject::flush_pending_reactive_queries (
@@ -37,41 +38,45 @@ void DBHostObject::flush_pending_reactive_queries(
3738
3839 invoker->invokeAsync (
3940 [results = std::make_shared<std::vector<DumbHostObject>>(results),
40- callback = query->callback , metadata, status = std::move (status)](jsi::Runtime &rt) {
41+ callback = query->callback , metadata,
42+ status = std::move (status)](jsi::Runtime &rt) {
4143 auto jsiResult = create_result (rt, status, results.get (), metadata);
4244 callback->asObject (rt).asFunction (rt).call (rt, jsiResult);
4345 });
4446 }
4547
4648 pending_reactive_queries.clear ();
4749
48- invoker->invokeAsync (
49- [resolve](jsi::Runtime &rt) { resolve->asObject (rt).asFunction (rt).call (rt, {}); });
50+ invoker->invokeAsync ([resolve](jsi::Runtime &rt) {
51+ resolve->asObject (rt).asFunction (rt).call (rt, {});
52+ });
5053}
5154
5255void DBHostObject::on_commit () {
53- invoker->invokeAsync (
54- [this ](jsi::Runtime &rt) { commit_hook_callback->asObject (rt).asFunction (rt).call (rt); });
56+ invoker->invokeAsync ([this ](jsi::Runtime &rt) {
57+ commit_hook_callback->asObject (rt).asFunction (rt).call (rt);
58+ });
5559}
5660
5761void DBHostObject::on_rollback () {
58- invoker->invokeAsync (
59- [this ](jsi::Runtime &rt) { rollback_hook_callback->asObject (rt).asFunction (rt).call (rt); });
62+ invoker->invokeAsync ([this ](jsi::Runtime &rt) {
63+ rollback_hook_callback->asObject (rt).asFunction (rt).call (rt);
64+ });
6065}
6166
6267void DBHostObject::on_update (const std::string &table,
6368 const std::string &operation, long long row_id) {
6469 if (update_hook_callback != nullptr ) {
65- invoker->invokeAsync (
66- [callback = update_hook_callback, table, operation, row_id](jsi::Runtime &rt) {
67- auto res = jsi::Object (rt);
68- res.setProperty (rt, " table" , jsi::String::createFromUtf8 (rt, table));
69- res.setProperty (rt, " operation" ,
70- jsi::String::createFromUtf8 (rt, operation));
71- res.setProperty (rt, " rowId" , jsi::Value (static_cast <double >(row_id)));
72-
73- callback->asObject (rt).asFunction (rt).call (rt, res);
74- });
70+ invoker->invokeAsync ([callback = update_hook_callback, table, operation,
71+ row_id](jsi::Runtime &rt) {
72+ auto res = jsi::Object (rt);
73+ res.setProperty (rt, " table" , jsi::String::createFromUtf8 (rt, table));
74+ res.setProperty (rt, " operation" ,
75+ jsi::String::createFromUtf8 (rt, operation));
76+ res.setProperty (rt, " rowId" , jsi::Value (static_cast <double >(row_id)));
77+
78+ callback->asObject (rt).asFunction (rt).call (rt, res);
79+ });
7580 }
7681
7782 for (const auto &query_ptr : reactive_queries) {
@@ -144,7 +149,7 @@ void DBHostObject::auto_register_update_hook() {
144149DBHostObject::DBHostObject (jsi::Runtime &rt, std::string &url,
145150 std::string &auth_token)
146151 : db_name(url) {
147- _thread_pool = std::make_shared<ThreadPool>();
152+ thread_pool = std::make_shared<ThreadPool>();
148153 db = opsqlite_libsql_open_remote (url, auth_token);
149154
150155 create_jsi_functions (rt);
@@ -158,7 +163,7 @@ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &db_name,
158163 std::string &remote_encryption_key)
159164 : db_name(db_name) {
160165
161- _thread_pool = std::make_shared<ThreadPool>();
166+ thread_pool = std::make_shared<ThreadPool>();
162167
163168 db =
164169 opsqlite_libsql_open_sync (db_name, path, url, auth_token, sync_interval,
@@ -175,7 +180,7 @@ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &base_path,
175180 std::string &sqlite_vec_path,
176181 std::string &encryption_key)
177182 : base_path(base_path), db_name(db_name) {
178- _thread_pool = std::make_shared<ThreadPool>();
183+ thread_pool = std::make_shared<ThreadPool>();
179184
180185#ifdef OP_SQLITE_USE_SQLCIPHER
181186 db = opsqlite_open (db_name, path, crsqlite_path, sqlite_vec_path,
@@ -281,7 +286,7 @@ void DBHostObject::create_jsi_functions(jsi::Runtime &rt) {
281286 : std::vector<JSVariant>();
282287
283288 return promisify (
284- rt,
289+ rt, thread_pool,
285290 [this , query, params]() {
286291 std::vector<std::vector<JSVariant>> results;
287292#ifdef OP_SQLITE_USE_LIBSQL
@@ -341,7 +346,7 @@ void DBHostObject::create_jsi_functions(jsi::Runtime &rt) {
341346 : std::vector<JSVariant>();
342347
343348 return promisify (
344- rt,
349+ rt, thread_pool,
345350 [this , query, params]() {
346351#ifdef OP_SQLITE_USE_LIBSQL
347352 auto status = opsqlite_libsql_execute (db, query, ¶ms);
@@ -363,7 +368,7 @@ void DBHostObject::create_jsi_functions(jsi::Runtime &rt) {
363368 : std::vector<JSVariant>();
364369
365370 return promisify (
366- rt,
371+ rt, thread_pool,
367372 [this , query, params]() {
368373 std::vector<DumbHostObject> results;
369374 std::shared_ptr<std::vector<SmartHostObject>> metadata =
@@ -408,7 +413,7 @@ void DBHostObject::create_jsi_functions(jsi::Runtime &rt) {
408413 to_batch_arguments (rt, batchParams, &commands);
409414
410415 return promisify (
411- rt,
416+ rt, thread_pool,
412417 [this , commands]() {
413418#ifdef OP_SQLITE_USE_LIBSQL
414419 auto batchResult = opsqlite_libsql_execute_batch (db, &commands);
@@ -432,7 +437,7 @@ void DBHostObject::create_jsi_functions(jsi::Runtime &rt) {
432437 return {};
433438 });
434439
435- function_map[" setReservedBytes" ] =HFN (this ) {
440+ function_map[" setReservedBytes" ] = HFN (this ) {
436441 auto reserved_bytes = static_cast <int32_t >(args[0 ].asNumber ());
437442 opsqlite_libsql_set_reserved_bytes (db, reserved_bytes);
438443 return {};
@@ -451,7 +456,8 @@ void DBHostObject::create_jsi_functions(jsi::Runtime &rt) {
451456 const std::string sqlFileName = args[0 ].asString (rt).utf8 (rt);
452457
453458 return promisify (
454- rt, [this , sqlFileName]() { return import_sql_file (db, sqlFileName); },
459+ rt, thread_pool,
460+ [this , sqlFileName]() { return import_sql_file (db, sqlFileName); },
455461 [](jsi::Runtime &rt, std::any prev) {
456462 auto result = std::any_cast<BatchResult>(prev);
457463 auto res = jsi::Object (rt);
@@ -583,7 +589,8 @@ void DBHostObject::create_jsi_functions(jsi::Runtime &rt) {
583589 sqlite3_stmt *statement = opsqlite_prepare_statement (db, query);
584590#endif
585591 auto preparedStatementHostObject =
586- std::make_shared<PreparedStatementHostObject>(db, statement);
592+ std::make_shared<PreparedStatementHostObject>(db, statement,
593+ thread_pool);
587594
588595 return jsi::Object::createFromHostObject (rt, preparedStatementHostObject);
589596 });
@@ -621,7 +628,7 @@ void DBHostObject::create_jsi_functions(jsi::Runtime &rt) {
621628 flush_pending_reactive_queries (resolve);
622629 };
623630
624- _thread_pool ->queueWork (task);
631+ thread_pool ->queueWork (task);
625632
626633 return {};
627634 }));
@@ -664,7 +671,7 @@ void DBHostObject::invalidate() {
664671 }
665672
666673 invalidated = true ;
667- _thread_pool ->restartPool ();
674+ thread_pool ->restartPool ();
668675#ifdef OP_SQLITE_USE_LIBSQL
669676 opsqlite_libsql_close (db);
670677#else
0 commit comments