Module grainite_cl.api.value

Classes

class Value (value: Any, b_value: Optional[bytes] = None)

Represents a typed value in Grainite. The underlying value may be of types int, float, str, bool, list, dict, bytes, None. Nested, arbitrarily complex, objects are supported via lists and dicts.

A typed value is understood by Grainite across supported languages. The lexicographical comparator on the serialized bytes will offer the same result as a comparison for the Type itself.

A typed value may be used anywhere, including for Grain Keys, Values, Map Keys or Map Values. However, it's recommended to use Key objects to represent Keys, as they add some additional constraints on the contents of a key.

You can construct a Value object in the following ways:

>>> Value(<value>)
>>> Value.of(<value1>, <value2>, ...) # Passing multiple arguments constructs a compound value
>>> Value.deserialize(<bytes>)

Use Value.is_null() to check if the underlying value is null. After retrieving a Value object from Grainite, use the appropriate as_long / as_double / as_string / as_bool / as_list / as_dict / as_bytes method to retrieve the underlying object, corresponding to the underyling object's type.

Subclasses

Class variables

var NULLVALUE

This is equivalent to None

Static methods

def deserialize(b_value: bytes) ‑> Value

Returns a Value object from the given bytes

def max_key() ‑> Value

Represents the largest possible (non-compound) Value.

Useful when fetching a range of Values or Keys.

def min_key() ‑> Value

Represents the smallest possible (non-compound) Value.

Useful when fetching a range of Values or Keys.

def of(*args) ‑> Value

Used to construct a compound Value object from multiple arguments provided as underlying values. This function is also used by Key to construct compound keys.

Methods

def as_bytes(self) ‑> bytes

Return the underlying value as bytes

def as_dict(self) ‑> Dict

Return the underlying value as a dict

def as_double(self) ‑> float

Return the underlying value as a float

def as_list(self) ‑> List

Return the underlying value as a list

def as_long(self) ‑> int

Return the underlying value as an int

def as_string(self) ‑> str

Return the underlying value as a str

def get_bytes(self) ‑> bytes

Return the underlying value as bytes

def is_null(self) ‑> bool

Returns True if the underlying value is Value.NULLVALUE or None

def last_key_for_prefix(self) ‑> Value

Produces a Value that by literal order would be immediately after the last possible key with the current Value as a prefix.

Useful when performing a range scan to compute the ending key.

def size(self) ‑> int

Return the length of the underlying value when represented as bytes