Overview
Vault uses SQLite as its storage backend, with each user having their own isolated database file. The database is automatically created and initialized when you first run any Vault command.Database Location
The SQLite database is stored in a per-user directory at~/.kvstore/store.db. The exact path depends on your operating system:
The
.kvstore directory is automatically created in your user profile directory if it doesn’t exist. This ensures per-user data isolation.Database Path Resolution
The database path is determined by theGetDatabasePath() method in KVSTORE.cs (lines 36-45):
- Resolves the user’s home directory using
Environment.SpecialFolder.UserProfile - Creates the
.kvstoredirectory if it doesn’t exist - Returns the full path to
store.db
Database Schema
The database contains a single table calledstore with the following structure:
Table Structure
| Column | Type | Constraints | Description |
|---|---|---|---|
id | INT | PRIMARY KEY | Unique identifier for each entry |
key | TEXT | UNIQUE | The key name (must be unique) |
value | TEXT | - | The value associated with the key |
The
UNIQUE constraint on the key column ensures that duplicate keys cannot be added to the database. Attempting to add a duplicate key will result in a SQLite constraint violation.Automatic Initialization
The database is automatically initialized when theStore object is created. The initialization process (KVSTORE.cs lines 24-35):
CREATE TABLE IF NOT EXISTS statement ensures:
- The table is created only if it doesn’t already exist
- Existing data is preserved when running Vault commands
- No manual database setup is required
SQLite Package
Vault uses the Microsoft.Data.Sqlite package for database operations. This is the official Microsoft SQLite provider for .NET and provides:- Cross-platform support (Windows, macOS, Linux)
- Full ADO.NET compatibility
- Parameterized queries to prevent SQL injection
- Connection pooling and performance optimization
Connection Management
The database connection is managed through theStore class constructor (KVSTORE.cs lines 12-23):
- Resolves the database path (using default or custom path)
- Creates the parent directory if it doesn’t exist
- Opens a SQLite connection
- Initializes the database schema
Backup and Migration
Creating a Backup
Since Vault uses a single SQLite file, backing up your data is straightforward:Restoring from Backup
To restore from a backup, simply copy the backup file back:Make sure Vault is not running when restoring from a backup to avoid database locking issues.
Migrating to a Different Machine
To migrate your Vault data to another machine:- Locate your database file at
~/.kvstore/store.db - Copy it to the same location on the new machine
- Ensure the
.kvstoredirectory exists on the new machine - Run any Vault command to verify the migration
Per-User Isolation
Each user account on the system has their own isolated database:- Data is stored in each user’s home directory
- No shared data between users
- No special permissions or configuration required
- Suitable for multi-user systems
If you need to share data between users, you can use a custom database path, though this is not officially supported by the CLI interface.
Database File Size
The SQLite database file grows dynamically based on the number of keys and the size of values stored:- Initial empty database: ~8-12 KB
- Grows incrementally as data is added
- SQLite uses page-based storage (typically 4 KB pages)
- No automatic compression or cleanup
Deleting keys does not automatically shrink the database file. To reclaim space, you would need to manually run
VACUUM on the database or delete and recreate the database file.