NHyDBrun4
R
u
v
Version of 1
lane
NLOverview

dNHyDB

dNHyDB (directNHyDB) applies the same addressing idea in a deliberately reduced form: one realm, direct 64-bit coordinates, one file. It is meant for applications that want to store and read records simply and quickly.

Records, extensions, free cells

Every value lives in a cell (u, v, side): u is the record, v the field or position, the side NL or NR. There are three kinds of cells:

  • BASE fields – the fixed, typed structure of every record, stored densely.
  • Extensions – named, typed columns beyond the BASE.
  • Free cells – any positions without prior declaration.

You read directly by address, with iterators that skip gaps, or through a VALUE index for equal values and ranges.

Writing in batches

Changes collect in a write buffer and become durable with the commit. For larger amounts there are batches and NumPy columns. You decide when to commit, or leave it to a commit policy with thresholds. Transactions group changes together: they apply in full or are discarded in full.

One writer, many readers

There is always exactly one writing process. Readers – also in other processes – see the last commit as a consistent state and pick up newer states with refresh().

Crash-safe

The file is only appended to; two header blocks protected by checksums record the valid state. After a crash the last commit applies – never half a batch. For maintenance there are statistics, a health report, verification, compaction and repair.

Example: transaction and reader

An aborted transaction changes nothing; a reader sees a new commit only after refresh():

import dnhydb

db = dnhydb.create("warehouse.dnhydb")
db.define_base([("item", "utf8"), ("stock", "u64")])
db.put_record(1, ["Screw", 500])
db.commit()

reader = dnhydb.open_reader("warehouse.dnhydb")   # sees the last commit

try:
    with db.transaction():
        db.put_record(1, ["Screw", 450])
        raise ValueError("abort")              # everything in the transaction is discarded
except ValueError:
    pass
print(db.get_record(1))

db.put_record(2, ["Nut", 800])
db.commit()
print(reader.get_record(2), reader.refresh(), reader.get_record(2))
reader.close()
db.close()

Output:

{'item': 'Screw', 'stock': 500}
None True {'item': 'Nut', 'stock': 800}
# dNHyDB dNHyDB (directNHyDB) applies the same addressing idea in a deliberately reduced form: one realm, direct 64-bit coordinates, one file. It is meant for applications that want to store and read records simply and quickly. ## Records, extensions, free cells Every value lives in a cell (u, v, side): u is the record, v the field or position, the side NL or NR. There are three kinds of cells: - **BASE fields** – the fixed, typed structure of every record, stored densely.- **Extensions** – named, typed columns beyond the BASE.- **Free cells** – any positions without prior declaration. You read directly by address, with iterators that skip gaps, or through a VALUE index for equal values and ranges. ## Writing in batches Changes collect in a write buffer and become durable with the commit. For larger amounts there are batches and NumPy columns. You decide when to commit, or leave it to a commit policy with thresholds. Transactions group changes together: they apply in full or are discarded in full. ## One writer, many readers There is always exactly one writing process. Readers – also in other processes – see the last commit as a consistent state and pick up newer states with `refresh()`. ## Crash-safe The file is only appended to; two header blocks protected by checksums record the valid state. After a crash the last commit applies – never half a batch. For maintenance there are statistics, a health report, verification, compaction and repair. ## Example: transaction and reader An aborted transaction changes nothing; a reader sees a new commit only after `refresh()`: ```pythonimport dnhydb db = dnhydb.create("warehouse.dnhydb")db.define_base([("item", "utf8"), ("stock", "u64")])db.put_record(1, ["Screw", 500])db.commit() reader = dnhydb.open_reader("warehouse.dnhydb") # sees the last commit try: with db.transaction(): db.put_record(1, ["Screw", 450]) raise ValueError("abort") # everything in the transaction is discardedexcept ValueError: passprint(db.get_record(1)) db.put_record(2, ["Nut", 800])db.commit()print(reader.get_record(2), reader.refresh(), reader.get_record(2))reader.close()db.close()``` Output: ```text{'item': 'Screw', 'stock': 500}None True {'item': 'Nut', 'stock': 800}```