id | title | sidebar_label |
---|---|---|
next |
Next storage implementation |
Next storage implementation |
import PlatformSupport from "../../src/components/Platform.js"
Supported platforms:
Current implementation of persistence layer is created using SQLiteOpenHelper, a helper class that manages database creation and migrations. Even if this approach is powerful, the lack of compile time query verification and a big boilerplate of mapping SQLite queries to actual values make this implementation prone to many errors.
This Async Storage feature improves the persistence layer, using modern approaches to access SQLite (using Room), to reduce possible anomalies to the minimum. On top of that, it allows accessing AsyncStorage from the native side, useful in Brownfield integration.
This feature requires no migration from the developer perspective - the current database will be recreated (based on the current one), meaning user won't lose any data if you decide to opt in. There's a small drawback to know - the database "recreation" happens only once.
The new database (the one used by this feature) will be created based on the current database file, if the new one does not exist yet. If we detect that there's already the new database on the device, recreation will not kick in.
Let's say you enabled the feature for the first time - recreation kicks in and the old database file is untouched. If you decide to disable the feature, your users will be back using old database. No data migrations is happening from new to old database file. When you enable the feature again, the new database is not recreated, because it already exists, and no data is copied over.
See Configuration section below to learn more about setting different versions of Kotlin or Room.
- In your project's
android
directory, locate rootbuild.gradle
file. Add Kotlin dependency to thebuildscript
:
buildscript {
ext {
// other extensions
+ kotlinVersion = '1.5.31'
}
dependencies {
// other dependencies
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
- In the same directory (normally
android
) locategradle.properties
file (if it does not exist, create one) and add the line:
AsyncStorage_useNextStorage=true
Kotlin version
Next storage is tested against Kotlin version 1.5.31
.
You can specify different version, in one of two ways:
- add
kotlinVersion
extension to therootProject
:
rootProject.ext.kotlinVersion = '1.5.31'
- specify
AsyncStorage_kotlinVersion
ingradle.properties
:
AsyncStorage_kotlinVersion=1.5.31
Room
Next AsyncStorage uses Room persistence library to store data.
Currently, tested version is 2.3.0
. You can specify different version, by adding a flag to gradle.properties
:
AsyncStorage_next_roomVersion=2.3.0
Alongside of a warning regarding key
/value
, errors are thrown when:
- Your
key
isnull
ornot a string
- You provide value that is
not a string