Module sql

Module sql 

Source
Expand description

SQL storage backend for L3 archive.

Content-type aware storage with proper columns for queryability:

  • JSON content → Stored in payload TEXT column (queryable via JSON_EXTRACT)
  • Binary content → Stored in payload_blob MEDIUMBLOB column

Schema mirrors Redis structure:

CREATE TABLE sync_items (
  id VARCHAR(255) PRIMARY KEY,
  version BIGINT NOT NULL,
  timestamp BIGINT NOT NULL,
  payload_hash VARCHAR(64),
  payload LONGTEXT,        -- JSON as text (sqlx Any driver limitation)
  payload_blob MEDIUMBLOB, -- For binary content
  audit TEXT               -- Operational metadata: {batch, trace, home}
)

§sqlx Any Driver Quirks

We use TEXT instead of native JSON type because sqlx’s Any driver:

  1. Doesn’t support MySQL’s JSON type mapping
  2. Treats LONGTEXT/TEXT as BLOB (requires reading as Vec<u8> then converting)

JSON functions still work on TEXT columns:

-- Find users named Alice
SELECT * FROM sync_items WHERE JSON_EXTRACT(payload, '$.name') = 'Alice';
 
-- Find all items from a batch
SELECT * FROM sync_items WHERE JSON_EXTRACT(audit, '$.batch') = 'abc-123';

Structs§

SqlStore