Module schema

Module schema 

Source
Expand description

Schema-based table partitioning for horizontal scalability.

Routes object IDs to separate SQL tables based on prefix matching. This enables partitioning large datasets across dedicated tables while maintaining a unified API surface.

§Example

use sync_engine::schema::SchemaRegistry;

let registry = SchemaRegistry::new();

// Register prefixes to route to separate tables
registry.register("view:users:", "users_items");
registry.register("crdt:users:", "users_items");
registry.register("view:orders:", "orders_items");

// Keys are routed by longest prefix match
assert_eq!(registry.table_for_key("view:users:alice"), "users_items");
assert_eq!(registry.table_for_key("crdt:users:bob"), "users_items");
assert_eq!(registry.table_for_key("view:orders:123"), "orders_items");

// Unknown prefixes fall back to default table
assert_eq!(registry.table_for_key("unknown:key"), "sync_items");

§Design

  • Longest prefix match: More specific prefixes take precedence
  • Default fallback: Unmatched keys go to sync_items
  • SQLite bypass: Returns sync_items for all keys (no benefit from partitioning)
  • Thread-safe: Uses parking_lot::RwLock for concurrent access

Structs§

SchemaRegistry
Registry mapping key prefixes to table names.

Constants§

DEFAULT_TABLE
Default table name for unmatched keys.