{"by":"swaminarayan","descendants":31,"id":47136553,"kids":[47136907,47138044,47136676,47136753,47136714,47136891,47136722],"score":36,"text":"SQLite has six layers: SQL parser → query planner → VDBE → B-tree → pager → OS. (<a href=\"https:&#x2F;&#x2F;sqlite.org&#x2F;arch.html\" rel=\"nofollow\">https:&#x2F;&#x2F;sqlite.org&#x2F;arch.html</a>)\nFor key-value workloads you only need the bottom three.<p>SNKV cuts the top three layers and talks directly to SQLite&#x27;s B-tree engine.\nNo SQL strings. No query planner. No VM. Just put&#x2F;get&#x2F;delete on the same\nstorage core that powers SQLite.<p>Python:<p><pre><code>    pip install snkv\n\n    from snkv import KVStore\n\n    with KVStore(&quot;mydb.db&quot;) as db:\n        db[&quot;hello&quot;] = &quot;world&quot;\n        print(db[&quot;hello&quot;])   # b&quot;world&quot;\n</code></pre>\nC&#x2F;C++ (single-header, drop-in):<p><pre><code>    #define SNKV_IMPLEMENTATION\n    #include &quot;snkv.h&quot;\n\n    KVStore *db;\n    kvstore_open(&quot;mydb.db&quot;, &amp;db, KVSTORE_JOURNAL_WAL);\n    kvstore_put(db, &quot;key&quot;, 3, &quot;value&quot;, 5);\n</code></pre>\nBenchmarks vs SQLite WITHOUT ROWID (1M records, identical settings):<p><pre><code>  Sequential writes  +57%\n  Random reads       +68%\n  Sequential scan    +90%\n  Random updates     +72%\n  Random deletes    +104%\n  Exists checks      +75%\n  Mixed workload     +84%\n  Bulk insert        +10%\n</code></pre>\nHonest tradeoffs:\n- LMDB beats it on raw reads (memory-mapped)\n- RocksDB beats it on write-heavy workloads (LSM-tree)\n- sqlite3 CLI won&#x27;t open the database (schema layer is bypassed by design)<p>What you get: ACID, WAL concurrency, column families, crash safety —\nwith less overhead for read-heavy KV workloads.","time":1771937991,"title":"Show HN: SNKV – SQLite's B-tree as a key-value store (C/C++ and Python bindings)","type":"story","url":"https://github.com/hash-anu/snkv"}