react-native-nitro-sqlite 9.6.0 → 9.7.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.
- package/RNNitroSQLite.podspec +20 -16
- package/android/CMakeLists.txt +15 -0
- package/android/build.gradle +14 -0
- package/cpp/hybridObjects/HybridNitroSQLiteQueryResult.cpp +5 -4
- package/cpp/hybridObjects/HybridNitroSQLiteQueryResult.hpp +1 -1
- package/cpp/importSqlFile.cpp +5 -5
- package/cpp/operations.cpp +129 -146
- package/cpp/operations.hpp +2 -1
- package/cpp/sqliteExecuteBatch.cpp +12 -16
- package/lib/commonjs/operations/execute.js +0 -8
- package/lib/commonjs/operations/execute.js.map +1 -1
- package/lib/module/operations/execute.js +0 -8
- package/lib/module/operations/execute.js.map +1 -1
- package/lib/typescript/commonjs/specs/NitroSQLite.nitro.d.ts.map +1 -1
- package/lib/typescript/commonjs/specs/NitroSQLiteQueryResult.nitro.d.ts.map +1 -1
- package/lib/typescript/module/specs/NitroSQLite.nitro.d.ts.map +1 -1
- package/lib/typescript/module/specs/NitroSQLiteQueryResult.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/RNNitroSQLiteOnLoad.cpp +2 -2
- package/nitrogen/generated/android/c++/JHybridNitroSQLiteOnLoadSpec.hpp +2 -2
- package/nitrogen/generated/ios/RNNitroSQLite+autolinking.rb +2 -0
- package/package.json +5 -4
- package/src/operations/execute.ts +0 -8
- package/src/specs/NitroSQLite.nitro.ts +4 -1
- package/src/specs/NitroSQLiteQueryResult.nitro.ts +4 -1
- package/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/8.9/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.9/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
package/RNNitroSQLite.podspec
CHANGED
|
@@ -2,6 +2,9 @@ require "json"
|
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
4
|
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1'
|
|
5
|
+
log_message = lambda do |message|
|
|
6
|
+
puts "\e[34m#{message}\e[0m"
|
|
7
|
+
end
|
|
5
8
|
|
|
6
9
|
# TODO: Should be customizable in package.json.
|
|
7
10
|
# Used to create comparable benchmark results
|
|
@@ -17,6 +20,10 @@ Pod::Spec.new do |s|
|
|
|
17
20
|
s.platforms = { :ios => min_ios_version_supported, :visionos => "1.0" }
|
|
18
21
|
s.source = { :git => "https://github.com/margelo/react-native-nitro-sqlite.git", :tag => "#{s.version}" }
|
|
19
22
|
|
|
23
|
+
# Opt-in vector search (NITRO_SQLITE_VEC=1); the companion pod compiles the sources.
|
|
24
|
+
nitro_sqlite_vec = ENV['NITRO_SQLITE_VEC'] == '1'
|
|
25
|
+
nitro_sqlite_vec_cpp = File.expand_path(File.join(__dir__, "..", "react-native-nitro-sqlite-vec", "cpp"))
|
|
26
|
+
|
|
20
27
|
s.source_files = [
|
|
21
28
|
# Implementation (Swift)
|
|
22
29
|
"ios/**/*.{swift}",
|
|
@@ -26,17 +33,26 @@ Pod::Spec.new do |s|
|
|
|
26
33
|
"cpp/**/*.{h,hpp,c,cpp}"
|
|
27
34
|
]
|
|
28
35
|
|
|
36
|
+
optimizedCflags = '$(inherited) -DSQLITE_DQS=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1 -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_OMIT_DEPRECATED=1 -DSQLITE_OMIT_PROGRESS_CALLBACK=1 -DSQLITE_OMIT_SHARED_CACHE=1 -DSQLITE_USE_ALLOCA=1'
|
|
37
|
+
|
|
38
|
+
if performance_mode == 1
|
|
39
|
+
log_message.call("Thread unsafe (1) performance mode enabled. Use only transactions! 🚀🚀")
|
|
40
|
+
other_cflags = optimizedCflags + ' -DSQLITE_THREADSAFE=0 '
|
|
41
|
+
elsif performance_mode == 2
|
|
42
|
+
log_message.call("Thread safe (2) performance mode enabled 🚀")
|
|
43
|
+
other_cflags = optimizedCflags + ' -DSQLITE_THREADSAFE=1 '
|
|
44
|
+
end
|
|
45
|
+
|
|
29
46
|
s.pod_target_xcconfig = {
|
|
30
47
|
:GCC_PREPROCESSOR_DEFINITIONS => "HAVE_FULLFSYNC=1",
|
|
31
48
|
:WARNING_CFLAGS => "-Wno-shorten-64-to-32 -Wno-comma -Wno-unreachable-code -Wno-conditional-uninitialized -Wno-deprecated-declarations",
|
|
32
49
|
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++20',
|
|
33
50
|
'CLANG_CXX_LIBRARY' => 'libc++',
|
|
34
51
|
'DEFINES_MODULE' => 'YES',
|
|
35
|
-
"HEADER_SEARCH_PATHS" =>
|
|
36
|
-
|
|
37
|
-
],
|
|
38
|
-
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES",
|
|
52
|
+
"HEADER_SEARCH_PATHS" => "\"${PODS_ROOT}/RCT-Folly\"" + (nitro_sqlite_vec ? " \"#{nitro_sqlite_vec_cpp}\"" : ""),
|
|
53
|
+
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES" + (nitro_sqlite_vec ? " NITRO_SQLITE_VEC=1" : ""),
|
|
39
54
|
"OTHER_CPLUSPLUSFLAGS" => folly_compiler_flags,
|
|
55
|
+
"OTHER_CFLAGS" => other_cflags,
|
|
40
56
|
}
|
|
41
57
|
|
|
42
58
|
load 'nitrogen/generated/ios/RNNitroSQLite+autolinking.rb'
|
|
@@ -44,18 +60,6 @@ Pod::Spec.new do |s|
|
|
|
44
60
|
|
|
45
61
|
install_modules_dependencies(s)
|
|
46
62
|
|
|
47
|
-
optimizedCflags = '$(inherited) -DSQLITE_DQS=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1 -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_OMIT_DEPRECATED=1 -DSQLITE_OMIT_PROGRESS_CALLBACK=1 -DSQLITE_OMIT_SHARED_CACHE=1 -DSQLITE_USE_ALLOCA=1'
|
|
48
|
-
|
|
49
|
-
if performance_mode == '1' then
|
|
50
|
-
log_message.call("Thread unsafe (1) performance mode enabled. Use only transactions! 🚀🚀")
|
|
51
|
-
xcconfig[:OTHER_CFLAGS] = optimizedCflags + ' -DSQLITE_THREADSAFE=0 '
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
if performance_mode == '2' then
|
|
55
|
-
log_message.call("Thread safe (2) performance mode enabled 🚀")
|
|
56
|
-
xcconfig[:OTHER_CFLAGS] = optimizedCflags + ' -DSQLITE_THREADSAFE=1 '
|
|
57
|
-
end
|
|
58
|
-
|
|
59
63
|
if ENV['NITRO_SQLITE_USE_PHONE_VERSION'] == '1' then
|
|
60
64
|
s.exclude_files = "cpp/sqlite/sqlite3.c", "cpp/sqlite/sqlite3.h"
|
|
61
65
|
s.library = "sqlite3"
|
package/android/CMakeLists.txt
CHANGED
|
@@ -29,6 +29,21 @@ include_directories(
|
|
|
29
29
|
src/main/cpp
|
|
30
30
|
)
|
|
31
31
|
|
|
32
|
+
# Opt-in: compile the companion's sqlite-vec into this library (shared single sqlite3).
|
|
33
|
+
if(NITRO_SQLITE_VEC)
|
|
34
|
+
message(STATUS "[react-native-nitro-sqlite] vector search ENABLED (sqlite-vec from ${NITRO_SQLITE_VEC_CPP_DIR})")
|
|
35
|
+
set(NITRO_SQLITE_VEC_SOURCES
|
|
36
|
+
"${NITRO_SQLITE_VEC_CPP_DIR}/sqlite-vec/sqlite-vec.c"
|
|
37
|
+
"${NITRO_SQLITE_VEC_CPP_DIR}/registerVectorExtensions.cpp"
|
|
38
|
+
)
|
|
39
|
+
target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${NITRO_SQLITE_VEC_SOURCES})
|
|
40
|
+
# SQLITE_CORE: link against our bundled sqlite3; SQLITE_VEC_STATIC: drop Windows dllexport.
|
|
41
|
+
set_source_files_properties(${NITRO_SQLITE_VEC_SOURCES}
|
|
42
|
+
PROPERTIES COMPILE_DEFINITIONS "SQLITE_CORE;SQLITE_VEC_STATIC")
|
|
43
|
+
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE "${NITRO_SQLITE_VEC_CPP_DIR}")
|
|
44
|
+
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE NITRO_SQLITE_VEC)
|
|
45
|
+
endif()
|
|
46
|
+
|
|
32
47
|
set_target_properties(
|
|
33
48
|
${CMAKE_PROJECT_NAME} PROPERTIES
|
|
34
49
|
CXX_STANDARD ${CMAKE_CXX_STANDARD}
|
package/android/build.gradle
CHANGED
|
@@ -75,6 +75,18 @@ def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 100
|
|
|
75
75
|
|
|
76
76
|
def SQLITE_FLAGS = rootProject.properties['nitroSqliteFlags']
|
|
77
77
|
|
|
78
|
+
// Opt-in: resolve the companion's cpp dir so CMake compiles its sqlite-vec into this library.
|
|
79
|
+
def NITRO_SQLITE_VEC_ENABLED = (rootProject.findProperty('nitroSqliteVec') ?: 'false').toString() == 'true'
|
|
80
|
+
def NITRO_SQLITE_VEC_CPP_DIR = ''
|
|
81
|
+
if (NITRO_SQLITE_VEC_ENABLED) {
|
|
82
|
+
try {
|
|
83
|
+
def vecPkgJson = ["node", "--print", "require.resolve('react-native-nitro-sqlite-vec/package.json')"].execute(null, rootDir).text.trim()
|
|
84
|
+
NITRO_SQLITE_VEC_CPP_DIR = new File(new File(vecPkgJson).parentFile, "cpp").absolutePath
|
|
85
|
+
} catch (Exception e) {
|
|
86
|
+
throw new GradleException("[react-native-nitro-sqlite] nitroSqliteVec=true but 'react-native-nitro-sqlite-vec' could not be resolved. Install it in your app (e.g. `bun add react-native-nitro-sqlite-vec`).")
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
78
90
|
apply plugin: "com.android.library"
|
|
79
91
|
apply plugin: "kotlin-android"
|
|
80
92
|
|
|
@@ -111,6 +123,8 @@ android {
|
|
|
111
123
|
"-DANDROID_TOOLCHAIN=clang",
|
|
112
124
|
"-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
|
|
113
125
|
"-DSQLITE_FLAGS='${SQLITE_FLAGS ? SQLITE_FLAGS : ''}'",
|
|
126
|
+
"-DNITRO_SQLITE_VEC=${NITRO_SQLITE_VEC_ENABLED ? 'ON' : 'OFF'}",
|
|
127
|
+
"-DNITRO_SQLITE_VEC_CPP_DIR=${NITRO_SQLITE_VEC_CPP_DIR}",
|
|
114
128
|
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
115
129
|
abiFilters (*reactNativeArchitectures())
|
|
116
130
|
}
|
|
@@ -10,6 +10,8 @@ namespace margelo::nitro::rnnitrosqlite {
|
|
|
10
10
|
|
|
11
11
|
namespace {
|
|
12
12
|
|
|
13
|
+
constexpr size_t nodePadding = 24;
|
|
14
|
+
|
|
13
15
|
/**
|
|
14
16
|
* Compute the approximate external memory size of a single result row.
|
|
15
17
|
* This includes:
|
|
@@ -18,8 +20,7 @@ namespace {
|
|
|
18
20
|
*/
|
|
19
21
|
size_t getRowExternalMemorySize(const SQLiteQueryResultRow& row) {
|
|
20
22
|
size_t bucketMemory = row.bucket_count() * sizeof(void*);
|
|
21
|
-
|
|
22
|
-
size_t nodesMemory = row.size() * (sizeof(std::pair<std::string, SQLiteValue>) * nodePadding);
|
|
23
|
+
size_t nodesMemory = row.size() * (sizeof(std::pair<std::string, SQLiteValue>) + nodePadding);
|
|
23
24
|
return bucketMemory + nodesMemory;
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -49,10 +50,10 @@ namespace {
|
|
|
49
50
|
* - Metadata contents, especially the `name` string on each metadata entry.
|
|
50
51
|
*/
|
|
51
52
|
size_t getMetadataExternalMemorySize(const SQLiteQueryTableMetadata& metadata) {
|
|
52
|
-
size_t size =
|
|
53
|
+
size_t size = metadata.bucket_count() * sizeof(void*);
|
|
54
|
+
size += metadata.size() * (sizeof(SQLiteQueryTableMetadata::value_type) + nodePadding);
|
|
53
55
|
|
|
54
56
|
for (const auto& [columnName, columnMeta] : metadata) {
|
|
55
|
-
|
|
56
57
|
size += columnName.capacity();
|
|
57
58
|
size += columnMeta.name.capacity();
|
|
58
59
|
}
|
|
@@ -13,7 +13,7 @@ public:
|
|
|
13
13
|
HybridNitroSQLiteQueryResult() : HybridObject(TAG) {}
|
|
14
14
|
HybridNitroSQLiteQueryResult(SQLiteQueryResults results, std::optional<double> insertId, double rowsAffected,
|
|
15
15
|
std::optional<SQLiteQueryTableMetadata> metadata)
|
|
16
|
-
: HybridObject(TAG), _insertId(insertId), _rowsAffected(rowsAffected), _results(std::move(results)), _metadata(metadata) {}
|
|
16
|
+
: HybridObject(TAG), _insertId(insertId), _rowsAffected(rowsAffected), _results(std::move(results)), _metadata(std::move(metadata)) {}
|
|
17
17
|
|
|
18
18
|
private:
|
|
19
19
|
std::optional<double> _insertId;
|
package/cpp/importSqlFile.cpp
CHANGED
|
@@ -17,15 +17,15 @@ SQLiteOperationResult importSqlFile(const std::string& dbName, const std::string
|
|
|
17
17
|
try {
|
|
18
18
|
int rowsAffected = 0;
|
|
19
19
|
int commands = 0;
|
|
20
|
-
|
|
20
|
+
sqliteExecuteCommand(dbName, "BEGIN EXCLUSIVE TRANSACTION");
|
|
21
21
|
while (std::getline(sqFile, line, '\n')) {
|
|
22
22
|
if (!line.empty()) {
|
|
23
23
|
try {
|
|
24
|
-
SQLiteOperationResult result =
|
|
24
|
+
SQLiteOperationResult result = sqliteExecuteCommand(dbName, line);
|
|
25
25
|
rowsAffected += result.rowsAffected;
|
|
26
26
|
commands++;
|
|
27
27
|
} catch (NitroSQLiteException& e) {
|
|
28
|
-
|
|
28
|
+
sqliteExecuteCommand(dbName, "ROLLBACK");
|
|
29
29
|
sqFile.close();
|
|
30
30
|
throw NitroSQLiteException::CouldNotLoadFile(fileLocation, "Transaction was rolled back");
|
|
31
31
|
}
|
|
@@ -33,11 +33,11 @@ SQLiteOperationResult importSqlFile(const std::string& dbName, const std::string
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
sqFile.close();
|
|
36
|
-
|
|
36
|
+
sqliteExecuteCommand(dbName, "COMMIT");
|
|
37
37
|
return {.rowsAffected = rowsAffected, .commands = commands};
|
|
38
38
|
} catch (...) {
|
|
39
39
|
sqFile.close();
|
|
40
|
-
|
|
40
|
+
sqliteExecuteCommand(dbName, "ROLLBACK");
|
|
41
41
|
throw NitroSQLiteException(NitroSQLiteExceptionType::UnknownError, "Unexpected error. Transaction was rolled back");
|
|
42
42
|
}
|
|
43
43
|
} else {
|
package/cpp/operations.cpp
CHANGED
|
@@ -7,21 +7,36 @@
|
|
|
7
7
|
#include <cmath>
|
|
8
8
|
#include <ctime>
|
|
9
9
|
#include <iostream>
|
|
10
|
+
#include <limits>
|
|
10
11
|
#include <map>
|
|
12
|
+
#include <memory>
|
|
11
13
|
#include <optional>
|
|
12
14
|
#include <sqlite3.h>
|
|
13
15
|
#include <sstream>
|
|
14
16
|
#include <unistd.h>
|
|
15
17
|
|
|
18
|
+
#ifdef NITRO_SQLITE_VEC
|
|
19
|
+
// Angle-bracket so it resolves via -I (CocoaPods intercepts quoted includes).
|
|
20
|
+
#include <registerVectorExtensions.hpp>
|
|
21
|
+
#endif
|
|
22
|
+
|
|
16
23
|
using namespace facebook;
|
|
17
24
|
using namespace margelo::nitro;
|
|
18
25
|
using namespace margelo::nitro::rnnitrosqlite;
|
|
19
26
|
|
|
20
27
|
namespace margelo::rnnitrosqlite {
|
|
21
28
|
|
|
29
|
+
static constexpr double kInt64MinAsDouble = static_cast<double>(std::numeric_limits<int64_t>::min());
|
|
30
|
+
static constexpr double kInt64UpperBoundAsDouble = -kInt64MinAsDouble;
|
|
31
|
+
|
|
22
32
|
std::map<std::string, sqlite3*> dbMap = std::map<std::string, sqlite3*>();
|
|
23
33
|
|
|
24
34
|
void sqliteOpenDb(const std::string& dbName, const std::string& docPath) {
|
|
35
|
+
#ifdef NITRO_SQLITE_VEC
|
|
36
|
+
// Register before opening so the connection exposes vec0 + vec_*.
|
|
37
|
+
margelo::rnnitrosqlitevec::registerVectorExtensions();
|
|
38
|
+
#endif
|
|
39
|
+
|
|
25
40
|
std::string dbPath = get_db_path(dbName, docPath);
|
|
26
41
|
|
|
27
42
|
int sqlOpenFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX;
|
|
@@ -62,13 +77,13 @@ void sqliteCloseAll() {
|
|
|
62
77
|
void sqliteAttachDb(const std::string& mainDBName, const std::string& docPath, const std::string& databaseToAttach,
|
|
63
78
|
const std::string& alias) {
|
|
64
79
|
/**
|
|
65
|
-
* There is no need to check if mainDBName is opened because
|
|
80
|
+
* There is no need to check if mainDBName is opened because sqliteExecuteCommand will do that.
|
|
66
81
|
* */
|
|
67
82
|
std::string dbPath = get_db_path(databaseToAttach, docPath);
|
|
68
83
|
std::string statement = "ATTACH DATABASE '" + dbPath + "' AS " + alias;
|
|
69
84
|
|
|
70
85
|
try {
|
|
71
|
-
|
|
86
|
+
sqliteExecuteCommand(mainDBName, statement);
|
|
72
87
|
} catch (NitroSQLiteException& e) {
|
|
73
88
|
throw NitroSQLiteException(NitroSQLiteExceptionType::UnableToAttachToDatabase,
|
|
74
89
|
mainDBName + " was unable to attach another database: " + std::string(e.what()));
|
|
@@ -77,12 +92,12 @@ void sqliteAttachDb(const std::string& mainDBName, const std::string& docPath, c
|
|
|
77
92
|
|
|
78
93
|
void sqliteDetachDb(const std::string& mainDBName, const std::string& alias) {
|
|
79
94
|
/**
|
|
80
|
-
* There is no need to check if mainDBName is opened because
|
|
95
|
+
* There is no need to check if mainDBName is opened because sqliteExecuteCommand will do that.
|
|
81
96
|
* */
|
|
82
97
|
std::string statement = "DETACH DATABASE " + alias;
|
|
83
98
|
|
|
84
99
|
try {
|
|
85
|
-
|
|
100
|
+
sqliteExecuteCommand(mainDBName, statement);
|
|
86
101
|
} catch (NitroSQLiteException& e) {
|
|
87
102
|
throw NitroSQLiteException(NitroSQLiteExceptionType::UnableToAttachToDatabase,
|
|
88
103
|
mainDBName + " was unable to detach database: " + std::string(e.what()));
|
|
@@ -111,7 +126,13 @@ void bindStatement(sqlite3_stmt* statement, const SQLiteQueryParams& values) {
|
|
|
111
126
|
} else if (std::holds_alternative<bool>(value)) {
|
|
112
127
|
sqlite3_bind_int(statement, sqliteIndex, std::get<bool>(value));
|
|
113
128
|
} else if (std::holds_alternative<double>(value)) {
|
|
114
|
-
|
|
129
|
+
// Bind whole numbers as INTEGER so vec0 rowid/pk/partition (which reject REAL) work; SQLite still coerces to REAL for REAL columns.
|
|
130
|
+
double doubleValue = std::get<double>(value);
|
|
131
|
+
if (std::trunc(doubleValue) == doubleValue && doubleValue >= kInt64MinAsDouble && doubleValue < kInt64UpperBoundAsDouble) {
|
|
132
|
+
sqlite3_bind_int64(statement, sqliteIndex, static_cast<sqlite3_int64>(doubleValue));
|
|
133
|
+
} else {
|
|
134
|
+
sqlite3_bind_double(statement, sqliteIndex, doubleValue);
|
|
135
|
+
}
|
|
115
136
|
} else if (std::holds_alternative<std::string>(value)) {
|
|
116
137
|
const auto stringValue = std::get<std::string>(value);
|
|
117
138
|
sqlite3_bind_text(statement, sqliteIndex, stringValue.c_str(), stringValue.length(), SQLITE_TRANSIENT);
|
|
@@ -122,173 +143,135 @@ void bindStatement(sqlite3_stmt* statement, const SQLiteQueryParams& values) {
|
|
|
122
143
|
}
|
|
123
144
|
}
|
|
124
145
|
|
|
125
|
-
|
|
126
|
-
const std::optional<SQLiteQueryParams>& params) {
|
|
127
|
-
if (dbMap.count(dbName) == 0) {
|
|
128
|
-
throw NitroSQLiteException::DatabaseNotOpen(dbName);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
auto db = dbMap[dbName];
|
|
146
|
+
namespace {
|
|
132
147
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
bindStatement(statement, *params);
|
|
148
|
+
struct SQLiteStatementFinalizer {
|
|
149
|
+
void operator()(sqlite3_stmt* statement) const noexcept {
|
|
150
|
+
if (statement != nullptr) {
|
|
151
|
+
sqlite3_finalize(statement);
|
|
152
|
+
}
|
|
139
153
|
}
|
|
140
|
-
}
|
|
141
|
-
throw NitroSQLiteException::SqlExecution(sqlite3_errmsg(db));
|
|
142
|
-
}
|
|
154
|
+
};
|
|
143
155
|
|
|
144
|
-
|
|
145
|
-
auto isFailed = false;
|
|
156
|
+
using SQLiteStatement = std::unique_ptr<sqlite3_stmt, SQLiteStatementFinalizer>;
|
|
146
157
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
SQLiteQueryResultRow row;
|
|
151
|
-
SQLiteQueryResults results;
|
|
152
|
-
std::optional<SQLiteQueryTableMetadata> metadata = std::nullopt;
|
|
153
|
-
|
|
154
|
-
while (isConsuming) {
|
|
155
|
-
result = sqlite3_step(statement);
|
|
156
|
-
|
|
157
|
-
switch (result) {
|
|
158
|
-
case SQLITE_ROW:
|
|
159
|
-
i = 0;
|
|
160
|
-
row = std::unordered_map<std::string, SQLiteValue>();
|
|
161
|
-
count = sqlite3_column_count(statement);
|
|
162
|
-
|
|
163
|
-
while (i < count) {
|
|
164
|
-
column_type = sqlite3_column_type(statement, i);
|
|
165
|
-
column_name = sqlite3_column_name(statement, i);
|
|
166
|
-
switch (column_type) {
|
|
167
|
-
|
|
168
|
-
case SQLITE_INTEGER: {
|
|
169
|
-
auto column_value = sqlite3_column_double(statement, i);
|
|
170
|
-
row[column_name] = column_value;
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
case SQLITE_FLOAT: {
|
|
174
|
-
auto column_value = sqlite3_column_double(statement, i);
|
|
175
|
-
row[column_name] = column_value;
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
case SQLITE_TEXT: {
|
|
179
|
-
auto column_value = reinterpret_cast<const char*>(sqlite3_column_text(statement, i));
|
|
180
|
-
sqlite3_column_bytes(statement, i);
|
|
181
|
-
row[column_name] = column_value;
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
case SQLITE_BLOB: {
|
|
185
|
-
int blob_size = sqlite3_column_bytes(statement, i);
|
|
186
|
-
const void* blob = sqlite3_column_blob(statement, i);
|
|
187
|
-
// Copy the SQLite BLOB into a new native ArrayBuffer.
|
|
188
|
-
// This avoids manual memory management and unsafe pointer handling.
|
|
189
|
-
if (blob_size > 0) {
|
|
190
|
-
const auto* blob_data = reinterpret_cast<const uint8_t*>(blob);
|
|
191
|
-
row[column_name] = ArrayBuffer::copy(blob_data, static_cast<size_t>(blob_size));
|
|
192
|
-
} else {
|
|
193
|
-
// Represent empty BLOBs as an empty, but valid, ArrayBuffer.
|
|
194
|
-
row[column_name] = ArrayBuffer::allocate(0);
|
|
195
|
-
}
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
case SQLITE_NULL:
|
|
199
|
-
// Intentionally left blank to switch to default case
|
|
200
|
-
default:
|
|
201
|
-
row[column_name] = NullType::null;
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
i++;
|
|
205
|
-
}
|
|
206
|
-
results.push_back(std::move(row));
|
|
207
|
-
break;
|
|
208
|
-
case SQLITE_DONE:
|
|
209
|
-
i = 0;
|
|
210
|
-
count = sqlite3_column_count(statement);
|
|
211
|
-
while (i < count) {
|
|
212
|
-
column_name = sqlite3_column_name(statement, i);
|
|
213
|
-
const char* tp = sqlite3_column_decltype(statement, i);
|
|
214
|
-
column_declared_type = mapSQLiteTypeToColumnType(tp);
|
|
215
|
-
auto columnMeta = NitroSQLiteQueryColumnMetadata(std::move(column_name), std::move(column_declared_type), i);
|
|
216
|
-
|
|
217
|
-
if (!metadata) {
|
|
218
|
-
metadata = std::make_optional<SQLiteQueryTableMetadata>();
|
|
219
|
-
}
|
|
220
|
-
metadata->insert({column_name, columnMeta});
|
|
221
|
-
i++;
|
|
222
|
-
}
|
|
223
|
-
isConsuming = false;
|
|
224
|
-
break;
|
|
225
|
-
default:
|
|
226
|
-
isFailed = true;
|
|
227
|
-
isConsuming = false;
|
|
158
|
+
sqlite3* getOpenDatabase(const std::string& dbName) {
|
|
159
|
+
if (dbMap.count(dbName) == 0) {
|
|
160
|
+
throw NitroSQLiteException::DatabaseNotOpen(dbName);
|
|
228
161
|
}
|
|
162
|
+
|
|
163
|
+
return dbMap[dbName];
|
|
229
164
|
}
|
|
230
165
|
|
|
231
|
-
|
|
166
|
+
SQLiteStatement prepareStatement(sqlite3* db, const std::string& query, const std::optional<SQLiteQueryParams>& params) {
|
|
167
|
+
sqlite3_stmt* rawStatement = nullptr;
|
|
168
|
+
int statementStatus = sqlite3_prepare_v2(db, query.c_str(), -1, &rawStatement, nullptr);
|
|
169
|
+
SQLiteStatement statement(rawStatement);
|
|
232
170
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
171
|
+
if (statementStatus != SQLITE_OK) {
|
|
172
|
+
throw NitroSQLiteException::SqlExecution(sqlite3_errmsg(db));
|
|
173
|
+
}
|
|
236
174
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
175
|
+
if (params) {
|
|
176
|
+
bindStatement(statement.get(), *params);
|
|
177
|
+
}
|
|
241
178
|
|
|
242
|
-
|
|
243
|
-
// Check if db connection is opened
|
|
244
|
-
if (dbMap.count(dbName) == 0) {
|
|
245
|
-
throw NitroSQLiteException::DatabaseNotOpen(dbName);
|
|
179
|
+
return statement;
|
|
246
180
|
}
|
|
247
181
|
|
|
248
|
-
|
|
182
|
+
template <typename OnRow>
|
|
183
|
+
void consumeStatement(sqlite3* db, sqlite3_stmt* statement, OnRow&& onRow) {
|
|
184
|
+
while (true) {
|
|
185
|
+
int result = sqlite3_step(statement);
|
|
249
186
|
|
|
250
|
-
|
|
251
|
-
|
|
187
|
+
if (result == SQLITE_ROW) {
|
|
188
|
+
onRow(statement);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
252
191
|
|
|
253
|
-
|
|
254
|
-
|
|
192
|
+
if (result == SQLITE_DONE) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
255
195
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
throw NitroSQLiteException::SqlExecution(sqlite3_errmsg(db));
|
|
196
|
+
throw NitroSQLiteException::SqlExecution(sqlite3_errmsg(db));
|
|
197
|
+
}
|
|
259
198
|
}
|
|
260
199
|
|
|
261
|
-
|
|
262
|
-
bool isFailed = false;
|
|
263
|
-
|
|
264
|
-
int result;
|
|
265
|
-
std::string column_name;
|
|
200
|
+
} // namespace
|
|
266
201
|
|
|
267
|
-
|
|
268
|
-
|
|
202
|
+
std::shared_ptr<HybridNitroSQLiteQueryResult> sqliteExecute(const std::string& dbName, const std::string& query,
|
|
203
|
+
const std::optional<SQLiteQueryParams>& params) {
|
|
204
|
+
auto db = getOpenDatabase(dbName);
|
|
205
|
+
auto statement = prepareStatement(db, query, params);
|
|
206
|
+
SQLiteQueryResults results;
|
|
269
207
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
208
|
+
consumeStatement(db, statement.get(), [&](sqlite3_stmt* currentStatement) {
|
|
209
|
+
SQLiteQueryResultRow row;
|
|
210
|
+
int count = sqlite3_column_count(currentStatement);
|
|
211
|
+
|
|
212
|
+
for (int i = 0; i < count; i++) {
|
|
213
|
+
int columnType = sqlite3_column_type(currentStatement, i);
|
|
214
|
+
std::string columnName = sqlite3_column_name(currentStatement, i);
|
|
215
|
+
|
|
216
|
+
switch (columnType) {
|
|
217
|
+
case SQLITE_INTEGER:
|
|
218
|
+
case SQLITE_FLOAT:
|
|
219
|
+
row[columnName] = sqlite3_column_double(currentStatement, i);
|
|
220
|
+
break;
|
|
221
|
+
case SQLITE_TEXT: {
|
|
222
|
+
auto columnValue = reinterpret_cast<const char*>(sqlite3_column_text(currentStatement, i));
|
|
223
|
+
row[columnName] = columnValue;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
case SQLITE_BLOB: {
|
|
227
|
+
int blobSize = sqlite3_column_bytes(currentStatement, i);
|
|
228
|
+
const void* blob = sqlite3_column_blob(currentStatement, i);
|
|
229
|
+
if (blobSize > 0) {
|
|
230
|
+
const auto* blobData = reinterpret_cast<const uint8_t*>(blob);
|
|
231
|
+
row[columnName] = ArrayBuffer::copy(blobData, static_cast<size_t>(blobSize));
|
|
232
|
+
} else {
|
|
233
|
+
row[columnName] = ArrayBuffer::allocate(0);
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
case SQLITE_NULL:
|
|
238
|
+
default:
|
|
239
|
+
row[columnName] = NullType::null;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
274
243
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
break;
|
|
244
|
+
results.push_back(std::move(row));
|
|
245
|
+
});
|
|
278
246
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
247
|
+
std::optional<SQLiteQueryTableMetadata> metadata = std::nullopt;
|
|
248
|
+
int count = sqlite3_column_count(statement.get());
|
|
249
|
+
for (int i = 0; i < count; i++) {
|
|
250
|
+
std::string columnName = sqlite3_column_name(statement.get(), i);
|
|
251
|
+
ColumnType columnDeclaredType = mapSQLiteTypeToColumnType(sqlite3_column_decltype(statement.get(), i));
|
|
252
|
+
auto columnMeta = NitroSQLiteQueryColumnMetadata(columnName, std::move(columnDeclaredType), i);
|
|
253
|
+
|
|
254
|
+
if (!metadata) {
|
|
255
|
+
metadata = std::make_optional<SQLiteQueryTableMetadata>();
|
|
282
256
|
}
|
|
257
|
+
metadata->insert({columnName, std::move(columnMeta)});
|
|
283
258
|
}
|
|
284
259
|
|
|
285
|
-
|
|
260
|
+
int rowsAffected = sqlite3_changes(db);
|
|
261
|
+
long long latestInsertRowId = sqlite3_last_insert_rowid(db);
|
|
262
|
+
return std::make_shared<HybridNitroSQLiteQueryResult>(std::move(results), static_cast<double>(latestInsertRowId), rowsAffected,
|
|
263
|
+
std::move(metadata));
|
|
264
|
+
}
|
|
286
265
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
266
|
+
SQLiteOperationResult sqliteExecuteCommand(const std::string& dbName, const std::string& query,
|
|
267
|
+
const std::optional<SQLiteQueryParams>& params) {
|
|
268
|
+
auto db = getOpenDatabase(dbName);
|
|
269
|
+
auto statement = prepareStatement(db, query, params);
|
|
270
|
+
bool isReadOnly = sqlite3_stmt_readonly(statement.get()) != 0;
|
|
271
|
+
|
|
272
|
+
consumeStatement(db, statement.get(), [](sqlite3_stmt*) {});
|
|
290
273
|
|
|
291
|
-
return {.rowsAffected = sqlite3_changes(db)};
|
|
274
|
+
return {.rowsAffected = isReadOnly ? 0 : sqlite3_changes(db)};
|
|
292
275
|
}
|
|
293
276
|
|
|
294
277
|
} // namespace margelo::rnnitrosqlite
|
package/cpp/operations.hpp
CHANGED
|
@@ -19,7 +19,8 @@ void sqliteDetachDb(const std::string& mainDBName, const std::string& alias);
|
|
|
19
19
|
std::shared_ptr<HybridNitroSQLiteQueryResult> sqliteExecute(const std::string& dbName, const std::string& query,
|
|
20
20
|
const std::optional<SQLiteQueryParams>& params);
|
|
21
21
|
|
|
22
|
-
SQLiteOperationResult
|
|
22
|
+
SQLiteOperationResult sqliteExecuteCommand(const std::string& dbName, const std::string& query,
|
|
23
|
+
const std::optional<SQLiteQueryParams>& params = std::nullopt);
|
|
23
24
|
|
|
24
25
|
void sqliteCloseAll();
|
|
25
26
|
|
|
@@ -40,28 +40,24 @@ SQLiteOperationResult sqliteExecuteBatch(const std::string& dbName, const std::v
|
|
|
40
40
|
|
|
41
41
|
try {
|
|
42
42
|
int rowsAffected = 0;
|
|
43
|
-
|
|
44
|
-
for (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// We do not provide a datas tructure to receive query data because we don't need/want to handle this results in a batch execution
|
|
48
|
-
auto results = SQLiteQueryResults();
|
|
49
|
-
auto metadata = std::optional<SQLiteQueryTableMetadata>(std::nullopt);
|
|
50
|
-
try {
|
|
51
|
-
auto result = sqliteExecute(dbName, command.sql, command.params);
|
|
52
|
-
rowsAffected += result->getRowsAffected();
|
|
53
|
-
} catch (NitroSQLiteException& e) {
|
|
54
|
-
sqliteExecuteLiteral(dbName, "ROLLBACK");
|
|
55
|
-
throw e;
|
|
56
|
-
}
|
|
43
|
+
sqliteExecuteCommand(dbName, "BEGIN EXCLUSIVE TRANSACTION");
|
|
44
|
+
for (const auto& command : commands) {
|
|
45
|
+
auto result = sqliteExecuteCommand(dbName, command.sql, command.params);
|
|
46
|
+
rowsAffected += result.rowsAffected;
|
|
57
47
|
}
|
|
58
|
-
|
|
48
|
+
|
|
49
|
+
sqliteExecuteCommand(dbName, "COMMIT");
|
|
59
50
|
return {
|
|
60
51
|
.rowsAffected = rowsAffected,
|
|
61
52
|
.commands = (int)commandCount,
|
|
62
53
|
};
|
|
63
54
|
} catch (NitroSQLiteException& e) {
|
|
64
|
-
|
|
55
|
+
// Roll back exactly once; a failed ROLLBACK must not mask the original error.
|
|
56
|
+
try {
|
|
57
|
+
sqliteExecuteCommand(dbName, "ROLLBACK");
|
|
58
|
+
} catch (...) {
|
|
59
|
+
// ignore — surface the original error below
|
|
60
|
+
}
|
|
65
61
|
throw e;
|
|
66
62
|
}
|
|
67
63
|
}
|
|
@@ -32,13 +32,5 @@ function buildJSQueryResult(result) {
|
|
|
32
32
|
item: idx => result.results[idx]
|
|
33
33
|
};
|
|
34
34
|
return resultWithRows;
|
|
35
|
-
|
|
36
|
-
// return Object.assign(result, {
|
|
37
|
-
// rows: {
|
|
38
|
-
// _array: result.results,
|
|
39
|
-
// length: result.results.length,
|
|
40
|
-
// item: (idx: number) => result.results[idx],
|
|
41
|
-
// },
|
|
42
|
-
// })
|
|
43
35
|
}
|
|
44
36
|
//# sourceMappingURL=execute.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_nitro","require","_NitroSQLiteError","_interopRequireDefault","e","__esModule","default","execute","dbName","query","params","nativeResult","HybridNitroSQLite","buildJSQueryResult","error","NitroSQLiteError","fromError","executeAsync","result","resultWithRows","rows","_array","results","length","item","idx"],"sourceRoot":"../../../src","sources":["operations/execute.ts"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAkD,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAG3C,SAASG,OAAOA,CACrBC,MAAc,EACdC,KAAa,EACbC,MAA0B,EACR;EAClB,IAAI;IACF,MAAMC,YAAY,GAAGC,wBAAiB,CAACL,OAAO,CAACC,MAAM,EAAEC,KAAK,EAAEC,MAAM,CAAC;IACrE,OAAOG,kBAAkB,CAAMF,YAAY,CAAC;EAC9C,CAAC,CAAC,OAAOG,KAAK,EAAE;IACd,MAAMC,yBAAgB,CAACC,SAAS,CAACF,KAAK,CAAC;EACzC;AACF;AAEO,eAAeG,YAAYA,CAChCT,MAAc,EACdC,KAAa,EACbC,MAA0B,EACC;EAC3B,IAAI;IACF,MAAMC,YAAY,GAAG,MAAMC,wBAAiB,CAACK,YAAY,CACvDT,MAAM,EACNC,KAAK,EACLC,MACF,CAAC;IACD,OAAOG,kBAAkB,CAAMF,YAAY,CAAC;EAC9C,CAAC,CAAC,OAAOG,KAAK,EAAE;IACd,MAAMC,yBAAgB,CAACC,SAAS,CAACF,KAAK,CAAC;EACzC;AACF;AAEA,SAASD,kBAAkBA,CACzBK,MAA8B,EACZ;EAClB,MAAMC,cAAc,GAAGD,MAA0B;EAEjDC,cAAc,CAACC,IAAI,GAAG;IACpBC,MAAM,EAAEH,MAAM,CAACI,OAAgB;IAC/BC,MAAM,EAAEL,MAAM,CAACI,OAAO,CAACC,MAAM;IAC7BC,IAAI,EAAGC,GAAW,IAAKP,MAAM,CAACI,OAAO,CAACG,GAAG;EAC3C,CAAC;EAED,OAAON,cAAc
|
|
1
|
+
{"version":3,"names":["_nitro","require","_NitroSQLiteError","_interopRequireDefault","e","__esModule","default","execute","dbName","query","params","nativeResult","HybridNitroSQLite","buildJSQueryResult","error","NitroSQLiteError","fromError","executeAsync","result","resultWithRows","rows","_array","results","length","item","idx"],"sourceRoot":"../../../src","sources":["operations/execute.ts"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAkD,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAG3C,SAASG,OAAOA,CACrBC,MAAc,EACdC,KAAa,EACbC,MAA0B,EACR;EAClB,IAAI;IACF,MAAMC,YAAY,GAAGC,wBAAiB,CAACL,OAAO,CAACC,MAAM,EAAEC,KAAK,EAAEC,MAAM,CAAC;IACrE,OAAOG,kBAAkB,CAAMF,YAAY,CAAC;EAC9C,CAAC,CAAC,OAAOG,KAAK,EAAE;IACd,MAAMC,yBAAgB,CAACC,SAAS,CAACF,KAAK,CAAC;EACzC;AACF;AAEO,eAAeG,YAAYA,CAChCT,MAAc,EACdC,KAAa,EACbC,MAA0B,EACC;EAC3B,IAAI;IACF,MAAMC,YAAY,GAAG,MAAMC,wBAAiB,CAACK,YAAY,CACvDT,MAAM,EACNC,KAAK,EACLC,MACF,CAAC;IACD,OAAOG,kBAAkB,CAAMF,YAAY,CAAC;EAC9C,CAAC,CAAC,OAAOG,KAAK,EAAE;IACd,MAAMC,yBAAgB,CAACC,SAAS,CAACF,KAAK,CAAC;EACzC;AACF;AAEA,SAASD,kBAAkBA,CACzBK,MAA8B,EACZ;EAClB,MAAMC,cAAc,GAAGD,MAA0B;EAEjDC,cAAc,CAACC,IAAI,GAAG;IACpBC,MAAM,EAAEH,MAAM,CAACI,OAAgB;IAC/BC,MAAM,EAAEL,MAAM,CAACI,OAAO,CAACC,MAAM;IAC7BC,IAAI,EAAGC,GAAW,IAAKP,MAAM,CAACI,OAAO,CAACG,GAAG;EAC3C,CAAC;EAED,OAAON,cAAc;AACvB","ignoreList":[]}
|
|
@@ -26,13 +26,5 @@ function buildJSQueryResult(result) {
|
|
|
26
26
|
item: idx => result.results[idx]
|
|
27
27
|
};
|
|
28
28
|
return resultWithRows;
|
|
29
|
-
|
|
30
|
-
// return Object.assign(result, {
|
|
31
|
-
// rows: {
|
|
32
|
-
// _array: result.results,
|
|
33
|
-
// length: result.results.length,
|
|
34
|
-
// item: (idx: number) => result.results[idx],
|
|
35
|
-
// },
|
|
36
|
-
// })
|
|
37
29
|
}
|
|
38
30
|
//# sourceMappingURL=execute.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HybridNitroSQLite","NitroSQLiteError","execute","dbName","query","params","nativeResult","buildJSQueryResult","error","fromError","executeAsync","result","resultWithRows","rows","_array","results","length","item","idx"],"sourceRoot":"../../../src","sources":["operations/execute.ts"],"mappings":";;AAAA,SAASA,iBAAiB,QAAQ,aAAU;AAE5C,OAAOC,gBAAgB,MAAM,wBAAqB;AAGlD,OAAO,SAASC,OAAOA,CACrBC,MAAc,EACdC,KAAa,EACbC,MAA0B,EACR;EAClB,IAAI;IACF,MAAMC,YAAY,GAAGN,iBAAiB,CAACE,OAAO,CAACC,MAAM,EAAEC,KAAK,EAAEC,MAAM,CAAC;IACrE,OAAOE,kBAAkB,CAAMD,YAAY,CAAC;EAC9C,CAAC,CAAC,OAAOE,KAAK,EAAE;IACd,MAAMP,gBAAgB,CAACQ,SAAS,CAACD,KAAK,CAAC;EACzC;AACF;AAEA,OAAO,eAAeE,YAAYA,CAChCP,MAAc,EACdC,KAAa,EACbC,MAA0B,EACC;EAC3B,IAAI;IACF,MAAMC,YAAY,GAAG,MAAMN,iBAAiB,CAACU,YAAY,CACvDP,MAAM,EACNC,KAAK,EACLC,MACF,CAAC;IACD,OAAOE,kBAAkB,CAAMD,YAAY,CAAC;EAC9C,CAAC,CAAC,OAAOE,KAAK,EAAE;IACd,MAAMP,gBAAgB,CAACQ,SAAS,CAACD,KAAK,CAAC;EACzC;AACF;AAEA,SAASD,kBAAkBA,CACzBI,MAA8B,EACZ;EAClB,MAAMC,cAAc,GAAGD,MAA0B;EAEjDC,cAAc,CAACC,IAAI,GAAG;IACpBC,MAAM,EAAEH,MAAM,CAACI,OAAgB;IAC/BC,MAAM,EAAEL,MAAM,CAACI,OAAO,CAACC,MAAM;IAC7BC,IAAI,EAAGC,GAAW,IAAKP,MAAM,CAACI,OAAO,CAACG,GAAG;EAC3C,CAAC;EAED,OAAON,cAAc
|
|
1
|
+
{"version":3,"names":["HybridNitroSQLite","NitroSQLiteError","execute","dbName","query","params","nativeResult","buildJSQueryResult","error","fromError","executeAsync","result","resultWithRows","rows","_array","results","length","item","idx"],"sourceRoot":"../../../src","sources":["operations/execute.ts"],"mappings":";;AAAA,SAASA,iBAAiB,QAAQ,aAAU;AAE5C,OAAOC,gBAAgB,MAAM,wBAAqB;AAGlD,OAAO,SAASC,OAAOA,CACrBC,MAAc,EACdC,KAAa,EACbC,MAA0B,EACR;EAClB,IAAI;IACF,MAAMC,YAAY,GAAGN,iBAAiB,CAACE,OAAO,CAACC,MAAM,EAAEC,KAAK,EAAEC,MAAM,CAAC;IACrE,OAAOE,kBAAkB,CAAMD,YAAY,CAAC;EAC9C,CAAC,CAAC,OAAOE,KAAK,EAAE;IACd,MAAMP,gBAAgB,CAACQ,SAAS,CAACD,KAAK,CAAC;EACzC;AACF;AAEA,OAAO,eAAeE,YAAYA,CAChCP,MAAc,EACdC,KAAa,EACbC,MAA0B,EACC;EAC3B,IAAI;IACF,MAAMC,YAAY,GAAG,MAAMN,iBAAiB,CAACU,YAAY,CACvDP,MAAM,EACNC,KAAK,EACLC,MACF,CAAC;IACD,OAAOE,kBAAkB,CAAMD,YAAY,CAAC;EAC9C,CAAC,CAAC,OAAOE,KAAK,EAAE;IACd,MAAMP,gBAAgB,CAACQ,SAAS,CAACD,KAAK,CAAC;EACzC;AACF;AAEA,SAASD,kBAAkBA,CACzBI,MAA8B,EACZ;EAClB,MAAMC,cAAc,GAAGD,MAA0B;EAEjDC,cAAc,CAACC,IAAI,GAAG;IACpBC,MAAM,EAAEH,MAAM,CAACI,OAAgB;IAC/BC,MAAM,EAAEL,MAAM,CAACI,OAAO,CAACC,MAAM;IAC7BC,IAAI,EAAGC,GAAW,IAAKP,MAAM,CAACI,OAAO,CAACG,GAAG;EAC3C,CAAC;EAED,OAAON,cAAc;AACvB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NitroSQLite.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/NitroSQLite.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EAClB,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAE5E,MAAM,WAAW,WACf,SAAQ,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"NitroSQLite.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/NitroSQLite.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EAClB,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAE5E,MAAM,WAAW,WACf,SAAQ,YAAY,CAAC;IACnB,GAAG,EAAE,KAAK,CAAA;IACV,OAAO,EAAE,KAAK,CAAA;CACf,CAAC;IACF,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7C,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7C,MAAM,CACJ,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,MAAM,GAChB,IAAI,CAAA;IACP,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/C,OAAO,CACL,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,GACzB,sBAAsB,CAAA;IACzB,YAAY,CACV,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,sBAAsB,CAAC,CAAA;IAClC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,gBAAgB,CAAA;IAC7E,iBAAiB,CACf,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,iBAAiB,EAAE,GAC5B,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAAA;IAC1D,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;CACzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NitroSQLiteQueryResult.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/NitroSQLiteQueryResult.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEvD;;;;;;;;;GASG;AACH,MAAM,WAAW,sBACf,SAAQ,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"NitroSQLiteQueryResult.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/NitroSQLiteQueryResult.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEvD;;;;;;;;;GASG;AACH,MAAM,WAAW,sBACf,SAAQ,YAAY,CAAC;IACnB,GAAG,EAAE,KAAK,CAAA;IACV,OAAO,EAAE,KAAK,CAAA;CACf,CAAC;IACF,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAE1B,oBAAoB;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAA;IAE/C,qBAAqB;IACrB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,8BAA8B,CAAC,CAAA;CACnE;AASD,MAAM,MAAM,8BAA8B,GAAG;IAC3C,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAA;IAEZ,uLAAuL;IACvL,IAAI,EAAE,UAAU,CAAA;IAEhB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAA;CACd,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NitroSQLite.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/NitroSQLite.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EAClB,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAE5E,MAAM,WAAW,WACf,SAAQ,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"NitroSQLite.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/NitroSQLite.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EAClB,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAE5E,MAAM,WAAW,WACf,SAAQ,YAAY,CAAC;IACnB,GAAG,EAAE,KAAK,CAAA;IACV,OAAO,EAAE,KAAK,CAAA;CACf,CAAC;IACF,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7C,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7C,MAAM,CACJ,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,MAAM,GAChB,IAAI,CAAA;IACP,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/C,OAAO,CACL,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,GACzB,sBAAsB,CAAA;IACzB,YAAY,CACV,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,sBAAsB,CAAC,CAAA;IAClC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,gBAAgB,CAAA;IAC7E,iBAAiB,CACf,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,iBAAiB,EAAE,GAC5B,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAAA;IAC1D,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;CACzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NitroSQLiteQueryResult.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/NitroSQLiteQueryResult.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEvD;;;;;;;;;GASG;AACH,MAAM,WAAW,sBACf,SAAQ,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"NitroSQLiteQueryResult.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/NitroSQLiteQueryResult.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEvD;;;;;;;;;GASG;AACH,MAAM,WAAW,sBACf,SAAQ,YAAY,CAAC;IACnB,GAAG,EAAE,KAAK,CAAA;IACV,OAAO,EAAE,KAAK,CAAA;CACf,CAAC;IACF,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAE1B,oBAAoB;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAA;IAE/C,qBAAqB;IACrB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,8BAA8B,CAAC,CAAA;CACnE;AASD,MAAM,MAAM,8BAA8B,GAAG;IAC3C,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAA;IAEZ,uLAAuL;IACvL,IAAI,EAAE,UAAU,CAAA;IAEhB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAA;CACd,CAAA"}
|
|
@@ -28,9 +28,9 @@ int initialize(JavaVM* vm) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
struct JHybridNitroSQLiteOnLoadSpecImpl: public jni::JavaClass<JHybridNitroSQLiteOnLoadSpecImpl, JHybridNitroSQLiteOnLoadSpec::JavaPart> {
|
|
31
|
-
static auto
|
|
31
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/rnnitrosqlite/HybridNitroSQLiteOnLoad;";
|
|
32
32
|
static std::shared_ptr<JHybridNitroSQLiteOnLoadSpec> create() {
|
|
33
|
-
static auto constructorFn = javaClassStatic()->getConstructor<JHybridNitroSQLiteOnLoadSpecImpl::javaobject()>();
|
|
33
|
+
static const auto constructorFn = javaClassStatic()->getConstructor<JHybridNitroSQLiteOnLoadSpecImpl::javaobject()>();
|
|
34
34
|
jni::local_ref<JHybridNitroSQLiteOnLoadSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
|
|
35
35
|
return javaPart->getJHybridNitroSQLiteOnLoadSpec();
|
|
36
36
|
}
|
|
@@ -21,11 +21,11 @@ namespace margelo::nitro::rnnitrosqlite {
|
|
|
21
21
|
class JHybridNitroSQLiteOnLoadSpec: public virtual HybridNitroSQLiteOnLoadSpec, public virtual JHybridObject {
|
|
22
22
|
public:
|
|
23
23
|
struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
|
|
24
|
-
static auto
|
|
24
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/rnnitrosqlite/HybridNitroSQLiteOnLoadSpec;";
|
|
25
25
|
std::shared_ptr<JHybridNitroSQLiteOnLoadSpec> getJHybridNitroSQLiteOnLoadSpec();
|
|
26
26
|
};
|
|
27
27
|
struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
|
|
28
|
-
static auto
|
|
28
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/rnnitrosqlite/HybridNitroSQLiteOnLoadSpec$CxxPart;";
|
|
29
29
|
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
30
30
|
static void registerNatives();
|
|
31
31
|
using HybridBase::HybridBase;
|
|
@@ -56,5 +56,7 @@ def add_nitrogen_files(spec)
|
|
|
56
56
|
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
|
|
57
57
|
# Enables stricter modular headers
|
|
58
58
|
"DEFINES_MODULE" => "YES",
|
|
59
|
+
# Disable auto-generated ObjC header for Swift (Static linkage on Xcode 26.4 breaks here)
|
|
60
|
+
"SWIFT_INSTALL_OBJC_HEADER" => "NO",
|
|
59
61
|
})
|
|
60
62
|
end
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-sqlite",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.7.0",
|
|
4
4
|
"description": "Fast SQLite library for React Native built using Nitro Modules",
|
|
5
5
|
"main": "./lib/module/index",
|
|
6
6
|
"module": "./lib/module/index",
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"jest": "^30.2.0",
|
|
73
|
-
"nitrogen": "0.
|
|
73
|
+
"nitrogen": "0.36.1",
|
|
74
74
|
"react": "19.2.3",
|
|
75
75
|
"react-native": "0.85.0-rc.0",
|
|
76
76
|
"react-native-builder-bob": "^0.31.0",
|
|
77
|
-
"react-native-nitro-modules": "0.
|
|
77
|
+
"react-native-nitro-modules": "0.36.1"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"react": ">=17.0.0",
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
"release-it": {
|
|
95
95
|
"npm": {
|
|
96
96
|
"publish": true,
|
|
97
|
+
"skipChecks": true,
|
|
97
98
|
"versionArgs": [
|
|
98
99
|
"--allow-same-version"
|
|
99
100
|
]
|
|
@@ -126,7 +127,7 @@
|
|
|
126
127
|
[
|
|
127
128
|
"typescript",
|
|
128
129
|
{
|
|
129
|
-
"tsc": "
|
|
130
|
+
"tsc": "../../node_modules/.bin/tsc",
|
|
130
131
|
"project": "tsconfig.build.json",
|
|
131
132
|
"esm": true
|
|
132
133
|
}
|
|
@@ -45,12 +45,4 @@ function buildJSQueryResult<Row extends QueryResultRow = never>(
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
return resultWithRows
|
|
48
|
-
|
|
49
|
-
// return Object.assign(result, {
|
|
50
|
-
// rows: {
|
|
51
|
-
// _array: result.results,
|
|
52
|
-
// length: result.results.length,
|
|
53
|
-
// item: (idx: number) => result.results[idx],
|
|
54
|
-
// },
|
|
55
|
-
// })
|
|
56
48
|
}
|
|
@@ -8,7 +8,10 @@ import type {
|
|
|
8
8
|
import type { NitroSQLiteQueryResult } from './NitroSQLiteQueryResult.nitro'
|
|
9
9
|
|
|
10
10
|
export interface NitroSQLite
|
|
11
|
-
extends HybridObject<{
|
|
11
|
+
extends HybridObject<{
|
|
12
|
+
ios: 'c++'
|
|
13
|
+
android: 'c++'
|
|
14
|
+
}> {
|
|
12
15
|
open(dbName: string, location?: string): void
|
|
13
16
|
close(dbName: string): void
|
|
14
17
|
drop(dbName: string, location?: string): void
|
|
@@ -12,7 +12,10 @@ import type { ColumnType, SQLiteValue } from '../types'
|
|
|
12
12
|
* @interface QueryResult
|
|
13
13
|
*/
|
|
14
14
|
export interface NitroSQLiteQueryResult
|
|
15
|
-
extends HybridObject<{
|
|
15
|
+
extends HybridObject<{
|
|
16
|
+
ios: 'c++'
|
|
17
|
+
android: 'c++'
|
|
18
|
+
}> {
|
|
16
19
|
readonly rowsAffected: number
|
|
17
20
|
readonly insertId?: number
|
|
18
21
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
File without changes
|