Data types
We have data in database, the stored data must be typed for our convenience.
Supported types
| Type | Code | Type in Python |
|---|---|---|
| String | 0 | str |
| Number | 1 | float |
| Tree | 2 | dict |
| Empty | 3 | None |
| Boolean | 4 | bool |
| Bytes | 5 | bytes |
- The first column is the type class used by modb internally.
-
The second column is the type code used by modb internally to identify the type of the data read in database binary.
What is type code
Your inserted data must be represented as bytes then stored on you file binary. After the data is written as bytes. There should be a type code to help
modbto indentify the type of the data comes afterwards. -
The third column is the type you will get when you do
getonDataobject. The conversion will be done automatically fromTypetoType in Python. For example, if you insert a str-typed data value, your insertedstrobject will be converted tomodb.format.String, and vice versa.Note
Actually you don't need to care about this type conversion,
modbwill do the conversion automatically for you.
Important
- Unlike value data, the type of inserted key data is limited, only
String,NumberandBytesare supported. - Only one type can be inserted to one
node, for example, if you insert str-type key once, then you can not insert other typed data from now on. The value data does not have this limitation. - For simplicity, this limitation will not be released in near future.
Note about Tree
For Tree in modb, we use dict for inserting, modb.low.VirtualBNode for manipulating.
Layout in binary
Note
A unsigned 8-bit integer will be followed by concrete bytes data, like so
String
Your str-typed object will be encoded using utf-8 encoding.
Number
Using IEEE 754 binary32 conversion.