gitoriaLog in with ident

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8cda54128cda5412notes mission 002 (1/4): code order — files moved: lib/notes.hl, lib/users.hl, lib/jsoncheck.hl, components/styles.hl (imports only); gates 50/0 + 18/0, live-data run identicalmre8cda5412/plugins/mpackdb/README.md

2.7 KB

  1. # `hl:mpackdb` — the MessagePack file database
  2. A document store in plain files. Server realm. The class surface and its
  3. generated API docs live in `MPackDB.hl` and `cursor.hl`
  4. (`projects/homepage/docs/mpackdb.md`).
  5. ```hybriel
  6. import { MPackDB } from 'hl:mpackdb'
  7. db = new MPackDB(file = 'users.db', primaryKey = '*id', indexes = ['!email', 'age'])
  8. id = db.put({ name = "Alice"; email = "[email protected]"; age = 30; }) \\ 1
  9. ```
  10. ## Primary keys
  11. | declaration | key | generated by `put()` |
  12. |---|---|---|
  13. | `*name` | a number | the table's counter: **1, 2, 3, …** |
  14. | `@name` | a string | a random 12-character id |
  15. | `name` | a string | nothing — the record must carry it |
  16. **A fresh `*id` table starts at 1** (ticket #4, the creator's ruling "start at
  17. 1"). The counter is stored as `nextId` in `<base>.meta.json`, and an existing
  18. table keeps counting from its stored value. A table written before this rule
  19. therefore goes on from wherever it was, and its record 0 remains record 0.
  20. A record put with an explicit key takes that key if it is free, 0 included.
  21. ## One open table per process (ticket #110)
  22. Within one process, a table path has **one** open table, shared by every
  23. `open()` — another module instance, another realm, it doesn't matter, they
  24. all get the same handle. The file is never compacted or rewritten while a
  25. handle on it is live; compaction happens only when asked for explicitly
  26. (`compactNow()` / `#handle.compact()`) or when the **last** handle on that
  27. path closes. A second `open()` of an already-open table ignores its own
  28. `primaryKey`/`indexes`/`compact` arguments — the schema was fixed by whoever
  29. opened it first.
  30. This matters because compaction rewrites `<base>.mpack` and shifts every
  31. record after the first tombstone to a new offset. Before this rule, a second
  32. `open()` from anywhere in the process ran its own compact-on-open (ticket
  33. #21) against the same file, and the first handle's already-looked-up offsets
  34. went stale under it — reads through the first handle then missed or
  35. misread records until something compacted again. Related: ticket #21
  36. ("opening a table rewrote its files").
  37. ## Compatibility with the JS mpackdb
  38. The on-disk format is the JS mpackdb 1.0.7 format: `<base>.mpack`,
  39. `<base>.meta.json`, one `<base>.<field>.txt` per index, `<base>.idxstate.json`
  40. and the `<base>.lock` protocol. Either side reads and changes the other's
  41. files. The first id is not part of the format; `nextId` is. Therefore:
  42. - a table the JS mpackdb created carries `nextId` and keeps its sequence here,
  43. even when that sequence started at 0;
  44. - a table Hybriel created carries `nextId` too, and the JS mpackdb continues it;
  45. - the one divergence is a table with **no** `.meta.json` yet: Hybriel's first
  46. id is 1, the JS mpackdb's is 0.
  47. The other documented divergences are listed at the top of `engine.zig`.

Branches

Latest commits

  • 8cda5412notes mission 002 (1/4): code order — files moved: lib/notes.hl, lib/users.hl, lib/jsoncheck.hl, components/styles.hl (imports only); gates 50/0 + 18/0, live-data run identicalmre
  • 47dad68bnotes: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gates 50/0 + 18/0mre
  • a4a2b2aeantcolony#40: tracker missions moved too — references to them in missions/reports/LOG.md updatedmre
  • 3dea0ef2notes: Hybriel master 190aa11d (fc838894 GC correctness, #126 closure scopes, #127); gate 50/0mre
  • e27c7d71notes: Hybriel master 8efba065 (#126 GC by bytes, #48 lambda params copy; audit: nothing to fix; gate 50/0)mre
  • 124613b6antcolony#40: mission references point to the moved missionsmre
  • 1ca2f34dantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • 2bebebdanotes: Hybriel master ff51cf46 (re-vendor round)mre
  • 3eff126dnotes#3: installable app (manifest + own icon/favicon; notes' own sw.js kept)mre
  • 9883c540deploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • eee693b8deploy.sh: never send .git or .gitignore to Byrodinmre
  • c8904061State of 2026-09-27, before the move to gitoriamre