<?xml version="1.0"?><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr"><head><title>EER - SQLite for ERIS block storage</title><style type="text/css">body {max-width: 900px; margin-top: 3em; margin-bottom: 2em; margin-left: auto; margin-right: auto; text-align: left; line-height: 1.6; font-family: sans-serif; font-size: 12pt;}
#logo {margin: auto; width: 70px; display: block;}
figure {width: 80%; display: block; margin: auto; padding: 2.0rem;}
h1 {text-align: center;}
h2 {margin-top: 3em;}
table {border-collapse: collapse; width: 100%; margin: 1.5rem 0;}
td, th {border: 1px solid black; text-align: left; padding: 0.5rem;}
th {background: goldenrod; font-weight: bold;}
pre { max-width: 100%; overflow: auto; background:#f0f0f0; padding: 10px;}
img { margin: auto; max-width: 70%; }
footer { text-align: right; font-weight: 200; padding-top: 5em; }
footer span { padding: 0 0.5em 0 0.5em; }
</style></head><body><svg id="logo" xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32"><defs><clipPath id="inside"><circle cx="16" cy="16" r="12" /></clipPath></defs><circle cx="16" cy="16" r="14" fill="goldenrod" stroke="black" stroke-width="2" /><path id="symbol" d="M 6,6 A 8,8 0 0,1 6,26 M 16,1 V 31 M 26,6 A 8,8 0 0,0 26,26" fill="none" stroke="black" stroke-width="2" clip-path="url(#inside)" /></svg><nav><a href="index.html">back to index</a></nav><article><h1>SQLite for ERIS block storage</h1><p><a href="https://sqlite.org">SQLite</a> is a popular embedded database. This document specifies a portable schema for storing blocks of ERIS encoded content into an SQLite database. This allows SQLite datbases to be used as portable, cross-platform and cross-implementation formats for storing and exchanging ERIS encoded content (see also <a href="https://www.sqlite.org/appfileformat.html">SQLite As An Application File Format</a>).</p><p>An SQLite database is well-suited for transferring ERIS encoded content over USB sticks or other portable media. Unlike the <a href="https://eris.codeberg.page/eer/cbor.xml">CBOR serialization</a> an SQLite database allows efficient random-access without additional indexing or decoding.</p><h2>Schema</h2><p>Blocks of ERIS encoded content should be stored in a table <code>eris_block</code> that has 3 columns:</p><ul><li><code>block_id</code>: An integer identifier of the block. This is a database internal identifier that can be used to reference blocks from other tables in the database (see section on extensibility below). There is practically no performance cost for having this columns as it is an alias of the SQLite <code>rowid</code> column (see <a href="https://www.sqlite.org/lang_createtable.html#rowid">the SQLite documentation on ROWID</a>).</li><li><code>ref</code>: Stores the binary block reference (the Blake2b-256 hash of the block) with type <code>BLOB</code>. The column is set as <code>PRIMARY KEY</code> ensuring uniqueness of blocks as well as allowing efficient access by reference.</li><li><code>block</code>: Stores the block contents with type <code>BLOB</code></li></ul><p>An SQL statement that creates the table and an index for accessing blocks by their reference:</p><pre><code class="language-sql">CREATE TABLE IF NOT EXISTS eris_block (
              block_id INTEGER PRIMARY KEY,
              ref BLOB UNIQUE,
              block BLOB
);</code></pre><h2>Implementation Notes</h2><h3>Extensibility</h3><p>Applications and implementations may define other tables in the SQLite database. For example tables may be used for application specific configuration or block management.</p><p>When referencing blocks in the <code>eris_block</code> table, the <code>block_id</code> columns should be used as foreign key. This is much more efficient than using the <code>ref</code> column.</p><p>Note that it is necessary to define the <code>block_id</code> column instead of just using the <code>rowid</code> column as SQLite does not allow the <code>rowid</code> to be a parent key (see <a href="https://www.sqlite.org/foreignkeys.html">the SQLite documentation on foreign key support</a>).</p><h3>Transactions</h3><p>Performance can be increased by grouping block insertions into transactions (see <a href="https://www.sqlite.org/lang_transaction.html">the SQLite documentation on Transactions</a>).</p><h2>Implementations</h2><p>The <a href="https://codeberg.org/eris/oebstly">Oebstly</a> block storage tool implements the SQLite schema as described above.</p></article><footer><span><a href="https://codeberg.org/eris/eer/" title="Git repository from which this site is generated">Git</a></span><span><a href="https://creativecommons.org/licenses/by-sa/4.0/" title="Content licensed as CC-BY-SA-4.0">CC-BY-SA-4.0</a></span></footer></body></html>