litestream

    Backend-independent SQLite synchronization and LTX replication

    Download zip
    Author
    Version
    0.1.0
    License
    MIT
    Last updated
    3 hours ago
    Downloads
    7

    No dependencies

    #mizchi/litestream

    現在は 0.1.0。一般的なアプリのオフライン更新・復旧・競合解決を、各バックエンドの必須プロファイルで検証した。対応計画・完了条件を参照。

    DB エンジンに依存しない MoonBit 製の SQLite 同期・LTX 実装。JS / Wasm GC で動作し、LTX v3 の生成・適用、LZ4 / CRC64、SQLite Session codec、revision・適用可否と競合解決を扱う。SQLike・SQLite・Turso のドライバーを本モジュールの依存に含めない。

    moon.pkg に "mizchi/litestream" を import し、@litestream から利用する。SQLite イメージを受け取る LTX API は、そのイメージを作成・読取する DB ドライバーから独立している。SQLike なしでの利用を 外部 consumer test で検査する。

    ホスト側の 共通契約 に SQLike / SQLite WASM / Turso WASM のアダプターが従う。三つとも SQL 同期と原子的な outbox 保存を使える。Session capture と SQLite 物理イメージは optional な機能として分け、Turso の現行アダプターは SQL 同期を使う。

    SQLike と LTX を組み合わせる AOT export はアプリ側の examples/aot、mizchi/litestream-example/runtime にある。これにより両ライブラリの依存を独立させている。

    ルートの just test-litestream で JS / Wasm GC を検証する。just aot-check /absolute/path/to/litestream は上流 Go decoder・実 Litestream・SQLite とブラウザで検証する。全体構成、AOT の利用手順を参照。

    moon.modに依存を追加する。

    import {
    "mizchi/litestream@0.1.0",
    }

    LtxResult

    type LtxResult

    Opaque portable result; JavaScript only marshals metadata at the ABI boundary.

    apply_ltx

    fn apply_ltx(base : Bytes, txid : String, data : Bytes, version : Int) -> LtxResult

    apply_ltx_base64

    fn apply_ltx_base64(base : String, txid : String, data : String, version : Int) -> LtxResult

    assess_apply

    fn assess_apply(head : Int, base : Int, kind : Int, same_database : Bool, same_schema : Bool, matching_assertions : Bool, matching_effects : Bool) -> String

    Platform-independent, fail-closed order for application guard checks.

    decode_changeset

    fn decode_changeset(data : Bytes) -> String

    decode_frame

    fn decode_frame(data : Bytes) -> String

    encode_frame

    fn encode_frame(kind : Int, base : Int, op_id : String, payload : Bytes) -> Bytes

    Stable JS ABI: no dependency on the compiler's Result representation.

    encode_ltx

    fn encode_ltx(base : Bytes, data : Bytes, min : String, max : String, timestamp : String) -> LtxResult

    encode_ltx_base64

    fn encode_ltx_base64(base : String, data : String, min : String, max : String, timestamp : String) -> LtxResult

    ltx_data

    fn ltx_data(result : LtxResult) -> Bytes

    ltx_data_base64

    fn ltx_data_base64(result : LtxResult) -> String

    String ABI for hosts where MoonBit GC byte arrays are opaque references.

    ltx_info

    fn ltx_info(result : LtxResult) -> String

    note_policy

    fn note_policy(input : String) -> String

    Example consumer policy. The host supplies a read-only match count and score. Edit this function or register another policy; decisions are never sent as code.

    plan_changes

    fn plan_changes(changes_json : String, schema_json : String) -> String

    plan_ltx

    fn plan_ltx(catalog : String, current : String, target : String) -> String

    revision_decision

    fn revision_decision(head : Int, base : Int, kind : Int, duplicate : Bool) -> String

    Idempotency must be checked before rejecting an old revision.

    sql_allowed

    fn sql_allowed(sql : String) -> Bool

    cannot be reached through quoted identifiers or comments. SQLite parses SQL.