Skip to main content

Crate laravel_litebucket

Crate laravel_litebucket 

Source
Expand description

First-class laravel-rust integration for LiteBucket — durable SQLite on S3, Cloudflare R2, and Laravel Cloud Object Storage with zero sidecars and zero proxies.

§Quick Start (1 Line)

ⓘ
use laravel_litebucket::prelude::*;

laravel::Application::configure()
    .with_litebucket()
    .with_routing(...)
    .run();

Or customize fluently in a closure:

ⓘ
use laravel_litebucket::prelude::*;

laravel::Application::configure()
    .with_litebucket_using(|b| {
        b.sync_mode(SyncMode::Batched)
            .disk_cache_mb(64)
            .write_lease(true)
            .compact_every(32);
    })
    .with_routing(...)
    .run();

§Multi-Tenant Pairing (laravel-tenanted + LiteBucket in 1 Line)

ⓘ
use laravel_litebucket::prelude::*;
use laravel_tenanted::WithTenancy;

laravel::Application::configure()
    .with_litebucket()
    .with_tenancy_using(|t| {
        t.litebucket()
            .subdomain("example.com");
    })
    .with_routing(...)
    .run();

t.litebucket() automatically wires tenanted_database_url, s3_tenant_exists, s3_discover_tenants, and s3_shred_tenant for "tenants/{tenant}/main". Use t.litebucket_from_env() to keep local SQLite in dev/tests and activate LiteBucket whenever LITEBUCKET_VFS=1 is set.

Modules§

prelude
Common imports for 1-line LiteBucket setup (use laravel_litebucket::prelude::*;).

Structs§

CdcCommitEvent
CloneReport
CompactGcReport
EncryptionKey
256-bit client-side encryption key for AES-256-GCM page encryption. Caches the pre-expanded Aes256Gcm key schedule & GHASH table once per key so per-page encrypt/decrypt avoids redundant cipher initialization! Optionally carries a previous_cipher (LITEBUCKET_PREVIOUS_ENCRYPTION_KEY) for zero-downtime key rotation: new writes always encrypt with cipher, while reads transparently decrypt old chunks/frames encrypted with previous_cipher until litebucket rekey finishes. Supports RFC 5869 HKDF-SHA256 per-tenant key derivation (derive_for_tenant) for cryptographic tenant isolation in database-per-tenant architectures.
InspectReport
LiteBucketBuilder
Fluent configuration builder passed to WithLiteBucket::with_litebucket_using.
LiteBucketServiceProvider
Drop-in laravel-rust ServiceProvider:
LtxFrameInfo
ShredReport
SqliteClone
sqlite:clone — clone an S3/R2 prefix (zero-download S3 CopyObject or redacted SQL clone).
SqliteCompact
Compact the LiteBucket LTX history into a snapshot via monotonic CAS on manifest.json and garbage-collect superseded LTX/snapshot files outside --retain.
SqliteDoctor
Live S3/R2 doctor check: verifies bucket access, If-None-Match: * 412 fencing, If-Match ETag CAS, HTTP Range 206 reads, DELETE, and measures RTT.
SqliteHistory
sqlite:history — list restorable PITR transactions and ISO-8601 timestamps in S3/R2.
SqliteInspect
sqlite:inspect — inspect bucket health, size, chunks, PITR window, encryption, and active lease.
SqlitePitr
Run a read-only point-in-time recovery (PITR) query pinned at a historical --txid or --at timestamp.
SqliteRekey
sqlite:rekey — zero-downtime AES-256-GCM key rotation (LITEBUCKET_PREVIOUS_ENCRYPTION_KEY -> LITEBUCKET_ENCRYPTION_KEY).
SqliteRestore
sqlite:restore — non-destructive in-place PITR rollback (appends historical state at head + 1).
SqliteShred
sqlite:shred — permanently delete every S3/R2 object under --prefix (GDPR offboarding).
SqliteStatus
Print live S3/R2 lease status and LiteBucket LTX chain status.
SqliteVerify
Cold-boot verify a LiteBucket database in S3/R2: checks PRAGMA integrity_check and full CRC64 LTX chain.
VfsStats
WriteForwardingMiddleware
First-class laravel::http::Middleware for zero-config multi-replica horizontal scaling!

Enums§

SyncMode
Durability / commit mode for the s3ltx VFS:

Traits§

LiteBucketTenancy
Extension trait adding 1-line LiteBucket storage wiring onto laravel_tenanted::TenancyBuilder.
WithLiteBucket
Extension trait adding 1-line .with_litebucket() and .with_litebucket_using(|b| ...) directly onto laravel::Application::configure().

Functions§

all_open_dbs_prometheus_metrics
Render Prometheus exposition metrics (text/plain; version=0.0.4) for all open LiteBucket DBs.
all_open_dbs_stats
Snapshot VfsStats for every currently open litebucket database in this process.
current_write_owner_addr
Fast ~50 ns lookup for write-forwarding middleware: returns Some(peer_http_url) if another live replica currently holds write_lock.json and advertises an owner_addr, or None if this process is the active writer (or no peer owner is known).
database_url
Build a sqlx-sqlite / laravel-rust-compatible LiteBucket URL for a single database (e.g. "central/main" or "app/main"). Respects LITEBUCKET_SYNC_MODE (default batched).
database_url_strict
Build a sqlx-sqlite / laravel-rust-compatible LiteBucket URL using synchronous SyncMode::Strict (RPO = 0 on every commit — ideal for central auth/organization registries and billing ledgers).
flush_all_open_dbs
Synchronously flush all staged AND in-flight write-back buffers AND release distributed write leases across every open litebucket database in this process. Called automatically at process exit (atexit) and recommended in SIGTERM handlers so rolling deploys and hibernations hand off cleanly.
flush_db
Force an immediate S3/R2 durability barrier (PRAGMA litebucket_flush) on the active laravel-rust database connection — gives RPO = 0 on critical transactions (e.g., payments/checkouts) while keeping sub-millisecond SyncMode::Batched everywhere else.
flush_prefix
Synchronously flush staged AND in-flight write-back buffers for a single open litebucket database matching prefix without releasing its distributed write lease.
flush_staged_dbs
Synchronously flush all staged AND in-flight write-back buffers across every open litebucket database in this process without releasing distributed write leases.
forward_to_write_owner
Forward an incoming Axum request over private LAN to the replica currently holding write_lock.json, tagging X-LiteBucket-Forwarded to prevent forwarding loops.
metrics_prometheus
Render Prometheus metrics (text/plain; version=0.0.4) for every open LiteBucket database in this laravel-rust process — wire directly into a GET /metrics route in 1 line.
s3_discover_tenants
Plug-and-play laravel-tenanted discover_tenants hook backed by S3/R2!
s3_shred_tenant
Plug-and-play laravel-tenanted on_delete hook backed by S3/R2!
s3_tenant_exists
Plug-and-play laravel-tenanted check_exists hook backed by S3/R2!
sanitize_tenant_id
Strict InfoSec tenant identifier validation:
tenanted_database_url
Build a drop-in LiteBucket SQLite URL template for laravel-tenanted (exact mirror of Rails’ LiteBucket.tenanted_database_uri("tenants/%{tenant}/main")).
tenanted_database_url_with_opts
Variant of tenanted_database_url allowing explicit toggle of per-tenant HKDF encryption.
with_retry
Multi-writer optimistic concurrency helper for SyncMode::Strict: runs an async write closure and automatically catches up (PRAGMA litebucket_catch_up) and retries with brief backoff if another container won the S3 If-None-Match: * race (SQLITE_BUSY / database is locked).
write_forwarding_middleware
Native in-process Axum middleware for horizontal multi-replica scaling!
write_forwarding_middleware_with_resolver
Variant of write_forwarding_middleware accepting a custom owner_resolver (useful for multi-DB prefixes or deterministic testing).
write_owner_addr
Fast (~50 ns) lookup returning the private LAN URL of the peer replica currently holding write_lock.json, or None if this replica owns the write lease locally.
write_owner_addr_for
Scoped variant of write_owner_addr filtering to a specific database prefix.