My solution is to use directly the ReactDatabaseSupplier
class (my app doesn't use Rocksdb
so I can be quite sure that the SQLite DB is always used as storage (and, I guess it will always prefer the SQLite database over local storage))
The database is a simple key-value DB (two columns, key
and value
), with a table name 'catalystLocalStorage' (you can try to read the ReactDatabaseSupplier#TABLE_NAME
but it's protected, you can try using reflection, but I'm not sure it's worth the troubles)
Cursor catalystLocalStorage = null;
SQLiteDatabase readableDatabase = null;
try {
readableDatabase = ReactDatabaseSupplier.getInstance(this.getApplicationContext()).getReadableDatabase();
catalystLocalStorage = readableDatabase.query("catalystLocalStorage", new String[]{"value"}, "key = ?", new String[] { "keyName" }, null, null, null);
final String value = catalystLocalStorage.getString(catalystLocalStorage.getColumnIndex("value"));
[...]
} finally {
if (catalystLocalStorage != null) {
catalystLocalStorage.close();
}
if (readableDatabase != null) {
readableDatabase.close();
}
}
It works to me, not sure how future-proof it can be