SOP Go Examples
This directory contains example applications demonstrating various features of Scalable Objects Persistence (SOP) in Go.
🌍 Interoperability & Polyglot Usage
SOP is designed to be a polyglot database. To ensure data written in Go can be read by Python, C#, Java, or Rust (and vice versa), you should use the jsondb package. This provides symmetry across all language bindings.
1. Basic Interop (interop_jsondb)
Demonstrates how to store Go structs so they are automatically serialized to the "Universal" JSON format.
- Key Feature:
jsondb.NewJsonBtree[K, V]
- Why: Ensures your data is accessible to AI models in Python or services in C#.
2. Secondary Indexes (interop_secondary_indexes)
Demonstrates "Schema-less" storage with composite secondary indexes.
- Key Feature:
jsondb.NewJsonBtreeMapKey + IndexSpecification
- Why: Allows you to define sorting rules (e.g., "Sort by Category ASC, then Price DESC") that are respected by all language bindings.
- New: Also includes
struct_key_main.go demonstrating jsondb.NewJsonBtreeStructKey for a more idiomatic Go experience using structs as keys.
For pure Go microservices where you don't need to share data with other languages, you can use the native generic API.
3. Swarm Computing (swarm_standalone & swarm_clustered)
Demonstrates SOP's ability to handle concurrent transactions from multiple threads (or processes) without external locks.
- Key Feature:
database.NewBtree[K, V] (Native)
- Scenario: 40 concurrent threads updating the same B-Tree.
- Variants:
swarm_standalone: Runs on local disk.
swarm_clustered: Runs on Redis (simulating a distributed cluster).
🏢 Multi-Tenancy & Configuration
4. Multi-Redis (multi_redis_url)
Demonstrates connecting to multiple Redis databases (e.g., DB 0 and DB 1) in the same application using the standard URL format.
- Key Feature:
RedisCacheConfig.URL (redis://host:port/db)
5. KnowledgeBase CLI (knowledgebase_cli)
Demonstrates a standalone in-memory KnowledgeBase workflow with nested categories, item upserts, category listing, and search.
- Key Feature:
memory.KnowledgeBase + memory.NewStore
- Why: Gives you a minimal app you can run directly to see the high-level API in action.
▶️ Running the Examples
You can run all examples in sequence using the suite script in the root directory:
./run_go_suite.sh
Or run individual examples:
go run examples/interop_jsondb/main.go