Open lamba92 opened 5 years ago
@lamba92 Do you have any suggestion about how I could test Exposed against android sqlite?
I'd say a Gradle module with the Android plugin. You can launch an activity and initialize something like this:
class CacheTransactionManagerImpl @Inject constructor(val context: Context) : CacheTransactionManager {
private val database by lazy {
Database.connectSQLite(File(context.cacheDir, "localCache.sqlite").absolutePath)
.also {
serializableTransaction(it) { SchemaUtils.createMissingTablesAndColumns(...) }
}
}
override fun <T> execute(block: Transaction.() -> T) = serializableTransaction(database, function = block)
}
You can either provide a context using DI or just creating it during execution.
As soon as some R/W operation occurs, all the lazy variables will be triggered until metadata.url
is requested, returns null
and Kotlin throws NPE.
What is it now
@lisonge We do use Exposed on Android. I've ported the SQLDroid driver and fixed the few problems Exposed had with it.
You can find some basic documents here: https://zakadabar.io/en/Documentation/guides/android/Introduction.md. This is an Apache 2.0 project, you can use the dependency from Maven Central as we do or copy the code.
You can see a working example in this recipe: Database Transfer to Android.
@toth-istvan-zoltan
now I use room , and a custom encapsulation framework that like Exposed to solve stackoverflow/71995278 on room
I may be mistaken but, no JDBC driver works for SQLite on Android, which means no SQLite Exposed on Android.
Here's a list of issues related to that problem:
UnsatisfiedLinkError
IllegalArgumentException
when trying to create tablesSQLDroid is out of question since the jdbc postfix is not one of the registered here, unless adding something like:
Anybody has a solution so far? I was happy to try Exposed on Android as well to replace Room but so far no success 😢
Digging a little deep I noticed that the problem resides in the
metadata.url
in theDatabase
class here.metadata.url
returnsnull
instead of the actual URL and since everything is evaluated lazily the error message gets a little confused. This happens with the SQLDroid drivers as well and I was not able to figure out why 😕