Table of Contents
KeyValue With Key
Overview
Usually, developers of a KeyValue store tends to use keys with some complex structure.
In Valentina DB, we allow defining such structure explicitly. There are few reasons to use this approach:
- engine is able to build comparator for such keys.
- engine can do more operations, such as: GET LIKE, DELETE LIKE.
Key Structure
Key Structure specification is just a list of allowed TYPEs.
Allowed types are:
- BOOLEAN, BYTE, USHORT, SHORT, ULONG, LONG, ULLONG, LLONG
- VARCHAR
- VARBINARY
Example:
// 3-part keyStructure specification for keys like // "1.1.John", "1.2.Smith" ... String keyStructure( "ULONG, ULONG, VARCHAR" );
You can specify Key Structure string in
You cannot change KeyStructure later. The only way it to copy keyValue pairs into new KeyValue.
DELETE/GET LIKE
Imagine that you have keys of structure “ULONG, ULONG, STRING”:
1.1.birth_date 1.1.first_name 1.1.last_name 1.2.birth_date 1.2.first_name 1.2.last_name 2.6.width 2.7.width
You can see that keys will be sorted into groups. Using the first parts of a key we are able to select group of records.
Example:
KEYVALUE kv1 GET LIKE '1.1' Results in records: 1.1.birth_date 1.1.first_name 1.1.last_name
Example:
KEYVALUE kv1 GET LIKE '1' Results in records: 1.1.birth_date 1.1.first_name 1.1.last_name 1.2.birth_date 1.2.first_name 1.2.last_name
Note that:
- Although we are using keyword LIKE, in fact, we are doing “START WITH” search.
- We mention only one or few key parts.
- You cannot do GET LIKE '' to select all pairs because this can be a huge number of records in general case. {Good/Bad ?}
- Currently, the LIKE commands work only in SQL. Because in v7.0 we have no way to return a group of records via API.
Key Delimiter
Since the key is a complex value, we use Value_Compound class to operate with such key. But also we need a string representation for such key. It is just a string contained sub-keys separated by some symbol - “Key Delimiter”. Default delimiter symbol is '.' (DOT).
You can change it runtime using:
- API: VDatabase.KeyDelimiter property.
- SQL: SET PROPERTY delimiter OF KEYVALUE kv_name TO '|'