This is where the fundamental change begins:
- Changed
to_command()method's return type fromOption<(String, Vec<String>)>toOption<(String, Vec<Value>)> - Instead of converting all arguments to strings, we're now preserving their original data types
- Added better type handling for numeric values, allowing integers to remain as
Value::Integerinstead of converting them to strings - This change enables type-preserving command processing throughout the system
This file was modified to accommodate the type preservation:
- Changed the
execute()method signature to acceptVec<Value>instead ofVec<String> - Added a conversion step that maps different Value types to strings for
backward compatibility:
let string_args: Vec<String> = args .iter() .map(|v| match v { Value::SimpleString(s) => s.clone(), Value::BulkString(s) => s.clone(), Value::Integer(i) => i.to_string(), Value::Boolean(b) => b.to_string(), _ => "".to_string(), }) .collect();
- Updated command calls to pass both the string arguments (for backward compatibility) and the original Value objects
- Now passes the original Value objects to the SET command, allowing it to preserve data types
This file implements the SET command and was updated to handle typed values:
- Added a new parameter
orig_args: Vec<Value>to receive the original typed values - Changed how values are extracted and stored to preserve their original type:
let value = if orig_args.len() > 1 { orig_args[1].clone() } else { Value::SimpleString(args[1].clone()) };
- Updated the argument parsing logic to use indexes rather than removing elements
- Improved value display in debug logs to show appropriate string representation based on type
- Now the SET command can store integers, booleans, and strings with their original types preserved
Only had a minor change in the order of imports (rearranging the anyhow
imports).
The overall improvement is significant: your database system now preserves data types throughout the command execution pipeline, instead of converting everything to strings. This makes your system more robust and provides better data integrity when retrieving values later.