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::advance_u64_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;pub use settings::get_nip55_user_pubkey;pub use settings::set_nip55_user_pubkey;pub use settings::get_nip55_signer_package;pub use settings::set_nip55_signer_package;pub use settings::commit_nip55_account_setup;
Modules§
- attachments
- Attachments table operations.
- 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.
- Downgrade
Block - A newer Vector already opened this account’s database.
- 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 - Clear every id cache on account switch. Row ids are PER-ACCOUNT (each account
has its own DB + id sequence), so a stale entry after a swap points into the
wrong DB: writes FK-fail silently and reads hit the wrong row. The caches live
in
id_cache; this is the public entry the swap path + callers already use. - 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_
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).
- inspect_
downgrade - Whether this account’s DB was written by a newer Vector.
- 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.
- optimize_
database - Run plain
PRAGMA optimizeon the live write connection — the periodic top-up SQLite recommends for long-lived connections (the heavy lifting is theoptimize=0x10002at connection open). Best-effort and cheap: re-analyzes only tables whose stats the planner used and that changed materially since the last run. - 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_
app_ version - 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).