By Oscar Franco
Twitter β’ YouTube β’ [Email](mailto:[email protected]?subject=I%20need%20a%20Freelancer)
Installing is easy
npm i -s @op-engineering/op-sqlite && npx pod-install
SQLite is very customizable on compilation level. op-sqlite also allows you add extensions or even change the base implementation. You can do this by adding the following to your package.json
:
{
// your normal package.json
// ...
"op-sqlite": {
"sqlcipher": false,
"crsqlite": false,
"performanceMode": true,
"iosSqlite": false,
"sqliteFlags": "-DSQLITE_DQS=0",
"fts5": true,
"rtree": true,
"libsql": false,
"sqliteVec": true,
"tokenizers": ["simple_tokenizer"]
}
}
All keys are optional, only turn on the features you want:
sqlcipher
allows to change the base sqlite implementation to sqlcipher, which encrypts all the database data with minimal overhead. You will still need to keep your encryption key secure. Read more about security in React Native here.crsqlite
is an extension that allows replication to a server backed sqlite database copy. Repo here.performanceMode
turns on certain compilation flags that make sqlite speedier at the cost of disabling some features. You should almost always turn this on, but test your app thoroughly.iosSqlite
uses the embedded iOS version from sqlite, which saves disk space but may use an older version and cannot load extensions as Apple disables it due to security concerns. On Android SQLite is always compiled from source as each vendor messes with sqlite or uses outdated versions.sqliteFlags
allows you to pass your own compilation flags to further disable/enable features and extensions. It follows the C flag format: -D[YOUR_FLAG]=[YOUR_VALUE]
. If you are running large queries on large databases sometimes on Android devices you might get a IO exception. You can disable temporary files by using adding the "-DSQLITE_TEMP_STORE=2"
flag.fts5
enables the full text search extension.tokenizers
allows you to write your own C tokenizers. Read more in the corresponding section in this documentation.rtree
enables the rtree extensionsqliteVec
enables sqlite-vec, an extension for RAG embeddingsSome combination of features are not allowed. For example sqlcipher
and iosSqlite
since they are fundamentally different sources. In this cases you will get an error while doing a pod install or during the Android build.
In case you are using use_frameworks
(for example because you are using react-native-firebase) this will break the compilation process and force the compilation to use the embedded sqlite on iOS. One possible workaround is putting this in your Podfile
:
pre_install do |installer|
installer.pod_targets.each do |pod|
if pod.name.eql?('op-sqlite')
def pod.build_type
Pod::BuildType.static_library
end
end
end
end
It forces static compilation on op-sqlite
only. Since everything is compiled from sources this SHOULD work, however do it at your own risk since other compilation errors might arise. It is possible you will not get any error, but you will not be using the latest version of sqlite but rather the OS embedded one.