HMove moves a field from a source hash to a destination hash. It takes the source key 'source', the destination key 'destination', and the field 'f' to be moved. It returns a boolean indicating the success of the move and any possible error. Parameters: source: The source hash key. destination:
(source, destination string, field interface{})
| 953 | // bool: True if the move was successful, false otherwise. |
| 954 | // error: An error if occurred during the operation, or nil on success. |
| 955 | func (hs *HashStructure) HMove(source, destination string, field interface{}) (bool, error) { |
| 956 | // Convert the parameters to bytes |
| 957 | f, err, _ := interfaceToBytes(field) |
| 958 | if err != nil { |
| 959 | return false, err |
| 960 | } |
| 961 | |
| 962 | // Check the parameters |
| 963 | if len(source) == 0 || len(destination) == 0 || len(f) == 0 { |
| 964 | return false, _const.ErrKeyIsEmpty |
| 965 | } |
| 966 | |
| 967 | // Find the hash metadata by the given source |
| 968 | sourceMeta, err := hs.findHashMeta(source, Hash) |
| 969 | if err != nil { |
| 970 | return false, err |
| 971 | } |
| 972 | |
| 973 | // If the counter is 0, return false |
| 974 | if sourceMeta.counter == 0 { |
| 975 | return false, nil |
| 976 | } |
| 977 | |
| 978 | // Find the hash metadata by the given destination |
| 979 | destinationMeta, err := hs.findHashMeta(destination, Hash) |
| 980 | if err != nil { |
| 981 | return false, err |
| 982 | } |
| 983 | |
| 984 | // If the counter is 0, return false |
| 985 | if destinationMeta.counter == 0 { |
| 986 | return false, nil |
| 987 | } |
| 988 | |
| 989 | // Create a new HashField for the source |
| 990 | hf := &HashField{ |
| 991 | field: f, |
| 992 | key: []byte(source), |
| 993 | version: sourceMeta.version, |
| 994 | } |
| 995 | |
| 996 | // Encode the HashField |
| 997 | hfBuf := hf.encodeHashField() |
| 998 | |
| 999 | // Create a new HashField for the destination |
| 1000 | destinationHf := &HashField{ |
| 1001 | field: f, |
| 1002 | key: []byte(destination), |
| 1003 | version: destinationMeta.version, |
| 1004 | } |
| 1005 | |
| 1006 | // Encode the HashField |
| 1007 | destinationHfBuf := destinationHf.encodeHashField() |
| 1008 | |
| 1009 | // Get the field from the database |
| 1010 | value, err := hs.db.Get(destinationHfBuf) |
| 1011 | if err != nil && err == _const.ErrKeyNotFound { |
| 1012 | return false, nil |
nothing calls this directly
no test coverage detected