Tiny multi-key JSON value database over a 4D sudoku lattice (1..215 cells per axis, 81 by default), with a SQL surface and sudoku digit constraints.
Dependencies
moon add riantr/tesseract@0.1.0///|
import {
"riantr/tesseract/src/tesseract",
}| C# original | this version | |
|---|---|---|
| shape | flat 9-cell ring shown as 3x3 | 3x3x3x3 lattice, 81 cells (default) |
| addressing | grid_position 1..9 | grid_position 1..81, or (x,y,z,w) |
| sudoku | none | digits 1..3, one set per axis-parallel line |
| structure | 9 rows / 1 box | 4 axes x 27 lines = 108 lines, 12 slabs |
| side = 3 (default) | side = 4 | |
|---|---|---|
| cells | 81 | 256 |
| digit domain | 1..3 | 1..4 |
| lines | 108 | 256 |
| slabs (each) | 12 of 27 cells | 16 of 64 cells |
| peers per cell | 8 | 12 |
moon run cmd/main -- --side 4 .status
moon run cmd/main -- --side 4 .solve .verifyposition = 1 + x*side^3 + y*side^2 + z*side + w (row-major, x slowest)digit(x,y,z,w) = (x + y + z + w) mod 3 + 1src/tesseract/
text.mbt ASCII helpers: trim, case folding, integer parse, split/join
coords.mbt the lattice: coordinates, positions, neighbours, shares_line
lattice.mbt lines, slabs, planes, peers
sudoku.mbt digits, the line rule, slab balance, backtracking solver
txn.mbt transactions: the undo journal, savepoints, statement atomicity
types.mbt GridCell, Record, Computed, DBResponse, DBStatus, formatting
logger.mbt bounded log ring (100 entries, matching the C# logger)
clock.mbt the injected clock and its ISO-8601 rendering
db.mbt the store, and the in-place resize between shapes
lexer.mbt the SQL tokenizer
ast.mbt the parsed shape of a statement
parser.mbt recursive descent, precedence climbing
exec.mbt the executor: expressions, aggregates, ordering, transactions
serialize.mbt .tsr JSON, .md table, .sql dump, lattice rendering
cmd/main/ command line front end
cmd/gui/ the proton desktop window
main.mbt the App: entry point, page asset, command registration
state.mbt the store the window drives, and its JSON projections
commands.mbt the seven typed commands the page can call
web/index.html the page itself - inline CSS and JS, no build step
proton.project.json bundle identity, backend package, packaging settings
gui-smoke.mjs end-to-end smoke test driven through Chromium DevTools| operation | what it does |
|---|---|
| app:state | occupancy, cursor, digit count, the current side × side plane, sudoku health, log tail |
| app:lattice | change side; rebuilds the store in place and reports kept/dropped |
| app:write | insert / update / delete / clear / cursor, plus solve and demo |
| app:query | one SQL statement, returning rows and a repaint |
| app:geometry | line / slab / peers around a cell, with the covered positions |
| app:export | .tsr, .md, .sql, or the ASCII lattice |
| app:import | load a .tsr, .md or .sql dump back in |

| before | now | |
|---|---|---|
| WHERE key='a' AND key='b' | 1 row — the last conjunct overwrote the first | 0 rows |
| WHERE key='a' OR key='b' | INVALID_SYNTAX | 2 rows |
| LIMIT 1 | 3 rows | 1 row |
| ORDER BY key DESC | insertion order | sorted |
| WHERE digit=1+1 | INVALID_SYNTAX | evaluates |
CREATE DATABASE tesseract;
INSERT INTO tesseract (key, value) VALUES ('user_001', '{"age": 25}');
SELECT * FROM tesseract WHERE key = 'user_001';
SELECT * FROM tesseract WHERE value LIKE '%age%';
UPDATE tesseract SET value = '{"age": 26}' WHERE key = 'user_001';
DELETE FROM tesseract WHERE key = 'user_001';-- explicit address, as a position or as coordinates
INSERT INTO tesseract (key, value) VALUES ('k', 'v') AT 42;
INSERT INTO tesseract (key, value) VALUES ('k', 'v') AT (1,2,0,2);
-- sudoku digits, enforced against the lines through the cell
INSERT INTO tesseract (key, value, digit) VALUES ('k', 'v', 2);
UPDATE tesseract SET value = 'v', digit = 3 WHERE grid_position = 42;
-- coordinate predicates
SELECT * FROM tesseract WHERE x = 1 AND y = 2;
SELECT * FROM tesseract WHERE digit = 1;
-- geometry
SELECT * FROM tesseract WHERE line(42, 0); -- the 3-cell axis-parallel line
SELECT * FROM tesseract WHERE slab(42, 1); -- the 27-cell slab
SELECT * FROM tesseract WHERE peers(42); -- the 8 cells sharing a lineSELECT * FROM tesseract WHERE peers(42) AND key = 'user_001';OR < AND < NOT < = <> != < <= > >= LIKE IN IS NULL
< + - < * / % < unary - < literals, columns, ( ), functionsSELECT * FROM tesseract WHERE key = 'a' OR key = 'b';
SELECT * FROM tesseract WHERE digit = 1 + 1;
SELECT * FROM tesseract WHERE key IN ('a', 'b', 'c');
SELECT * FROM tesseract WHERE NOT (x = 1 AND y = 2);SELECT digit, count(*) FROM tesseract GROUP BY digit;
SELECT sum(digit) FROM tesseract WHERE digit > 0;
SELECT key FROM tesseract ORDER BY key DESC, digit ASC;
SELECT key FROM tesseract ORDER BY key LIMIT 10 OFFSET 20;
SELECT DISTINCT value FROM tesseract;BEGIN;
INSERT INTO tesseract (key, value) VALUES ('a', '1') AT 1;
SAVEPOINT sp;
INSERT INTO tesseract (key, value) VALUES ('b', '2') AT 2;
ROLLBACK TO sp; -- the 'b' insert goes; the transaction stays open
COMMIT;
ROLLBACK; -- or undo the whole thingmoon check --target all # type-check every backend
moon test # 220 tests
moon fmt --check # canonical formatting
node cli-smoke.mjs # both CLIs, as real processes (builds them first)
node gui-smoke.mjs # the window, over CDP (needs `proton_cli dev` running)
moon run cmd/main -- .help
moon run cmd/main -- .status
moon run cmd/main -- .demo
moon run cmd/main -- .solve .verify
moon run cmd/main -- "INSERT INTO tesseract (key,value) VALUES ('a','1') AT 5;" "SELECT * FROM tesseract;"
moon run cmd/main -- .export tsr > dump.tsr
# 256 cells, digits 1..4
moon run cmd/main -- --side 4 .status
moon run cmd/main -- --side 4 .solve .verify$ moon run cmd/main -- --side 999 .status
--side side 999 is above the maximum 215 (cells are stored in one flat array indexed by a 32-bit Int)moon run cmd/persist --target native -- .open sudoku.db \
"INSERT INTO tesseract (key,value,digit) VALUES ('user_001','{\"age\": 25}',1) AT 1;" \
.save .status .verify
# a second process reads the same file back
moon run cmd/persist --target native -- .open sudoku.db .status| command | effect |
|---|---|
| .open <path> | replace the store with the file's contents |
| .save [path] | write the store out, to <path> or to the last .open |
| .status | occupancy, digits, cursor, and the file in use |
| .verify | line and slab check over the digits in the store |
while read -r line; do moon run cmd/main -- "$line"; donemoonx riantr/moonbit_static_analysis@0.4.1 . > scan.tsv
moon run cmd/sa --target native -- store scan.tsv scan.db
moon run cmd/sa --target native -- runs scan.db
moon run cmd/sa --target native -- show scan.db
moon run cmd/sa --target native -- files scan.db
moon run cmd/sa --target native -- unparsed scan.db| table | holds |
|---|---|
| sa_runs | one row per scan: coverage, counts, target |
| sa_files | each file the analyzer reported on, with outcome, defects, notices, shown |
| sa_findings | the findings that were actually rendered |
| sa_by_kind | the per-.mbt/.mbti/.mbt.md rollup the tool prints |
| sa_unparsed | per reason: how many files, and up to three example paths |
moon update # refresh the registry index
moon install moonbit-community/proton_cli@0.3.4 # match the library version
proton_cli cef setup # CEF runtime + subprocess helper
proton_cli doctor # identity, toolchain and runtime
proton_cli dev # run the window
proton_cli build # native build
proton_cli package --dry-run # check the packaging plan
proton_cli package # produce dist/"resources": [ "cmd/gui/web" ]node gui-smoke.mjs| format | role |
|---|---|
| .tsr | JSON, the native save format; round-trips key, value, position, digit and timestamp losslessly |
| .md | Markdown table, human-readable and diffable |
| .sql | SQL dump this package's own parser re-imports |
Install
Download zipTiny multi-key JSON value database over a 4D sudoku lattice (1..215 cells per axis, 81 by default), with a SQL surface and sudoku digit constraints.
Dependencies