OP SQLite

Installation

Configuration

Gotchas

Debugging

API


osp_circle.png

By Oscar Franco

Freelancer, RN/Rust magic

Twitter β€’ YouTube β€’ [Email](mailto:[email protected]?subject=I%20need%20a%20Freelancer)

Installing is easy

npm i -s @op-engineering/op-sqlite && npx pod-install

Configuration

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": true,
	  "crsqlite": true,
	  "performanceMode": "1",
	  "iosSqlite": false,
	  "sqliteFlags": "-DSQLITE_DQS=0",
	  "fts5": true
	}
}

Some 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 a Gradle build.

🚨🚨🚨 IOS PODS USE_FRAMEWORKS BREAKS OP-SQLITE 🚨🚨🚨

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.

Runtime loadable extensions

You can load your own extensions on runtime.

db.loadExtension('/path/to/library.so', 'optional_entry_point_function_name');

You will need to compile your extension for both iOS and Android and all the respective architectures and make it available in a location the library can read (be careful about sandboxing).