diff --git a/android/jniLibs/arm64-v8a/libsql_experimental.a b/android/jniLibs/arm64-v8a/libsql_experimental.a index 27e95e0a..1a5a8c0e 100644 Binary files a/android/jniLibs/arm64-v8a/libsql_experimental.a and b/android/jniLibs/arm64-v8a/libsql_experimental.a differ diff --git a/android/jniLibs/armeabi-v7a/libsql_experimental.a b/android/jniLibs/armeabi-v7a/libsql_experimental.a index 7c27b1b4..5fe9147a 100644 Binary files a/android/jniLibs/armeabi-v7a/libsql_experimental.a and b/android/jniLibs/armeabi-v7a/libsql_experimental.a differ diff --git a/android/jniLibs/x86/libsql_experimental.a b/android/jniLibs/x86/libsql_experimental.a index f17546e2..9388c75c 100644 Binary files a/android/jniLibs/x86/libsql_experimental.a and b/android/jniLibs/x86/libsql_experimental.a differ diff --git a/android/jniLibs/x86_64/libsql_experimental.a b/android/jniLibs/x86_64/libsql_experimental.a index 4232b656..4b83f347 100644 Binary files a/android/jniLibs/x86_64/libsql_experimental.a and b/android/jniLibs/x86_64/libsql_experimental.a differ diff --git a/cpp/DBHostObject.cpp b/cpp/DBHostObject.cpp index 13a0d9a2..225d2d27 100644 --- a/cpp/DBHostObject.cpp +++ b/cpp/DBHostObject.cpp @@ -150,11 +150,12 @@ DBHostObject::DBHostObject(jsi::Runtime &rt, std::shared_ptr invoker, std::shared_ptr thread_pool, std::string &db_name, std::string &path, - std::string &url, std::string &auth_token) + std::string &url, std::string &auth_token, + int sync_interval) : db_name(db_name), jsCallInvoker(invoker), thread_pool(thread_pool), rt(rt) { BridgeResult result = - opsqlite_libsql_open_sync(db_name, path, url, auth_token); + opsqlite_libsql_open_sync(db_name, path, url, auth_token, sync_interval); if (result.type == SQLiteError) { throw std::runtime_error(result.message); @@ -809,7 +810,7 @@ void DBHostObject::create_jsi_functions() { function_map["getDbPath"] = std::move(get_db_path); #ifdef OP_SQLITE_USE_LIBSQL function_map["sync"] = std::move(sync); -#else OP_SQLITE_USE_LIBSQL +#else function_map["loadFile"] = std::move(load_file); function_map["updateHook"] = std::move(update_hook); function_map["commitHook"] = std::move(commit_hook); diff --git a/cpp/DBHostObject.h b/cpp/DBHostObject.h index 262afd4f..4c5c15ab 100644 --- a/cpp/DBHostObject.h +++ b/cpp/DBHostObject.h @@ -43,7 +43,7 @@ class JSI_EXPORT DBHostObject : public jsi::HostObject { // Constructor for a local database with remote sync DBHostObject(jsi::Runtime &rt, std::shared_ptr invoker, std::shared_ptr thread_pool, std::string &db_name, - std::string &path, std::string &url, std::string &auth_token); + std::string &path, std::string &url, std::string &auth_token, int sync_interval); #endif std::vector getPropertyNames(jsi::Runtime &rt); diff --git a/cpp/bindings.cpp b/cpp/bindings.cpp index 7e9983b3..b2551b43 100644 --- a/cpp/bindings.cpp +++ b/cpp/bindings.cpp @@ -123,6 +123,7 @@ void install(jsi::Runtime &rt, std::shared_ptr invoker, std::string url = options.getProperty(rt, "url").asString(rt).utf8(rt); std::string auth_token = options.getProperty(rt, "authToken").asString(rt).utf8(rt); + int sync_interval = static_cast(options.getProperty(rt, "syncInterval").asNumber()); std::string location; if (options.hasProperty(rt, "location")) { @@ -140,7 +141,7 @@ void install(jsi::Runtime &rt, std::shared_ptr invoker, } std::shared_ptr db = std::make_shared( - rt, invoker, thread_pool, name, path, url, auth_token); + rt, invoker, thread_pool, name, path, url, auth_token, sync_interval); return jsi::Object::createFromHostObject(rt, db); }); #endif diff --git a/cpp/libsql/bridge.cpp b/cpp/libsql/bridge.cpp index 89533ff3..f9d23b3f 100644 --- a/cpp/libsql/bridge.cpp +++ b/cpp/libsql/bridge.cpp @@ -45,7 +45,8 @@ std::string opsqlite_get_db_path(std::string const &db_name, BridgeResult opsqlite_libsql_open_sync(std::string const &name, std::string const &base_path, std::string const &url, - std::string const &auth_token) { + std::string const &auth_token, + int sync_interval) { std::string path = opsqlite_get_db_path(name, base_path); int status = 0; @@ -53,9 +54,16 @@ BridgeResult opsqlite_libsql_open_sync(std::string const &name, libsql_connection_t c; const char *err = NULL; - status = libsql_open_sync_with_webpki( - path.c_str(), url.c_str(), auth_token.c_str(), '1', nullptr, &db, &err); - + libsql_config config = { + .db_path = path.c_str(), + .primary_url = url.c_str(), + .auth_token = auth_token.c_str(), + .read_your_writes = '1', + .encryption_key = nullptr, + .sync_interval = sync_interval, + .with_webpki = '1' + }; + status = libsql_open_sync_with_config(config, &db, &err); if (status != 0) { return {.type = SQLiteError, .message = err}; } diff --git a/cpp/libsql/bridge.h b/cpp/libsql/bridge.h index be354bb5..35d43946 100644 --- a/cpp/libsql/bridge.h +++ b/cpp/libsql/bridge.h @@ -36,7 +36,8 @@ BridgeResult opsqlite_libsql_open_remote(std::string const &url, BridgeResult opsqlite_libsql_open_sync(std::string const &name, std::string const &path, std::string const &url, - std::string const &auth_token); + std::string const &auth_token, + int sync_interval); BridgeResult opsqlite_libsql_close(std::string const &name); diff --git a/cpp/libsql/libsql.h b/cpp/libsql/libsql.h index c04baeed..952aec6b 100644 --- a/cpp/libsql/libsql.h +++ b/cpp/libsql/libsql.h @@ -27,6 +27,16 @@ typedef struct libsql_stmt libsql_stmt; typedef const libsql_database *libsql_database_t; +typedef struct { + const char *db_path; + const char *primary_url; + const char *auth_token; + char read_your_writes; + const char *encryption_key; + int sync_interval; + char with_webpki; +} libsql_config; + typedef const libsql_connection *libsql_connection_t; typedef const libsql_stmt *libsql_stmt_t; @@ -64,6 +74,8 @@ int libsql_open_sync_with_webpki(const char *db_path, libsql_database_t *out_db, const char **out_err_msg); +int libsql_open_sync_with_config(libsql_config config, libsql_database_t *out_db, const char **out_err_msg); + int libsql_open_ext(const char *url, libsql_database_t *out_db, const char **out_err_msg); int libsql_open_file(const char *url, libsql_database_t *out_db, const char **out_err_msg); diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 9fa4b822..79325530 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -7,7 +7,7 @@ PODS: - hermes-engine (0.74.0): - hermes-engine/Pre-built (= 0.74.0) - hermes-engine/Pre-built (0.74.0) - - op-sqlite (6.2.1): + - op-sqlite (7.0.0): - React - React-callinvoker - React-Core @@ -1358,7 +1358,7 @@ SPEC CHECKSUMS: fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120 glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2 hermes-engine: 6eae7edb2f563ee41d7c1f91f4f2e57c26d8a5c3 - op-sqlite: 52d3fbfad07bd80fd72fc86b110a29858ca2f450 + op-sqlite: a8bc5990d5d1774aafbbad7da708da10e03343e3 RCT-Folly: 045d6ecaa59d826c5736dfba0b2f4083ff8d79df RCTDeprecation: 3ca8b6c36bfb302e1895b72cfe7db0de0c92cd47 RCTRequired: 9fc183af555fd0c89a366c34c1ae70b7e03b1dc5 diff --git a/example/src/tests/queries.spec.ts b/example/src/tests/queries.spec.ts index c10b225c..95c1c925 100644 --- a/example/src/tests/queries.spec.ts +++ b/example/src/tests/queries.spec.ts @@ -7,7 +7,7 @@ import { type DB, type SQLBatchTuple, } from '@op-engineering/op-sqlite'; -import {beforeEach, describe, it, itOnly} from './MochaRNAdapter'; +import {beforeEach, describe, it} from './MochaRNAdapter'; import chai from 'chai'; const expect = chai.expect; @@ -50,12 +50,13 @@ export function queriesTests() { expect(res.rowsAffected).to.equal(0); }); - itOnly('Open a libsql database replicated to turso', async () => { + it('Open a libsql database replicated to turso', async () => { const remoteDb = openSync({ url: 'libsql://foo-ospfranco.turso.io', authToken: 'eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJhIjoicnciLCJpYXQiOjE3MTY5NTc5OTUsImlkIjoiZmJkNzZmMjYtZTliYy00MGJiLTlmYmYtMDczZjFmMjdjOGY4In0.U3cAWBOvcdiqoPN3MB81sco7x8CGOjjtZ1ZEf30uo2iPcAmOuJzcnAznmDlZ6SpQd4qzuJxE4mAIoRlOkpzgBQ', name: 'my replica', + syncInterval: 1000, }); const res = remoteDb.execute('SELECT 1'); diff --git a/ios/libsql.xcframework/ios-arm64/Headers/libsql.h b/ios/libsql.xcframework/ios-arm64/Headers/libsql.h index c04baeed..952aec6b 100644 --- a/ios/libsql.xcframework/ios-arm64/Headers/libsql.h +++ b/ios/libsql.xcframework/ios-arm64/Headers/libsql.h @@ -27,6 +27,16 @@ typedef struct libsql_stmt libsql_stmt; typedef const libsql_database *libsql_database_t; +typedef struct { + const char *db_path; + const char *primary_url; + const char *auth_token; + char read_your_writes; + const char *encryption_key; + int sync_interval; + char with_webpki; +} libsql_config; + typedef const libsql_connection *libsql_connection_t; typedef const libsql_stmt *libsql_stmt_t; @@ -64,6 +74,8 @@ int libsql_open_sync_with_webpki(const char *db_path, libsql_database_t *out_db, const char **out_err_msg); +int libsql_open_sync_with_config(libsql_config config, libsql_database_t *out_db, const char **out_err_msg); + int libsql_open_ext(const char *url, libsql_database_t *out_db, const char **out_err_msg); int libsql_open_file(const char *url, libsql_database_t *out_db, const char **out_err_msg); diff --git a/ios/libsql.xcframework/ios-arm64/libsql_experimental.a b/ios/libsql.xcframework/ios-arm64/libsql_experimental.a index 0d561a79..87f0cd11 100644 Binary files a/ios/libsql.xcframework/ios-arm64/libsql_experimental.a and b/ios/libsql.xcframework/ios-arm64/libsql_experimental.a differ diff --git a/ios/libsql.xcframework/ios-arm64_x86_64-simulator/Headers/libsql.h b/ios/libsql.xcframework/ios-arm64_x86_64-simulator/Headers/libsql.h index c04baeed..952aec6b 100644 --- a/ios/libsql.xcframework/ios-arm64_x86_64-simulator/Headers/libsql.h +++ b/ios/libsql.xcframework/ios-arm64_x86_64-simulator/Headers/libsql.h @@ -27,6 +27,16 @@ typedef struct libsql_stmt libsql_stmt; typedef const libsql_database *libsql_database_t; +typedef struct { + const char *db_path; + const char *primary_url; + const char *auth_token; + char read_your_writes; + const char *encryption_key; + int sync_interval; + char with_webpki; +} libsql_config; + typedef const libsql_connection *libsql_connection_t; typedef const libsql_stmt *libsql_stmt_t; @@ -64,6 +74,8 @@ int libsql_open_sync_with_webpki(const char *db_path, libsql_database_t *out_db, const char **out_err_msg); +int libsql_open_sync_with_config(libsql_config config, libsql_database_t *out_db, const char **out_err_msg); + int libsql_open_ext(const char *url, libsql_database_t *out_db, const char **out_err_msg); int libsql_open_file(const char *url, libsql_database_t *out_db, const char **out_err_msg); diff --git a/ios/libsql.xcframework/ios-arm64_x86_64-simulator/libsql_experimental.a b/ios/libsql.xcframework/ios-arm64_x86_64-simulator/libsql_experimental.a index a08164de..4e3b88b8 100644 Binary files a/ios/libsql.xcframework/ios-arm64_x86_64-simulator/libsql_experimental.a and b/ios/libsql.xcframework/ios-arm64_x86_64-simulator/libsql_experimental.a differ diff --git a/package.json b/package.json index 4169d047..8931a55a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@op-engineering/op-sqlite", - "version": "6.2.11", + "version": "7.0.0", "description": "Next generation SQLite for React Native", "main": "lib/commonjs/index", "module": "lib/module/index", diff --git a/src/index.ts b/src/index.ts index 4eb39699..86bc9428 100644 --- a/src/index.ts +++ b/src/index.ts @@ -425,6 +425,7 @@ export const openSync = (options: { authToken: string; name: string; location?: string; + syncInterval: number; }): DB => { if (!isLibsql()) { throw new Error('This function is only available for libsql');