Skip to content

chore: sqlite framework#2265

Open
SantiagoPittella wants to merge 1 commit into
nextfrom
santiagopittella-sqlite-framework-phase1
Open

chore: sqlite framework#2265
SantiagoPittella wants to merge 1 commit into
nextfrom
santiagopittella-sqlite-framework-phase1

Conversation

@SantiagoPittella

@SantiagoPittella SantiagoPittella commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

closes #2248 and #2249

Summary

Introduces a light SQLite framework in crates/db (miden-node-db) and migrates the validator onto it, removing Diesel. It handles a connection pool, type-enforced read/write transactions, always-cached queries, a type codec, and cacheable IN-list helpers.

  • The framework keeps a small pool of connections alive and hands them out. Because SQLite is blocking, the actual query work runs on a background thread.
  • We dont handle raw connections. The struct provides either a read or a write transaction and get a small
    handle:
    • read(...) gives you a ReadTx. It begins a read-only transaction that is never committed, so
      nothing it does can persist.
    • write(...) gives you a WriteTx. It begins a write transaction.
  • Added verbs like query_rows, query_opt, query_one, exists, count and execute (write only). Every one of them prepares its statement through SQLite's cache.
  • Added a codec to convert between native data types and sql's.

The usage is like this:

// a read
db.read("chain_tip", |tx| {
    tx.query_opt(
        "SELECT block_header FROM block_headers ORDER BY block_num DESC LIMIT 1",
        &[],
        |row| row.get::<BlockHeader>(0),
    )
}).await?;

// a write (several statements in one atomic transaction)
db.write("apply", move |tx| {
    tx.execute("INSERT INTO ... VALUES (?1, ?2)", &[&a, &b])?;
    tx.execute("UPDATE ... SET ... WHERE id = ?1", &[&id])?;
    Ok::<(), DatabaseError>(())
}).await?;

Changelog

changelog = "none"
reason    = "Internal change only."

@SantiagoPittella SantiagoPittella force-pushed the santiagopittella-sqlite-framework-phase1 branch from 31dc8cc to a954f57 Compare June 19, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLite: Design framework

1 participant