pub async fn set_meta_value(
pool: &Pool<MySql>,
key: &str,
value: &str,
) -> Result<()>
Expand description
Sets a metadata value for a specific key.
This function stores a key-value pair in the metadata table. If the key already exists, its value is updated. The operation is performed atomically within a transaction and is protected by a mutex to prevent concurrent modifications.
§Arguments
pool
- Database connection pool for executing the querykey
- The unique key to associate with the valuevalue
- The value to store
§Returns
Ok(())
- Successfully stored the key-value pairErr(anyhow::Error)
- Failed to store the key-value pair
§Concurrency
This function acquires the global metadata mutex to ensure thread safety when multiple threads attempt to modify the same key.
§Transaction Handling
This function uses a database transaction that:
- Deletes any existing entries with the same key
- Inserts the new key-value pair
If any part of this operation fails, the entire transaction is rolled back, preserving data consistency.