Expand description
Database layer — SQLite with per-account databases.
Architecture:
- Read pool: multiple connections for parallel reads (WAL mode)
- Write pool: single Mutex-protected connection (serialized writes)
- RAII guards: auto-return connections to pools on drop
All connection functions use static DATA_DIR — no Tauri AppHandle required.
Re-exports§
pub use settings::get_sql_setting;pub use settings::set_sql_setting;pub use settings::get_pkey;pub use settings::set_pkey;pub use settings::get_seed;pub use settings::set_seed;pub use settings::remove_setting;pub use settings::get_signer_type;pub use settings::set_signer_type;pub use settings::get_bunker_url;pub use settings::set_bunker_url;pub use settings::get_bunker_remote_pubkey;pub use settings::set_bunker_remote_pubkey;pub use settings::commit_bunker_account_setup;
Modules§
- bots
- Last-known bot manifests (kind 10304) — the
/command picker’s persistent layer. One row per bot pubkey, replaced only by a NEWER manifest edition, so the picker serves instantly from boot while a background refetch converges. Manifests are PUBLIC replaceable events: rows are plaintext by design. - chats
- Chat database operations — CRUD for the chats table.
- community
- Persistence for Community protocol local state (GROUP_PROTOCOL.md).
- events
- Event storage — save_event for the flat event architecture.
- id_
cache - ID cache — maps chat identifiers and npubs to SQLite row IDs.
- nip17_
keys - NIP-17 ephemeral wrap-key vault.
- profiles
- Profile database operations — read/write SlimProfile to SQLite.
- schema
- Database schema and migrations.
- settings
- Settings key-value store operations.
- wrappers
- Wrapper tracking — NIP-59 gift wrap dedup + NIP-77 negentropy.
Structs§
- Connection
Guard - RAII guard for READ connections — auto-returns to pool on drop.
- Write
Connection Guard - RAII guard for the WRITE connection — auto-returns on drop.
Enums§
Functions§
- account_
dir - Single source of truth for per-account directories. Every per-account
subsystem (DB, Tor state) resolves its path through this;
compose further subpaths with
.join(...)— never insert layers between<app_data>and<npub>. - clear_
active_ account_ file - Remove the active-account marker. Used after deleting the active account.
- clear_
current_ account_ in_ memory - Clear the in-memory active account WITHOUT touching the on-disk marker.
Used by
reset_session()so the next-boot marker stays intact while in-process state is torn down for an inline account swap. - clear_
id_ caches - close_
database - Close all database connections (for logout / account switch).
Bumps
POOL_GENERATIONfirst so in-flight guards fail their Drop check and discard the connection instead of returning it to the (now-cleared) pool. - get_
accounts - Get all available accounts (npub directories in app data).
- get_
app_ data_ dir - get_
current_ account - get_
database_ path - Get database path for a given npub.
- get_
db_ connection_ guard_ static - Get a READ connection (headless-safe — no AppHandle).
- get_
download_ dir - Platform-appropriate download directory for file attachments.
- get_
or_ create_ chat_ id - Get or create a chat_id integer for a chat identifier string.
- get_
or_ create_ user_ id - Get or create a user_id integer for an npub.
- get_
profile_ directory - Get the profile directory path for a given npub.
- get_
write_ connection_ guard_ static - Get the WRITE connection (headless-safe — no AppHandle).
- init_
database - Initialize the database for a given account (creates tables if needed).
- list_
account_ npubs - Scan the app data directory for valid npub directories. Strict bech32 regex rejects typos and stray subdirectories. Does NOT validate that each account has a usable database — callers do that separately.
- read_
active_ account_ file - Read the active-account marker file. Returns the stored npub if it exists, is well-formed, AND the corresponding account directory still exists. Any failure path returns Ok(None) so boot falls back to single-account or picker.
- set_
app_ data_ dir - set_
current_ account - Set the currently-active npub for THIS process AND persist it to the
<app_data>/active_accountmarker so the next boot picks the same account. - set_
download_ dir - Install the host-resolved download directory. Must be called at
startup before any
get_download_dir()consumer runs; callers that run earlier hit the fallback. - write_
active_ account_ file - Atomic write of the active-account marker (temp + rename).