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.
# Add a keyvault add version "1.0.0"# Update itvault update version "1.1.0"# Output: Updating key: version with the value: 1.1.0 in the vault# Verify the updatevault get version# Output: 1.1.0# Try to update non-existent keyvault update nonexistent "value"# Output: Key: nonexistent does not exist in db
The update command executes the following SQL query (KVSTORE.cs:75-79):
UPDATE storeSET value = $valueWHERE 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;}
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.