DatabaseManager

Manages per-device Room database instances for node data, with LRU eviction.

Constructors

Link copied to clipboard
constructor(datastore: DataStore<Preferences>, dispatchers: CoroutineDispatchers)

Properties

Link copied to clipboard
open override val cacheLimit: StateFlow<Int>
Link copied to clipboard
val currentAddress: StateFlow<String?>
Link copied to clipboard
open override val currentDb: StateFlow<MeshtasticDatabase>

The currently active database, built lazily on first access. Room's onOpen callback is itself lazy (not invoked until the first query), so construction only allocates the builder and connection pool — actual I/O is deferred.

Functions

Link copied to clipboard
fun close()

Closes all open databases and cancels background work.

Link copied to clipboard
open override fun getCurrentCacheLimit(): Int
Link copied to clipboard
open override fun hasDatabaseFor(address: String?): Boolean

Returns true if a database exists for the given device address. Android Room stores DB files without an extension; JVM/iOS append .db. We check both to stay platform-agnostic.

Link copied to clipboard
suspend fun init(address: String?)

Initialize the active database for address.

Link copied to clipboard
open override fun setCacheLimit(limit: Int)
Link copied to clipboard
open suspend override fun switchActiveDatabase(address: String?)

Switch active database to the one associated with address. Serialized via mutex.

Link copied to clipboard
open suspend override fun <T> withDb(block: suspend (MeshtasticDatabase) -> T): T?

Execute block with the current DB instance.