@op-engineering/op-sqlite 0.0.0-resolution-test
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/LICENSE +7 -0
- package/README.md +31 -0
- package/android/.project +17 -0
- package/android/.settings/org.eclipse.buildship.core.prefs +13 -0
- package/android/CMakeLists.txt +141 -0
- package/android/build.gradle +266 -0
- package/android/c_sources/tokenizers.cpp +88 -0
- package/android/c_sources/tokenizers.h +15 -0
- package/android/cpp-adapter.cpp +46 -0
- package/android/gradle.properties +1 -0
- package/android/jniLibs/arm64-v8a/libsql_experimental.a +0 -0
- package/android/jniLibs/armeabi-v7a/libsql_experimental.a +0 -0
- package/android/jniLibs/x86/libsql_experimental.a +0 -0
- package/android/jniLibs/x86_64/libsql_experimental.a +0 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/op/sqlite/OPSQLiteBridge.kt +37 -0
- package/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt +119 -0
- package/android/src/main/java/com/op/sqlite/OPSQLitePackage.kt +18 -0
- package/android/src/main/jniLibs/arm64-v8a/libcrsqlite.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libsqlite_vec.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libcrsqlite.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libsqlite_vec.so +0 -0
- package/android/src/main/jniLibs/x86/libcrsqlite.so +0 -0
- package/android/src/main/jniLibs/x86/libsqlite_vec.so +0 -0
- package/android/src/main/jniLibs/x86_64/libcrsqlite.so +0 -0
- package/android/src/main/jniLibs/x86_64/libsqlite_vec.so +0 -0
- package/android/src/paper/java/com/op/sqlite/NativeOPSQLiteSpec.java +77 -0
- package/cpp/DBHostObject.cpp +852 -0
- package/cpp/DBHostObject.h +99 -0
- package/cpp/DumbHostObject.cpp +72 -0
- package/cpp/DumbHostObject.h +36 -0
- package/cpp/OPThreadPool.cpp +120 -0
- package/cpp/OPThreadPool.h +44 -0
- package/cpp/PreparedStatementHostObject.cpp +151 -0
- package/cpp/PreparedStatementHostObject.h +59 -0
- package/cpp/SmartHostObject.cpp +34 -0
- package/cpp/SmartHostObject.h +24 -0
- package/cpp/bindings.cpp +182 -0
- package/cpp/bindings.h +19 -0
- package/cpp/bridge.cpp +873 -0
- package/cpp/bridge.h +80 -0
- package/cpp/libsql/bridge.cpp +738 -0
- package/cpp/libsql/bridge.h +85 -0
- package/cpp/libsql/libsql.h +172 -0
- package/cpp/logs.h +40 -0
- package/cpp/macros.h +15 -0
- package/cpp/sqlcipher/sqlite3.c +262970 -0
- package/cpp/sqlcipher/sqlite3.h +13485 -0
- package/cpp/sqlite3.c +261454 -0
- package/cpp/sqlite3.h +13715 -0
- package/cpp/types.h +33 -0
- package/cpp/utils.cpp +327 -0
- package/cpp/utils.h +47 -0
- package/generate_tokenizers_header_file.rb +29 -0
- package/ios/OPSQLite.h +7 -0
- package/ios/OPSQLite.mm +157 -0
- package/ios/OPSQLite.xcodeproj/project.pbxproj +275 -0
- package/ios/crsqlite.xcframework/Info.plist +46 -0
- package/ios/crsqlite.xcframework/ios-arm64/crsqlite.framework/Info.plist +24 -0
- package/ios/crsqlite.xcframework/ios-arm64/crsqlite.framework/crsqlite +0 -0
- package/ios/crsqlite.xcframework/ios-arm64_x86_64-simulator/crsqlite.framework/Info.plist +24 -0
- package/ios/crsqlite.xcframework/ios-arm64_x86_64-simulator/crsqlite.framework/crsqlite +0 -0
- package/ios/libsql.xcframework/Info.plist +48 -0
- package/ios/libsql.xcframework/ios-arm64/Headers/libsql.h +172 -0
- package/ios/libsql.xcframework/ios-arm64/libsql_experimental.a +0 -0
- package/ios/libsql.xcframework/ios-arm64_x86_64-simulator/Headers/libsql.h +172 -0
- package/ios/libsql.xcframework/ios-arm64_x86_64-simulator/libsql_experimental.a +0 -0
- package/ios/sqlitevec.xcframework/Info.plist +71 -0
- package/ios/sqlitevec.xcframework/ios-arm64/sqlitevec.framework/Info.plist +24 -0
- package/ios/sqlitevec.xcframework/ios-arm64/sqlitevec.framework/sqlitevec +0 -0
- package/ios/sqlitevec.xcframework/ios-arm64_x86_64-simulator/sqlitevec.framework/Info.plist +24 -0
- package/ios/sqlitevec.xcframework/ios-arm64_x86_64-simulator/sqlitevec.framework/sqlitevec +0 -0
- package/ios/sqlitevec.xcframework/tvos-arm64/sqlitevec.framework/Info.plist +24 -0
- package/ios/sqlitevec.xcframework/tvos-arm64/sqlitevec.framework/sqlitevec +0 -0
- package/ios/sqlitevec.xcframework/tvos-arm64_x86_64-simulator/sqlitevec.framework/Info.plist +24 -0
- package/ios/sqlitevec.xcframework/tvos-arm64_x86_64-simulator/sqlitevec.framework/sqlitevec +0 -0
- package/lib/commonjs/NativeOPSQLite.js +9 -0
- package/lib/commonjs/NativeOPSQLite.js.map +1 -0
- package/lib/commonjs/Storage.js +60 -0
- package/lib/commonjs/Storage.js.map +1 -0
- package/lib/commonjs/index.js +365 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/NativeOPSQLite.js +3 -0
- package/lib/module/NativeOPSQLite.js.map +1 -0
- package/lib/module/Storage.js +53 -0
- package/lib/module/Storage.js.map +1 -0
- package/lib/module/index.js +340 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/src/NativeOPSQLite.d.ts +15 -0
- package/lib/typescript/src/NativeOPSQLite.d.ts.map +1 -0
- package/lib/typescript/src/Storage.d.ts +23 -0
- package/lib/typescript/src/Storage.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +319 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/op-sqlite.podspec +212 -0
- package/package.json +85 -0
- package/src/NativeOPSQLite.ts +17 -0
- package/src/Storage.ts +85 -0
- package/src/index.ts +722 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2021 Oscar Franco
|
|
2
|
+
|
|
3
|
+
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:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
Created by [@ospfranco](https://twitter.com/ospfranco). **Please consider sponsoring!**.
|
|
4
|
+
|
|
5
|
+
OP-SQLite has grown large to cover a lot of plugins, sqlite versions and APIs. Please read the full documentation before opening an issue.
|
|
6
|
+
|
|
7
|
+
[Open the docs](https://op-engineering.github.io/op-sqlite/)
|
|
8
|
+
|
|
9
|
+
Join the Discord:
|
|
10
|
+
|
|
11
|
+
https://discord.gg/W9XmqCQCKP
|
|
12
|
+
|
|
13
|
+
Some of the big supported features:
|
|
14
|
+
|
|
15
|
+
- Vanilla sqlite
|
|
16
|
+
- Libsql is supported as a compilation target
|
|
17
|
+
- SQLCipher is supported as a compilation target
|
|
18
|
+
- FTS5 plugin
|
|
19
|
+
- Rtree plugin
|
|
20
|
+
- cr-sqlite plugin
|
|
21
|
+
- sqlite-vec plugin
|
|
22
|
+
- Reactive queries
|
|
23
|
+
- Custom tokenizers
|
|
24
|
+
- Load runtime extensions
|
|
25
|
+
- JSONB support
|
|
26
|
+
|
|
27
|
+
It also contains a simple [Key-Value store](https://op-engineering.github.io/op-sqlite/docs/key_value_storage) you can use without adding one more dependency to your app.
|
|
28
|
+
|
|
29
|
+
# License
|
|
30
|
+
|
|
31
|
+
MIT License.
|
package/android/.project
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<projectDescription>
|
|
3
|
+
<name>android_</name>
|
|
4
|
+
<comment>Project android_ created by Buildship.</comment>
|
|
5
|
+
<projects>
|
|
6
|
+
</projects>
|
|
7
|
+
<buildSpec>
|
|
8
|
+
<buildCommand>
|
|
9
|
+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
|
10
|
+
<arguments>
|
|
11
|
+
</arguments>
|
|
12
|
+
</buildCommand>
|
|
13
|
+
</buildSpec>
|
|
14
|
+
<natures>
|
|
15
|
+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
|
16
|
+
</natures>
|
|
17
|
+
</projectDescription>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
arguments=
|
|
2
|
+
auto.sync=false
|
|
3
|
+
build.scans.enabled=false
|
|
4
|
+
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0))
|
|
5
|
+
connection.project.dir=
|
|
6
|
+
eclipse.preferences.version=1
|
|
7
|
+
gradle.user.home=
|
|
8
|
+
java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
|
|
9
|
+
jvm.arguments=
|
|
10
|
+
offline.mode=false
|
|
11
|
+
override.workspace.settings=true
|
|
12
|
+
show.console.view=true
|
|
13
|
+
show.executions.view=true
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
project(OPSQLite)
|
|
2
|
+
cmake_minimum_required(VERSION 3.9.0)
|
|
3
|
+
|
|
4
|
+
set (PACKAGE_NAME "op-sqlite")
|
|
5
|
+
|
|
6
|
+
include_directories(
|
|
7
|
+
../cpp
|
|
8
|
+
../cpp/sqlcipher
|
|
9
|
+
../cpp/libsql
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
add_definitions(
|
|
13
|
+
${SQLITE_FLAGS}
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
add_library(
|
|
17
|
+
${PACKAGE_NAME}
|
|
18
|
+
SHARED
|
|
19
|
+
../cpp/bindings.cpp
|
|
20
|
+
../cpp/utils.cpp
|
|
21
|
+
../cpp/OPThreadPool.cpp
|
|
22
|
+
../cpp/SmartHostObject.cpp
|
|
23
|
+
../cpp/PreparedStatementHostObject.cpp
|
|
24
|
+
../cpp/DumbHostObject.cpp
|
|
25
|
+
../cpp/DBHostObject.cpp
|
|
26
|
+
cpp-adapter.cpp
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
if (USE_SQLCIPHER)
|
|
30
|
+
target_sources(${PACKAGE_NAME} PRIVATE ../cpp/sqlcipher/sqlite3.h ../cpp/sqlcipher/sqlite3.c ../cpp/bridge.cpp ../cpp/bridge.h)
|
|
31
|
+
|
|
32
|
+
add_definitions(
|
|
33
|
+
-DOP_SQLITE_USE_SQLCIPHER=1
|
|
34
|
+
-DSQLITE_HAS_CODEC
|
|
35
|
+
-DSQLITE_TEMP_STORE=2
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
find_package(openssl REQUIRED CONFIG)
|
|
39
|
+
elseif (USE_LIBSQL)
|
|
40
|
+
target_sources(${PACKAGE_NAME} PRIVATE ../cpp/libsql/bridge.cpp)
|
|
41
|
+
|
|
42
|
+
add_definitions(
|
|
43
|
+
-DOP_SQLITE_USE_LIBSQL=1
|
|
44
|
+
)
|
|
45
|
+
else()
|
|
46
|
+
target_sources(${PACKAGE_NAME} PRIVATE ../cpp/sqlite3.h ../cpp/sqlite3.c ../cpp/bridge.cpp ../cpp/bridge.h)
|
|
47
|
+
endif()
|
|
48
|
+
|
|
49
|
+
if (USE_CRSQLITE)
|
|
50
|
+
add_definitions(
|
|
51
|
+
-DOP_SQLITE_USE_CRSQLITE=1
|
|
52
|
+
)
|
|
53
|
+
endif()
|
|
54
|
+
|
|
55
|
+
if (USE_SQLITE_VEC)
|
|
56
|
+
add_definitions(
|
|
57
|
+
-DOP_SQLITE_USE_SQLITE_VEC=1
|
|
58
|
+
)
|
|
59
|
+
endif()
|
|
60
|
+
|
|
61
|
+
find_package(ReactAndroid REQUIRED CONFIG)
|
|
62
|
+
find_package(fbjni REQUIRED CONFIG)
|
|
63
|
+
find_library(LOG_LIB log)
|
|
64
|
+
|
|
65
|
+
# Add user defined files
|
|
66
|
+
if (USER_DEFINED_SOURCE_FILES)
|
|
67
|
+
target_sources(${PACKAGE_NAME} PRIVATE ${USER_DEFINED_SOURCE_FILES})
|
|
68
|
+
|
|
69
|
+
add_definitions("-DTOKENIZERS_HEADER_PATH=\"${USER_DEFINED_TOKENIZERS_HEADER_PATH}\"")
|
|
70
|
+
endif()
|
|
71
|
+
|
|
72
|
+
if (USE_SQLCIPHER)
|
|
73
|
+
if (ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
74
|
+
target_link_libraries(
|
|
75
|
+
${PACKAGE_NAME}
|
|
76
|
+
${LOG_LIB}
|
|
77
|
+
ReactAndroid::reactnative
|
|
78
|
+
ReactAndroid::jsi
|
|
79
|
+
fbjni::fbjni
|
|
80
|
+
openssl::crypto
|
|
81
|
+
)
|
|
82
|
+
else()
|
|
83
|
+
target_link_libraries(
|
|
84
|
+
${PACKAGE_NAME}
|
|
85
|
+
${LOG_LIB}
|
|
86
|
+
fbjni::fbjni
|
|
87
|
+
ReactAndroid::jsi
|
|
88
|
+
ReactAndroid::turbomodulejsijni
|
|
89
|
+
ReactAndroid::react_nativemodule_core
|
|
90
|
+
android
|
|
91
|
+
openssl::crypto
|
|
92
|
+
)
|
|
93
|
+
endif()
|
|
94
|
+
elseif (USE_LIBSQL)
|
|
95
|
+
cmake_path(SET LIBSQL ${CMAKE_CURRENT_SOURCE_DIR}/jniLibs/${ANDROID_ABI}/libsql_experimental.a NORMALIZE)
|
|
96
|
+
add_library(libsql STATIC IMPORTED)
|
|
97
|
+
set_target_properties(libsql PROPERTIES IMPORTED_LOCATION ${LIBSQL})
|
|
98
|
+
|
|
99
|
+
if (ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
100
|
+
target_link_libraries(
|
|
101
|
+
${PACKAGE_NAME}
|
|
102
|
+
${LOG_LIB}
|
|
103
|
+
ReactAndroid::reactnative
|
|
104
|
+
ReactAndroid::jsi
|
|
105
|
+
fbjni::fbjni
|
|
106
|
+
libsql
|
|
107
|
+
)
|
|
108
|
+
else()
|
|
109
|
+
target_link_libraries(
|
|
110
|
+
${PACKAGE_NAME}
|
|
111
|
+
${LOG_LIB}
|
|
112
|
+
fbjni::fbjni
|
|
113
|
+
ReactAndroid::jsi
|
|
114
|
+
ReactAndroid::turbomodulejsijni
|
|
115
|
+
ReactAndroid::react_nativemodule_core
|
|
116
|
+
android
|
|
117
|
+
libsql
|
|
118
|
+
)
|
|
119
|
+
endif()
|
|
120
|
+
else ()
|
|
121
|
+
# if (REACTNATIVE_MERGED_SO)
|
|
122
|
+
if (ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
123
|
+
target_link_libraries(
|
|
124
|
+
${PACKAGE_NAME}
|
|
125
|
+
${LOG_LIB}
|
|
126
|
+
ReactAndroid::reactnative
|
|
127
|
+
ReactAndroid::jsi
|
|
128
|
+
fbjni::fbjni
|
|
129
|
+
)
|
|
130
|
+
else()
|
|
131
|
+
target_link_libraries(
|
|
132
|
+
${PACKAGE_NAME}
|
|
133
|
+
${LOG_LIB}
|
|
134
|
+
fbjni::fbjni
|
|
135
|
+
ReactAndroid::jsi
|
|
136
|
+
ReactAndroid::turbomodulejsijni
|
|
137
|
+
ReactAndroid::react_nativemodule_core
|
|
138
|
+
android
|
|
139
|
+
)
|
|
140
|
+
endif()
|
|
141
|
+
endif()
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import java.nio.file.Paths
|
|
2
|
+
import groovy.json.JsonSlurper
|
|
3
|
+
|
|
4
|
+
buildscript {
|
|
5
|
+
repositories {
|
|
6
|
+
google()
|
|
7
|
+
gradlePluginPortal()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["OPSQLite_kotlinVersion"]
|
|
11
|
+
|
|
12
|
+
dependencies {
|
|
13
|
+
classpath("com.android.tools.build:gradle:7.3.1")
|
|
14
|
+
// noinspection DifferentKotlinGradleVersion
|
|
15
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
def resolveBuildType() {
|
|
20
|
+
Gradle gradle = getGradle()
|
|
21
|
+
String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString()
|
|
22
|
+
|
|
23
|
+
return tskReqStr.contains('Release') ? 'release' : 'debug'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def isNewArchitectureEnabled() {
|
|
27
|
+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def useSQLCipher = false
|
|
31
|
+
def useLibsql = false
|
|
32
|
+
def useCRSQLite = false
|
|
33
|
+
def performanceMode = false
|
|
34
|
+
def sqliteFlags = ""
|
|
35
|
+
def enableFTS5 = false
|
|
36
|
+
def useSqliteVec = false
|
|
37
|
+
def enableRtree = false
|
|
38
|
+
def tokenizers = []
|
|
39
|
+
|
|
40
|
+
def isInsideNodeModules = rootDir.absolutePath.contains("node_modules")
|
|
41
|
+
def packageJson
|
|
42
|
+
|
|
43
|
+
if ( isInsideNodeModules ) {
|
|
44
|
+
def packageJsonFile = new File("$rootDir/../../../package.json")
|
|
45
|
+
packageJson = new JsonSlurper().parseText(packageJsonFile.text)
|
|
46
|
+
} else {
|
|
47
|
+
def packageJsonFile = new File("$rootDir/../package.json")
|
|
48
|
+
packageJson = new JsonSlurper().parseText(packageJsonFile.text)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
def opsqliteConfig = packageJson["op-sqlite"]
|
|
52
|
+
if(opsqliteConfig) {
|
|
53
|
+
useSQLCipher = opsqliteConfig["sqlcipher"]
|
|
54
|
+
useCRSQLite = opsqliteConfig["crsqlite"]
|
|
55
|
+
useSqliteVec = opsqliteConfig["sqliteVec"]
|
|
56
|
+
performanceMode = opsqliteConfig["performanceMode"]
|
|
57
|
+
sqliteFlags = opsqliteConfig["sqliteFlags"] ? opsqliteConfig["sqliteFlags"] : ""
|
|
58
|
+
enableFTS5 = opsqliteConfig["fts5"]
|
|
59
|
+
useLibsql = opsqliteConfig["libsql"]
|
|
60
|
+
enableRtree = opsqliteConfig["rtree"]
|
|
61
|
+
tokenizers = opsqliteConfig["tokenizers"] ? opsqliteConfig["tokenizers"] : []
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if(useSQLCipher) {
|
|
65
|
+
println "[OP-SQLITE] using SQLCipher 🔒"
|
|
66
|
+
} else if(useLibsql) {
|
|
67
|
+
println "[OP-SQLITE] using libsql 📦"
|
|
68
|
+
} else {
|
|
69
|
+
println "[OP-SQLITE] using Vanilla SQLite"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if(useCRSQLite) {
|
|
73
|
+
println "[OP-SQLITE] using CR-SQLite 🤖"
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if(performanceMode) {
|
|
77
|
+
println "[OP-SQLITE] Performance mode enabled! 🚀"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if(enableFTS5) {
|
|
81
|
+
println "[OP-SQLITE] FTS5 enabled! 🔎"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if(enableRtree) {
|
|
85
|
+
println "[OP-SQLITE] RTree enabled! 🌲"
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if(useSqliteVec) {
|
|
89
|
+
println "[OP-SQLITE] Sqlite Vec enabled! ↗️"
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if (!tokenizers.isEmpty()) {
|
|
94
|
+
println "[OP-SQLITE] Tokenizers enabled! 🧾 Tokenizers: " + tokenizers
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (isNewArchitectureEnabled()) {
|
|
98
|
+
apply plugin: "com.facebook.react"
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
apply plugin: 'com.android.library'
|
|
102
|
+
apply plugin: "kotlin-android"
|
|
103
|
+
|
|
104
|
+
def safeExtGet(prop, fallback) {
|
|
105
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
def getExtOrDefault(name) {
|
|
109
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["OPSQLite" + name]
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
android {
|
|
113
|
+
|
|
114
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 33)
|
|
115
|
+
namespace "com.op.sqlite"
|
|
116
|
+
|
|
117
|
+
// Used to override the NDK path/version on internal CI or by allowing
|
|
118
|
+
// users to customize the NDK path/version from their root project (e.g. for M1 support)
|
|
119
|
+
if (rootProject.hasProperty("ndkPath")) {
|
|
120
|
+
ndkPath rootProject.ext.ndkPath
|
|
121
|
+
}
|
|
122
|
+
if (rootProject.hasProperty("ndkVersion")) {
|
|
123
|
+
ndkVersion rootProject.ext.ndkVersion
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
buildFeatures {
|
|
127
|
+
prefab true
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
defaultConfig {
|
|
131
|
+
minSdkVersion safeExtGet("minSdkVersion", 24)
|
|
132
|
+
targetSdkVersion safeExtGet('targetSdkVersion', 35)
|
|
133
|
+
versionCode 1
|
|
134
|
+
versionName "1.0"
|
|
135
|
+
|
|
136
|
+
externalNativeBuild {
|
|
137
|
+
cmake {
|
|
138
|
+
if(useSQLCipher) {
|
|
139
|
+
cFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
|
|
140
|
+
cppFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
|
|
141
|
+
}
|
|
142
|
+
if(useLibsql) {
|
|
143
|
+
cFlags += "-DOP_SQLITE_USE_LIBSQL=1"
|
|
144
|
+
cppFlags += "-DOP_SQLITE_USE_LIBSQL=1"
|
|
145
|
+
}
|
|
146
|
+
if(useCRSQLite) {
|
|
147
|
+
cFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
|
|
148
|
+
cppFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
|
|
149
|
+
}
|
|
150
|
+
if(performanceMode) {
|
|
151
|
+
cFlags += ["-DSQLITE_DQS=0", "-DSQLITE_THREADSAFE=1", "-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"]
|
|
152
|
+
}
|
|
153
|
+
if(enableFTS5) {
|
|
154
|
+
cFlags += ["-DSQLITE_ENABLE_FTS5=1"]
|
|
155
|
+
}
|
|
156
|
+
if(enableRtree) {
|
|
157
|
+
cFlags += ["-DSQLITE_ENABLE_RTREE=1"]
|
|
158
|
+
}
|
|
159
|
+
if(useSqliteVec) {
|
|
160
|
+
cFlags += "-DOP_SQLITE_USE_SQLITE_VEC=1"
|
|
161
|
+
cppFlags += "-DOP_SQLITE_USE_SQLITE_VEC=1"
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// This are zeroes because they will be passed as C flags, so they become falsy
|
|
165
|
+
def sourceFiles = 0
|
|
166
|
+
// def tokenizerInitStrings = 0
|
|
167
|
+
def tokenizersHeaderPath = 0
|
|
168
|
+
if (!tokenizers.isEmpty()) {
|
|
169
|
+
def sourceDir = isInsideNodeModules ? file("$rootDir/../../../c_sources") : file("$rootDir/../c_sources")
|
|
170
|
+
def destDir = file("$buildscript.sourceFile.parentFile/c_sources")
|
|
171
|
+
copy {
|
|
172
|
+
from sourceDir
|
|
173
|
+
into destDir
|
|
174
|
+
include "**/*.cpp", "**/*.h"
|
|
175
|
+
}
|
|
176
|
+
sourceFiles = fileTree(dir: destDir, include: ["**/*.cpp", "**/*.h"]).files.join(";")
|
|
177
|
+
tokenizersHeaderPath = "../c_sources/tokenizers.h"
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
|
|
181
|
+
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
|
|
182
|
+
arguments "-DANDROID_STL=c++_shared",
|
|
183
|
+
"-DSQLITE_FLAGS='$sqliteFlags'",
|
|
184
|
+
"-DUSE_SQLCIPHER=${useSQLCipher ? 1 : 0}",
|
|
185
|
+
"-DUSE_CRSQLITE=${useCRSQLite ? 1 : 0}",
|
|
186
|
+
"-DUSE_LIBSQL=${useLibsql ? 1 : 0}",
|
|
187
|
+
"-DUSE_SQLITE_VEC=${useSqliteVec ? 1 : 0}",
|
|
188
|
+
"-DUSER_DEFINED_SOURCE_FILES=${sourceFiles}",
|
|
189
|
+
"-DUSER_DEFINED_TOKENIZERS_HEADER_PATH='${tokenizersHeaderPath}'"
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
packagingOptions {
|
|
194
|
+
doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : ''
|
|
195
|
+
excludes = [
|
|
196
|
+
"META-INF",
|
|
197
|
+
"META-INF/**",
|
|
198
|
+
"**/libjsi.so",
|
|
199
|
+
"**/libreact_nativemodule_core.so",
|
|
200
|
+
"**/libturbomodulejsijni.so",
|
|
201
|
+
"**/libc++_shared.so",
|
|
202
|
+
"**/libfbjni.so",
|
|
203
|
+
"**/libreactnative.so",
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
compileOptions {
|
|
210
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
211
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
externalNativeBuild {
|
|
215
|
+
cmake {
|
|
216
|
+
path "CMakeLists.txt"
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
sourceSets.main {
|
|
221
|
+
java {
|
|
222
|
+
// TODO removed the codegen config to allow the package to be built under bridgeless
|
|
223
|
+
// Once there is a stable API for C++ Turbo Modules, maybe this can be enabled again
|
|
224
|
+
// if (!isNewArchitectureEnabled()) {
|
|
225
|
+
srcDirs += 'src/paper/java'
|
|
226
|
+
// }
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
repositories {
|
|
232
|
+
mavenCentral()
|
|
233
|
+
google()
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
237
|
+
dependencies {
|
|
238
|
+
implementation 'com.facebook.react:react-native'
|
|
239
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
240
|
+
if (useSQLCipher) {
|
|
241
|
+
implementation('com.android.ndk.thirdparty:openssl:1.1.1q-beta-1')
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Resolves "LOCAL_SRC_FILES points to a missing file, Check that libfb.so exists or that its path is correct".
|
|
246
|
+
tasks.whenTaskAdded { task ->
|
|
247
|
+
if (task.name.contains("configureCMakeDebug")) {
|
|
248
|
+
rootProject.getTasksByName("packageReactNdkDebugLibs", true).forEach {
|
|
249
|
+
task.dependsOn(it)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// We want to add a dependency for both configureCMakeRelease and configureCMakeRelWithDebInfo
|
|
253
|
+
if (task.name.contains("configureCMakeRel")) {
|
|
254
|
+
rootProject.getTasksByName("packageReactNdkReleaseLibs", true).forEach {
|
|
255
|
+
task.dependsOn(it)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (isNewArchitectureEnabled()) {
|
|
261
|
+
react {
|
|
262
|
+
jsRootDir = file("../src/")
|
|
263
|
+
libraryName = "opsqlite"
|
|
264
|
+
codegenJavaPackageName = "com.op.sqlite.example"
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#include "tokenizers.h"
|
|
2
|
+
#include <cctype>
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
namespace opsqlite {
|
|
7
|
+
|
|
8
|
+
fts5_api *fts5_api_from_db(sqlite3 *db) {
|
|
9
|
+
fts5_api *pRet = 0;
|
|
10
|
+
sqlite3_stmt *pStmt = 0;
|
|
11
|
+
|
|
12
|
+
if (SQLITE_OK == sqlite3_prepare_v2(db, "SELECT fts5(?1)", -1, &pStmt, 0)) {
|
|
13
|
+
sqlite3_bind_pointer(pStmt, 1, (void *)&pRet, "fts5_api_ptr", NULL);
|
|
14
|
+
sqlite3_step(pStmt);
|
|
15
|
+
}
|
|
16
|
+
sqlite3_finalize(pStmt);
|
|
17
|
+
return pRet;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class WordTokenizer {
|
|
21
|
+
public:
|
|
22
|
+
WordTokenizer() = default;
|
|
23
|
+
~WordTokenizer() = default;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Define `xCreate`, which initializes the tokenizer
|
|
27
|
+
int wordTokenizerCreate(void *pUnused, const char **azArg, int nArg,
|
|
28
|
+
Fts5Tokenizer **ppOut) {
|
|
29
|
+
auto tokenizer = std::make_unique<WordTokenizer>();
|
|
30
|
+
*ppOut = reinterpret_cast<Fts5Tokenizer *>(
|
|
31
|
+
tokenizer.release()); // Cast to Fts5Tokenizer*
|
|
32
|
+
return SQLITE_OK;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Define `xDelete`, which frees the tokenizer
|
|
36
|
+
void wordTokenizerDelete(Fts5Tokenizer *pTokenizer) {
|
|
37
|
+
delete reinterpret_cast<WordTokenizer *>(pTokenizer);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Define `xTokenize`, which performs the actual tokenization
|
|
41
|
+
int wordTokenizerTokenize(Fts5Tokenizer *pTokenizer, void *pCtx, int flags,
|
|
42
|
+
const char *pText, int nText,
|
|
43
|
+
int (*xToken)(void *, int, const char *, int, int,
|
|
44
|
+
int)) {
|
|
45
|
+
int start = 0;
|
|
46
|
+
int i = 0;
|
|
47
|
+
|
|
48
|
+
while (i <= nText) {
|
|
49
|
+
if (i == nText || !std::isalnum(static_cast<unsigned char>(pText[i]))) {
|
|
50
|
+
if (start < i) { // Found a token
|
|
51
|
+
int rc = xToken(pCtx, 0, pText + start, i - start, start, i);
|
|
52
|
+
if (rc != SQLITE_OK)
|
|
53
|
+
return rc;
|
|
54
|
+
}
|
|
55
|
+
start = i + 1;
|
|
56
|
+
}
|
|
57
|
+
i++;
|
|
58
|
+
}
|
|
59
|
+
return SQLITE_OK;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
int opsqlite_wordtokenizer_init(sqlite3 *db, char **error,
|
|
63
|
+
sqlite3_api_routines const *api) {
|
|
64
|
+
fts5_tokenizer wordtokenizer = {wordTokenizerCreate, wordTokenizerDelete,
|
|
65
|
+
wordTokenizerTokenize};
|
|
66
|
+
|
|
67
|
+
fts5_api *ftsApi = (fts5_api *)fts5_api_from_db(db);
|
|
68
|
+
if (ftsApi == NULL)
|
|
69
|
+
return SQLITE_ERROR;
|
|
70
|
+
|
|
71
|
+
return ftsApi->xCreateTokenizer(ftsApi, "wordtokenizer", NULL, &wordtokenizer,
|
|
72
|
+
NULL);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
int opsqlite_porter_init(sqlite3 *db, char **error,
|
|
76
|
+
sqlite3_api_routines const *api) {
|
|
77
|
+
fts5_tokenizer porter_tokenizer = {wordTokenizerCreate, wordTokenizerDelete,
|
|
78
|
+
wordTokenizerTokenize};
|
|
79
|
+
|
|
80
|
+
fts5_api *ftsApi = (fts5_api *)fts5_api_from_db(db);
|
|
81
|
+
if (ftsApi == nullptr)
|
|
82
|
+
return SQLITE_ERROR;
|
|
83
|
+
|
|
84
|
+
return ftsApi->xCreateTokenizer(ftsApi, "portertokenizer", NULL,
|
|
85
|
+
&porter_tokenizer, NULL);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
} // namespace opsqlite
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#ifndef TOKENIZERS_H
|
|
2
|
+
#define TOKENIZERS_H
|
|
3
|
+
|
|
4
|
+
#define TOKENIZER_LIST opsqlite_wordtokenizer_init(db,&errMsg,nullptr);opsqlite_porter_init(db,&errMsg,nullptr);
|
|
5
|
+
|
|
6
|
+
#include <sqlite3.h>
|
|
7
|
+
|
|
8
|
+
namespace opsqlite {
|
|
9
|
+
|
|
10
|
+
int opsqlite_wordtokenizer_init(sqlite3 *db, char **error, sqlite3_api_routines const *api);
|
|
11
|
+
int opsqlite_porter_init(sqlite3 *db, char **error, sqlite3_api_routines const *api);
|
|
12
|
+
|
|
13
|
+
} // namespace opsqlite
|
|
14
|
+
|
|
15
|
+
#endif // TOKENIZERS_H
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#include "bindings.h"
|
|
2
|
+
#include "logs.h"
|
|
3
|
+
#include <ReactCommon/CallInvokerHolder.h>
|
|
4
|
+
#include <fbjni/fbjni.h>
|
|
5
|
+
#include <jni.h>
|
|
6
|
+
#include <jsi/jsi.h>
|
|
7
|
+
#include <typeinfo>
|
|
8
|
+
|
|
9
|
+
namespace jsi = facebook::jsi;
|
|
10
|
+
namespace react = facebook::react;
|
|
11
|
+
namespace jni = facebook::jni;
|
|
12
|
+
|
|
13
|
+
// This file is not using raw jni but rather fbjni, do not change how the native
|
|
14
|
+
// functions are registered
|
|
15
|
+
// https://github.com/facebookincubator/fbjni/blob/main/docs/quickref.md
|
|
16
|
+
struct OPSQLiteBridge : jni::JavaClass<OPSQLiteBridge> {
|
|
17
|
+
static constexpr auto kJavaDescriptor = "Lcom/op/sqlite/OPSQLiteBridge;";
|
|
18
|
+
|
|
19
|
+
static void registerNatives() {
|
|
20
|
+
javaClassStatic()->registerNatives(
|
|
21
|
+
{makeNativeMethod("installNativeJsi", OPSQLiteBridge::installNativeJsi),
|
|
22
|
+
makeNativeMethod("clearStateNativeJsi",
|
|
23
|
+
OPSQLiteBridge::clearStateNativeJsi)});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private:
|
|
27
|
+
static void installNativeJsi(
|
|
28
|
+
jni::alias_ref<jni::JObject> thiz, jlong jsiRuntimePtr,
|
|
29
|
+
jni::alias_ref<react::CallInvokerHolder::javaobject> jsCallInvokerHolder,
|
|
30
|
+
jni::alias_ref<jni::JString> dbPath) {
|
|
31
|
+
auto jsiRuntime = reinterpret_cast<jsi::Runtime *>(jsiRuntimePtr);
|
|
32
|
+
auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();
|
|
33
|
+
std::string dbPathStr = dbPath->toStdString();
|
|
34
|
+
|
|
35
|
+
opsqlite::install(*jsiRuntime, jsCallInvoker, dbPathStr.c_str(),
|
|
36
|
+
"libcrsqlite", "libsqlite_vec");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static void clearStateNativeJsi(jni::alias_ref<jni::JObject> thiz) {
|
|
40
|
+
opsqlite::invalidate();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) {
|
|
45
|
+
return jni::initialize(vm, [] { OPSQLiteBridge::registerNatives(); });
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
OPSQLite_kotlinVersion=1.9.22
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"/>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
package com.op.sqlite
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactContext
|
|
4
|
+
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
|
|
5
|
+
import com.facebook.react.common.annotations.FrameworkAPI
|
|
6
|
+
|
|
7
|
+
@OptIn(FrameworkAPI::class)
|
|
8
|
+
class OPSQLiteBridge {
|
|
9
|
+
private external fun installNativeJsi(
|
|
10
|
+
jsContextNativePointer: Long,
|
|
11
|
+
jsCallInvokerHolder: CallInvokerHolderImpl,
|
|
12
|
+
docPath: String
|
|
13
|
+
)
|
|
14
|
+
private external fun clearStateNativeJsi()
|
|
15
|
+
|
|
16
|
+
fun install(context: ReactContext) {
|
|
17
|
+
val jsContextPointer = context.javaScriptContextHolder!!.get()
|
|
18
|
+
val jsCallInvokerHolder =
|
|
19
|
+
context.catalystInstance.jsCallInvokerHolder as CallInvokerHolderImpl
|
|
20
|
+
// Trick to get the base database path
|
|
21
|
+
val dbPath =
|
|
22
|
+
context.getDatabasePath("defaultDatabase").absolutePath.replace("defaultDatabase", "")
|
|
23
|
+
installNativeJsi(
|
|
24
|
+
jsContextPointer,
|
|
25
|
+
jsCallInvokerHolder,
|
|
26
|
+
dbPath
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fun invalidate() {
|
|
31
|
+
clearStateNativeJsi()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
companion object {
|
|
35
|
+
val instance = OPSQLiteBridge()
|
|
36
|
+
}
|
|
37
|
+
}
|