@op-engineering/op-sqlite 15.0.6 → 15.1.0

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.
Files changed (55) hide show
  1. package/android/CMakeLists.txt +1 -1
  2. package/android/build.gradle +1 -1
  3. package/android/cpp-adapter.cpp +1 -1
  4. package/android/jniLibs/arm64-v8a/libsql_experimental.a +0 -0
  5. package/android/jniLibs/armeabi-v7a/libsql_experimental.a +0 -0
  6. package/android/jniLibs/x86/libsql_experimental.a +0 -0
  7. package/android/jniLibs/x86_64/libsql_experimental.a +0 -0
  8. package/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt +7 -9
  9. package/cpp/DBHostObject.cpp +470 -660
  10. package/cpp/DBHostObject.h +56 -58
  11. package/cpp/DumbHostObject.cpp +1 -1
  12. package/cpp/DumbHostObject.h +12 -13
  13. package/cpp/OPSqlite.cpp +207 -0
  14. package/cpp/OPThreadPool.cpp +79 -79
  15. package/cpp/OPThreadPool.h +28 -28
  16. package/cpp/PreparedStatementHostObject.cpp +87 -136
  17. package/cpp/PreparedStatementHostObject.h +16 -28
  18. package/cpp/SmartHostObject.cpp +1 -1
  19. package/cpp/SmartHostObject.h +6 -7
  20. package/cpp/bridge.cpp +639 -633
  21. package/cpp/bridge.h +2 -2
  22. package/cpp/libsql/LICENSE.txt +9 -0
  23. package/cpp/libsql/bridge.cpp +25 -2
  24. package/cpp/libsql/{bridge.h → bridge.hpp} +8 -4
  25. package/cpp/libsql/libsql.h +4 -0
  26. package/cpp/macros.hpp +21 -0
  27. package/cpp/sqlcipher/LICENSE.txt +24 -0
  28. package/cpp/types.hpp +42 -0
  29. package/cpp/utils.cpp +320 -255
  30. package/cpp/{utils.h → utils.hpp} +9 -1
  31. package/ios/OPSQLite.mm +104 -106
  32. package/ios/libsql.xcframework/Info.plist +5 -5
  33. package/ios/libsql.xcframework/ios-arm64/Headers/libsql.h +4 -0
  34. package/ios/libsql.xcframework/ios-arm64/libsql_experimental.a +0 -0
  35. package/ios/libsql.xcframework/ios-arm64_x86_64-simulator/Headers/libsql.h +4 -0
  36. package/ios/libsql.xcframework/ios-arm64_x86_64-simulator/libsql_experimental.a +0 -0
  37. package/lib/module/functions.js +42 -33
  38. package/lib/module/functions.js.map +1 -1
  39. package/lib/module/index.js +1 -1
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/typescript/src/functions.d.ts +5 -1
  42. package/lib/typescript/src/functions.d.ts.map +1 -1
  43. package/lib/typescript/src/index.d.ts +1 -1
  44. package/lib/typescript/src/index.d.ts.map +1 -1
  45. package/lib/typescript/src/types.d.ts +9 -1
  46. package/lib/typescript/src/types.d.ts.map +1 -1
  47. package/op-sqlite.podspec +1 -1
  48. package/package.json +10 -8
  49. package/src/functions.ts +54 -43
  50. package/src/index.ts +1 -12
  51. package/src/types.ts +9 -1
  52. package/cpp/bindings.cpp +0 -202
  53. package/cpp/macros.h +0 -15
  54. package/cpp/types.h +0 -33
  55. /package/cpp/{bindings.h → OPSqlite.hpp} +0 -0
package/cpp/bridge.h CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  #include "DumbHostObject.h"
4
4
  #include "SmartHostObject.h"
5
- #include "types.h"
6
- #include "utils.h"
5
+ #include "types.hpp"
6
+ #include "utils.hpp"
7
7
  #ifdef __ANDROID__
8
8
  #include "sqlite3.h"
9
9
  #else
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright 2023 the sqld authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,9 +1,9 @@
1
- #include "bridge.h"
1
+ #include "bridge.hpp"
2
2
  #include "DumbHostObject.h"
3
3
  #include "SmartHostObject.h"
4
4
  #include "libsql.h"
5
5
  #include "logs.h"
6
- #include "utils.h"
6
+ #include "utils.hpp"
7
7
  #include <filesystem>
8
8
  #include <iostream>
9
9
  #include <unordered_map>
@@ -165,6 +165,29 @@ void opsqlite_libsql_detach(DB const &db, std::string const &alias) {
165
165
  opsqlite_libsql_execute(db, statement, nullptr);
166
166
  }
167
167
 
168
+ int32_t opsqlite_libsql_get_reserved_bytes(DB const &db) {
169
+ const char *err = nullptr;
170
+ int32_t reserved_bytes = 0;
171
+
172
+ int status = libsql_get_reserved_bytes(db.c, &reserved_bytes, &err);
173
+
174
+ if (status != 0) {
175
+ throw std::runtime_error(err);
176
+ }
177
+
178
+ return reserved_bytes;
179
+ }
180
+
181
+ void opsqlite_libsql_set_reserved_bytes(DB const &db, int32_t reserved_bytes) {
182
+ const char *err = nullptr;
183
+
184
+ int status = libsql_set_reserved_bytes(db.c, reserved_bytes, &err);
185
+
186
+ if (status != 0) {
187
+ throw std::runtime_error(err);
188
+ }
189
+ }
190
+
168
191
  void opsqlite_libsql_sync(DB const &db) {
169
192
  const char *err = nullptr;
170
193
 
@@ -3,8 +3,8 @@
3
3
  #include "DumbHostObject.h"
4
4
  #include "SmartHostObject.h"
5
5
  #include "libsql.h"
6
- #include "types.h"
7
- #include "utils.h"
6
+ #include "types.hpp"
7
+ #include "utils.hpp"
8
8
  #include <vector>
9
9
 
10
10
  #define LIBSQL_INT 1
@@ -25,8 +25,8 @@ typedef std::function<void(std::string dbName)> CommitCallback;
25
25
  typedef std::function<void(std::string dbName)> RollbackCallback;
26
26
 
27
27
  struct DB {
28
- libsql_database_t db;
29
- libsql_connection_t c;
28
+ libsql_database_t db;
29
+ libsql_connection_t c;
30
30
  };
31
31
 
32
32
  std::string opsqlite_get_db_path(std::string const &name,
@@ -55,6 +55,10 @@ void opsqlite_libsql_attach(DB const &db, std::string const &docPath,
55
55
 
56
56
  void opsqlite_libsql_detach(DB const &db, std::string const &alias);
57
57
 
58
+ int32_t opsqlite_libsql_get_reserved_bytes(DB const &db);
59
+
60
+ void opsqlite_libsql_set_reserved_bytes(DB const &db, int32_t reserved_bytes);
61
+
58
62
  void opsqlite_libsql_sync(DB const &db);
59
63
 
60
64
  BridgeResult opsqlite_libsql_execute(DB const &db, std::string const &query,
@@ -107,6 +107,10 @@ int libsql_load_extension(libsql_connection_t conn,
107
107
  const char *entry_point,
108
108
  const char **out_err_msg);
109
109
 
110
+ int libsql_set_reserved_bytes(libsql_connection_t conn, int32_t reserved_bytes, const char **out_err_msg);
111
+
112
+ int libsql_get_reserved_bytes(libsql_connection_t conn, int32_t *reserved_bytes, const char **out_err_msg);
113
+
110
114
  int libsql_reset(libsql_connection_t conn, const char **out_err_msg);
111
115
 
112
116
  void libsql_disconnect(libsql_connection_t conn);
package/cpp/macros.hpp ADDED
@@ -0,0 +1,21 @@
1
+ #pragma once
2
+
3
+ #define HOSTFN(name) \
4
+ jsi::Function::createFromHostFunction( \
5
+ rt, \
6
+ jsi::PropNameID::forAscii(rt, name), \
7
+ 0, \
8
+ [=, this](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value
9
+
10
+ #define HOST_STATIC_FN(name) \
11
+ jsi::Function::createFromHostFunction( \
12
+ rt, \
13
+ jsi::PropNameID::forAscii(rt, name), \
14
+ 0, \
15
+ [=](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value
16
+
17
+ // Do not unroll into multi lines to avoid Xcode reporting the wrong lines
18
+ #define HFN0 jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, ""), 0, [](jsi::Runtime &rt, const jsi::Value &that, const jsi::Value *args, size_t count) -> jsi::Value
19
+ #define HFN(c1) jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, ""), 0, [c1](jsi::Runtime &rt, const jsi::Value &that, const jsi::Value *args, size_t count) -> jsi::Value
20
+ #define HFN2(c1, c2) jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, ""), 0, [c1, c2](jsi::Runtime &rt, const jsi::Value &that, const jsi::Value *args, size_t count) -> jsi::Value
21
+ #define HFN3(c1, c2, c3) jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, ""), 0, [c1, c2, c3](jsi::Runtime &rt, const jsi::Value &that, const jsi::Value *args, size_t count) -> jsi::Value
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2025, ZETETIC LLC
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the ZETETIC LLC nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY ZETETIC LLC ''AS IS'' AND ANY
16
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL ZETETIC LLC BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/cpp/types.hpp ADDED
@@ -0,0 +1,42 @@
1
+ #pragma once
2
+
3
+ #include <ReactCommon/CallInvoker.h>
4
+ #include <memory>
5
+ #include <sqlite3.h>
6
+ #include <string>
7
+ #include <variant>
8
+ #include <vector>
9
+
10
+ namespace opsqlite {
11
+
12
+ extern std::shared_ptr<facebook::react::CallInvoker> invoker;
13
+ extern bool invalidated;
14
+
15
+ struct ArrayBuffer {
16
+ std::shared_ptr<uint8_t> data;
17
+ size_t size;
18
+ };
19
+
20
+ using JSVariant = std::variant<nullptr_t, bool, int, double, long, long long,
21
+ std::string, ArrayBuffer>;
22
+
23
+ struct BridgeResult {
24
+ std::string message;
25
+ int affectedRows;
26
+ double insertId;
27
+ std::vector<std::vector<JSVariant>> rows;
28
+ std::vector<std::string> column_names;
29
+ };
30
+
31
+ struct BatchResult {
32
+ std::string message;
33
+ int affectedRows;
34
+ int commands;
35
+ };
36
+
37
+ struct BatchArguments {
38
+ std::string sql;
39
+ std::vector<JSVariant> params;
40
+ };
41
+
42
+ } // namespace opsqlite