dbzero.deserialize(data)
The dbzero.deserialize() method reconstructs a dbzero query iterable or enum value from its serialized bytes representation. It's the direct counterpart to dbzero.serialize().
When you deserialize a query, it is "rehydrated" into a live, executable query object. A key point is that dbzero.deserialize() runs the query against the current state of the database. If you need to run a query against a historical state, use the snapshot.deserialize() method instead.
Parameters
| Name | Type | Description |
|---|---|---|
data | bytes | The bytes object previously created by dbzero.serialize(). |
Returns
Returns a fully functional dbzero object (e.g., a query iterable or an enum value) that was encoded in the data bytes.
Examples
This example shows a basic round trip: serializing a query to bytes and then deserializing it back into a working query object.
# Create and tag some objects
for i in range(5):
db0.tags(MemoTestClass(i)).add("active_users")
# 1. Serialize a query into bytes
query_bytes = db0.serialize(db0.find("active_users"))
# 2. Store the bytes, and later, deserialize them
reconstituted_query = db0.deserialize(query_bytes)
# The resulting object is a live query you can iterate over
active_count = len(list(reconstituted_query))
print(f"Found {active_count} active users.")
# Expected output: Found 5 active users.