Skip to main content

Overview

The update command modifies the value associated with an existing key in the vault. If the key doesn’t exist, it prints a message indicating the key was not found.

Syntax

vault update <key> <value>

Parameters

key
string
required
The key whose value you want to update. Must already exist in the vault.
value
string
required
The new value to store. Can contain spaces and special characters (use quotes for values with spaces).

Examples

Basic Usage

vault update api_key "sk-new-token-9876543210"

Expected Output

When key exists:
Updating key: api_key with the value: sk-new-token-9876543210 in the vault
When key doesn’t exist:
Key: missing_key does not exist in db

Complete Workflow Example

# Add a key
vault add version "1.0.0"

# Update it
vault update version "1.1.0"
# Output: Updating key: version with the value: 1.1.0 in the vault

# Verify the update
vault get version
# Output: 1.1.0

# Try to update non-existent key
vault update nonexistent "value"
# Output: Key: nonexistent does not exist in db

Implementation Details

Under the Hood

The update command executes the following SQL query (KVSTORE.cs:75-79):
UPDATE store
SET value = $value
WHERE key = $key
The implementation checks the number of affected rows to determine if the key exists (KVSTORE.cs:72-90):
public int Update(string key, string value)
{
    using var command = connection.CreateCommand();
    command.CommandText = """
        UPDATE store
        SET value = $value
        WHERE key = $key
        """;
    command.Parameters.AddWithValue("$key", key);
    command.Parameters.AddWithValue("$value", value);
    int rowsAffected = command.ExecuteNonQuery();
    if (rowsAffected == 0)
    {
        Console.WriteLine($"Key: {key} does not exist in db");
        return 0;
    }
    Console.WriteLine($"Updating key: {key} with the value: {value} in the vault");
    return 0;
}

Validation

The command validates that exactly 2 arguments are provided (KVSTORE.cs:175-179):
case "update":
    if (args.Length == 2)
    {
        return Command.UPDATE;
    }

Behavior Notes

Non-Existent KeysUnlike some key-value stores, update does NOT create a new entry if the key doesn’t exist. It will simply report that the key doesn’t exist in the database (KVSTORE.cs:84-86).If you want to add a new key, use the add command instead.
No Rows AffectedWhen updating a non-existent key, the command prints:
Key: your_key does not exist in db
The command still exits successfully (return code 0), but no changes are made to the vault.

Error Cases

Invalid ArgumentsProviding the wrong number of arguments will result in:
Please enter a valid command, could not execute

Use Cases

  • Rotate API keys or credentials stored in the vault
  • Update configuration values as your application evolves
  • Modify environment-specific settings
  • Change values without removing and re-adding keys
  • add - Add a new key-value pair
  • get - Retrieve a value to verify the update
  • list - List all keys to see what can be updated
  • remove - Delete a key-value pair

Build docs developers (and LLMs) love