Hi, it's Takuya.
I'm building a note-taking app called Inkdrop for mobile using React Native.
The app uses react-native-quick-sqlite, a fast wrapper of SQLite:
ospfranco / react-native-quick-sqlite
Fast SQLite for react-native.
New package op-sqlite. It is a lot faster and consumes much less memory.
It embeds the latest version of SQLite in C/C++.
That means that you build SQLite from source in your RN project on Xcode and Android Studio (CMake).
It doesn't enable any compile-time options by default, and I needed to enable FTS5 for full-text search in my app.
It can be enabled by specifying a SQLITE_ENABLE_FTS5
pre-processor flag when compiling.
I've managed to enable FTS5 and I'd like to share how to do that in your project.
For Android, the library needs to make some changes. So, it'd be helpful for library maintainers who would support accepting custom build flags.
iOS
Fortunately, CocoaPods allows you to customize the pods project settings via Podfile
:
Add a post_install
block to your <PROJECT_ROOT>/ios/Podfile
like so:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "react-native-quick-sqlite" then
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '<SQLITE_FLAGS>']
end
end
end
end
Replace the <SQLITE_FLAGS>
part with flags you want to add.
For example, you could add SQLITE_ENABLE_FTS5=1
to GCC_PREPROCESSOR_DEFINITIONS
to enable FTS5 in the iOS project.
Android
The native modules are compiled with CMake that reads CMakeLists.txt
.
CMake supports adding flags with add_definitions
command.
Add the following lines in the library's CMakeLists.txt:
add_definitions(
${SQLITE_FLAGS}
)
It specifies flags via the variable SQLITE_FLAGS
, which needs to be specified in react-native-quick-sqlite/android/build.gradle
like so:
def SQLITE_FLAGS = rootProject.properties['quickSqliteFlags']
android {
defaultConfig {
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared',
"-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION}",
"-DNODE_MODULES_DIR=${nodeModules}",
"-DSQLITE_FLAGS='${SQLITE_FLAGS ? SQLITE_FLAGS : ''}'"
}
}
Now, you can define the flags in your <PROJECT_ROOT>/android/gradle.properties
like so:
quickSqliteFlags="<SQLITE_FLAGS>"
That's it!
I've sent a pull request to the quick sqlite repository:
feat(ios&android): Support specifying pre-processor flags to sqlite #86
I've managed to enable FTS5 on both iOS and Android by specifying pre-processor flags.
On Android, we need to accept a setting from the parent project.
This PR makes it possible to specify SQLite flags via android/gradle.properties
.
Also, I've added instructions on how to do that for iOS and Android. Maybe the grammar could be improved tho.
fix #37
Hope that helps.
Follow me online
- Check out my app called Inkdrop — A Markdown note-taking app
- Twitter https://twitter.com/inkdrop_app
- Blog https://blog.inkdrop.app/
- YouTube https://www.youtube.com/devaslife
- Instagram https://instagram.com/craftzdog
Top comments (1)
I do not understand the following thing: why would I use something apart from the regular SQL?