In detail
Tested: the example runs with nhydb 0.28.2 from PyPI.
Records with a fixed shape
create_shape(shape_id, realm_id, name, fields) creates a record shape; each field is {"v": …, "name": …, "type": …}. For writing there are:
put_record(layout_id, object_id, values_dict) – one record, fields by name.
put(realm_id, u, values_list) – one record, fields in order.
put_dense_batch(realm_id, u_start, rows) – consecutive records starting at u_start.
put_object / put_objects_batch – records of any layout.
You read with get(realm_id, u), get_record(layout_id, object_id) or get_value(realm_id, u, v) for a single cell. shape_id may be omitted if the realm has a default shape.
Fields of a record shape cannot store None – that raises ValueError. An empty value can only be created with put_cell.
Enumerations (enums): a field can map labels to integers ("enum": {"open": 0, "done": 1}). You write and read labels; the integers are stored. An unknown label raises ValueError.
Single cells
put_cell(realm_id, u, v, value, type=…, lane=…) writes a cell. type is required if the cell belongs to neither a field nor an extension field – otherwise SchemaError. You give the side as "NL"/"NR" or 0/1; the default is NL.
Three states are kept apart: missing (never written), empty (written with None, the cell exists) and deleted. get_cell(...)["present"] shows whether a cell exists.
Coordinates must be integers; 2.7 raises TypeError. u may be of any size, v goes up to 10¹⁰⁰ per realm.
For many cells there are put_points(realm_id, [(u, v, value, type), …]) and db.batch(): a batch() block collects write and delete calls and writes them as one unit at the end – if the block ends with an exception, nothing is written. Inside the block the collected changes cannot be read yet.
get(realm_id, u) returns records. If a u has only single cells, get returns None; you read such cells with get_value, get_cell or iter_materialized_cells.
Extension fields
define_extension(realm_id, v, type, name=…) creates an extension field, define_extensions several. You write with put_extensions (by name), put_extension_list (by v) or put_extension_range (from a given v), or directly together with put_record and put_dense_batch. With merge=False, put_extensions replaces all extension fields of a record.
create_realm(..., base_reserve_to=20) keeps v = 1 … 20 free for later fixed fields.
In the example, the free cell at v = 50 appears in get under its position (v50) because it has no name.
Overwriting and deleting
put replaces the record as a whole: if you write the same u with a different record shape, fields that the new shape does not have no longer belong to it. put_cell changes exactly one cell. put leaves cells outside the record shape (extension fields, free cells) in place.
| Call |
Deletes |
Returns |
delete_cell(realm_id, u, v) |
one cell |
True if it existed |
delete_area(realm_id, u_from, u_to, v_from, v_to) |
all cells in the rectangle (bounds included), as one unit |
number of deleted cells |
delete_record(layout_id, object_id) |
all cells of a record: fields, extension fields, single cells |
number of deleted cells |
The cost of delete_area grows with the number of live cells in the area. Deleted data is only removed physically by compact_file().
Data types
There are 15 field types: u8, u16, u32, u64, i8, i16, i32, i64 (value range checked), varuint and varint (any size), f32, f64, bool, utf8 and bytes.
Read more: Python Cookbook, chapter 6 “Records” · chapter 7 “Single cells” · chapter 8 “Extensions” · chapter 11 “Data types” · chapter 12 “Reading many records” · Technical documentation, section 5
# In detail **Tested:** the example runs with nhydb 0.28.2 from PyPI. ## Records with a fixed shape `create_shape(shape_id, realm_id, name, fields)` creates a record shape; each field is `{"v": …, "name": …, "type": …}`. For writing there are: - `put_record(layout_id, object_id, values_dict)` – one record, fields by name.- `put(realm_id, u, values_list)` – one record, fields in order.- `put_dense_batch(realm_id, u_start, rows)` – consecutive records starting at `u_start`.- `put_object` / `put_objects_batch` – records of any [layout](/en/layouts/). You read with `get(realm_id, u)`, `get_record(layout_id, object_id)` or `get_value(realm_id, u, v)` for a single cell. `shape_id` may be omitted if the realm has a default shape. **Fields of a record shape cannot store `None`** – that raises `ValueError`. An empty value can only be created with `put_cell`. **Enumerations (enums):** a field can map labels to integers (`"enum": {"open": 0, "done": 1}`). You write and read labels; the integers are stored. An unknown label raises `ValueError`. ## Single cells `put_cell(realm_id, u, v, value, type=…, lane=…)` writes a cell. `type` is required if the cell belongs to neither a field nor an extension field – otherwise `SchemaError`. You give the side as `"NL"`/`"NR"` or `0`/`1`; the default is NL. Three states are kept apart: **missing** (never written), **empty** (written with `None`, the cell exists) and **deleted**. `get_cell(...)["present"]` shows whether a cell exists. Coordinates must be integers; `2.7` raises `TypeError`. u may be of any size, v goes up to 10¹⁰⁰ per realm. For many cells there are `put_points(realm_id, [(u, v, value, type), …])` and `db.batch()`: a `batch()` block collects write and delete calls and writes them as one unit at the end – if the block ends with an exception, nothing is written. Inside the block the collected changes cannot be read yet. `get(realm_id, u)` returns records. If a u has only single cells, `get` returns `None`; you read such cells with `get_value`, `get_cell` or `iter_materialized_cells`. ## Extension fields `define_extension(realm_id, v, type, name=…)` creates an extension field, `define_extensions` several. You write with `put_extensions` (by name), `put_extension_list` (by v) or `put_extension_range` (from a given v), or directly together with `put_record` and `put_dense_batch`. With `merge=False`, `put_extensions` replaces all extension fields of a record. `create_realm(..., base_reserve_to=20)` keeps v = 1 … 20 free for later fixed fields. In the example, the free cell at v = 50 appears in `get` under its position (`v50`) because it has no name. ## Overwriting and deleting `put` replaces the record as a whole: if you write the same u with a different record shape, fields that the new shape does not have no longer belong to it. `put_cell` changes exactly one cell. `put` leaves cells outside the record shape (extension fields, free cells) in place. | Call | Deletes | Returns ||---|---|---|| `delete_cell(realm_id, u, v)` | one cell | `True` if it existed || `delete_area(realm_id, u_from, u_to, v_from, v_to)` | all cells in the rectangle (bounds included), as one unit | number of deleted cells || `delete_record(layout_id, object_id)` | all cells of a record: fields, extension fields, single cells | number of deleted cells | The cost of `delete_area` grows with the number of live cells in the area. Deleted data is only removed physically by `compact_file()`. ## Data types There are 15 field types: `u8`, `u16`, `u32`, `u64`, `i8`, `i16`, `i32`, `i64` (value range checked), `varuint` and `varint` (any size), `f32`, `f64`, `bool`, `utf8` and `bytes`. **Read more:** Python Cookbook, [chapter 6 “Records”](https://github.com/nhydb-run4/NHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md#6-records-classic-layout) · [chapter 7 “Single cells”](https://github.com/nhydb-run4/NHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md#7-single-cells-lanes-null-and-delete) · [chapter 8 “Extensions”](https://github.com/nhydb-run4/NHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md#8-extensions-additional-fields-per-record) · [chapter 11 “Data types”](https://github.com/nhydb-run4/NHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md#11-data-types) · [chapter 12 “Reading many records”](https://github.com/nhydb-run4/NHyDB/blob/main/docs/cookbook/PYTHON_COOKBOOK.md#12-reading-many-records-ranges-and-iterators) · [Technical documentation, section 5](https://github.com/nhydb-run4/NHyDB/blob/main/docs/en/NHyDB_Technical_Documentation.md#5-data-model-realms-shapes-extensions-layouts)