In my Flutter app I'm using sqflite to talk to a local database. I need to peek into JSON data. The JSON1 extension would be ideal for this. However, I can't load the extension in a Flutter app to make it available in my queries since the documentation is for C, not Dart.
- Should I compile in different architectures for iOS and Android?
- Where should the compiled file(s) be placed? I assume it's not added as an asset.
- How to access/load the C extension in my Flutter/Dart code?
Suggestions for other well supported local databases (document databases or databases that support JSON queries) for Flutter are also welcome. I looked into Couchbase Lite, but the plugins (Fluttercouch, couchbase-lite-flutter) are still under development.
By default,
sqflite
uses the OS-supplied version of SQLite, which may not have json1 enabled.Instead, use
sqflite_ffi
, which would ship a copy of SQLite with your application. Any recent version would include json1 automatically.The process is explained here: https://github.com/tekartik/sqflite/blob/master/sqflite_common_ffi/doc/using_ffi_instead_of_sqflite.md
The gist is:
sqflite_common_ffi
andsqlite3_flutter_libs
dependencies (in addition tosqflite
).sqfliteFfiInit()
before opening the databasesqflite
in your app.An added advantage is that the ffi version also has much better performance.