C db22dc4cd6 Store amounts in a form the database can add up exactly пре 2 месеци
..
src db22dc4cd6 Store amounts in a form the database can add up exactly пре 2 месеци
tests db22dc4cd6 Store amounts in a form the database can add up exactly пре 2 месеци
Cargo.toml db22dc4cd6 Store amounts in a form the database can add up exactly пре 2 месеци
README.md db22dc4cd6 Store amounts in a form the database can add up exactly пре 2 месеци

README.md

kuatia-storage-sql

SQL-backed Store implementation for the kuatia ledger.

Uses sqlx::Any for database-agnostic queries. Enable features to select the backend:

[dependencies]
kuatia-storage-sql = { features = ["sqlite"] }   # or "postgres"

Backends

Feature Backend Status
sqlite (default) SQLite via sqlx Conformance tests pass
postgres PostgreSQL via sqlx Portable DDL/queries; needs a running instance to test

The migrations in src/migrations/ serve both backends. Applied migrations are tracked in a _migrations table, so migrate() is idempotent. Upserts use portable ON CONFLICT … DO UPDATE, and all ids are generated in Rust (no AUTOINCREMENT/SERIAL).

Identifier and payload columns are text, so any row is readable in a plain SQL client for auditing: content-addressed ids as lower-case hex TEXT, structured payloads as their JSON TEXT serialization (never queried into). Amounts are the exception, stored natively so the database can sum and order them: NUMERIC(39,0) on PostgreSQL, a 16-byte order-preserving BLOB on SQLite. A SQLite amount reads back as a decimal string through kuatia_i128_to_text(value) in any process that called install_drivers(); a plain sqlite3 CLI has no such function and sees the blob. See ADR-0024.

Usage

install_drivers() replaces sqlx::any::install_default_drivers() and must run before the pool connects: it registers the SQLite money functions as an auto-extension, so a connection opened earlier would not have them.

use kuatia_storage_sql::{SqlStore, install_drivers};

install_drivers()?;
let pool = sqlx::any::AnyPoolOptions::new()
    .connect("sqlite::memory:").await?;
let store = SqlStore::new(pool);
store.migrate().await?;

Schema

Tables: accounts, account_head, postings, live_postings, transfers, transfer_accounts, events, books, balance_projection. Migrations run via store.migrate(); the full catalog is in doc/storage-schema.md.