@@ -286,6 +286,51 @@ void osp::install(jsi::Runtime &rt,
286286 return {};
287287 });
288288
289+ auto refreshSchema = HOSTFN (" refreshSchema" , 1 ) {
290+ if (count == 0 ) {
291+ throw jsi::JSError (rt, " [react-native-quick-sqlite][refreshSchema] database name is required" );
292+ }
293+
294+ if (!args[0 ].isString ()) {
295+ throw jsi::JSError (rt, " [react-native-quick-sqlite][refreshSchema] database name must be a string" );
296+ }
297+
298+ std::string dbName = args[0 ].asString (rt).utf8 (rt);
299+
300+ auto promiseCtr = rt.global ().getPropertyAsFunction (rt, " Promise" );
301+ auto jsPromise = promiseCtr.callAsConstructor (rt, HOSTFN (" executor" , 2 ) {
302+ auto resolve = std::make_shared<jsi::Value>(rt, args[0 ]);
303+ auto reject = std::make_shared<jsi::Value>(rt, args[1 ]);
304+
305+ try {
306+ auto future = sqliteRefreshSchema (dbName);
307+
308+ // Waiting for the future to complete in a separate thread
309+ std::thread ([future = std::move (future), &rt, resolve, reject]() mutable {
310+ try {
311+ future.get ();
312+ invoker->invokeAsync ([&rt, resolve] {
313+ resolve->asObject (rt).asFunction (rt).call (rt);
314+ });
315+ } catch (const std::exception& exc) {
316+ invoker->invokeAsync ([&rt, reject, exc] {
317+ auto errorCtr = rt.global ().getPropertyAsFunction (rt, " Error" );
318+ auto error = errorCtr.callAsConstructor (rt, jsi::String::createFromUtf8 (rt, exc.what ()));
319+ reject->asObject (rt).asFunction (rt).call (rt, error);
320+ });
321+ }
322+ }).detach ();
323+
324+ } catch (const std::exception& exc) {
325+ invoker->invokeAsync ([&rt, &exc] { jsi::JSError (rt, exc.what ()); });
326+ }
327+
328+ return {};
329+ }));
330+
331+ return jsPromise;
332+ });
333+
289334 auto executeInContext = HOSTFN (" executeInContext" , 3 ) {
290335 if (count < 4 ) {
291336 throw jsi::JSError (rt,
@@ -500,6 +545,7 @@ void osp::install(jsi::Runtime &rt,
500545 module .setProperty (rt, " releaseLock" , move (releaseLock));
501546 module .setProperty (rt, " executeInContext" , move (executeInContext));
502547 module .setProperty (rt, " close" , move (close));
548+ module .setProperty (rt, " refreshSchema" , move (refreshSchema));
503549
504550 module .setProperty (rt, " attach" , move (attach));
505551 module .setProperty (rt, " detach" , move (detach));
0 commit comments