SqlDelightStorageProvider

StorageProvider backed by SQLDelight + SQLite, keyed by radio NodeNum so the same physical device shares one database across transports (BLE ↔ TCP ↔ serial).

File layout

<baseDir>/
.meshtastic-index ← identity ↔ nodeNum ↔ opaque-dbId bindings
<dbId>.db ← one SQLite DB per radio (opaque filename)

Activation flow

  1. activate(identity) reads the index.

    • If identity → dbId mapping exists, open <dbId>.db directly.

    • Otherwise return a deferred wrapper that buffers reads/writes in-memory until the radio's NodeNum is learned via DeviceStorage.recordOwnNode.

  2. On first recordOwnNode(nodeNum, …) for a deferred wrapper:

    • If nodeNum → dbId mapping already exists (same radio already reached via another transport), open that DB; buffered scratch state is replayed into it.

    • Otherwise allocate a fresh opaque dbId, create <dbId>.db, replay scratch.

    • Persist both identity → dbId and nodeNum → dbId bindings atomically.

  3. If a later recordOwnNode reports a different nodeNum (factory reset / radio swap), the inner storage's own factory-reset logic clears the DB; the provider updates the nodeNum → dbId binding so the old NodeNum no longer resolves to this DB.

Pass baseDir = "" for in-memory-only mode (every activation returns a fresh in-memory DB).

Parameters

baseDir

path to the directory where database files and the index live

Constructors

Link copied to clipboard
constructor(baseDir: String = "")

Functions

Link copied to clipboard
open suspend override fun activate(identity: TransportIdentity): DeviceStorage