| 1234567891011121314151617181920212223242526272829303132333435363738 |
- package main
- import (
- "fmt"
- "os"
- "igit.com/xbase/raft/db"
- )
- func main() {
- dir := "test_db_data"
- os.RemoveAll(dir) // Start fresh
-
- fmt.Println("Initializing DB Engine...")
- e, err := db.NewEngine(dir)
- if err != nil {
- panic(err)
- }
-
- fmt.Println("\n1. Insert initial data (Append)")
- e.Set("config.timeout", "10s", 1) // len=3, cap=16
- e.Set("config.retries", "3", 2) // len=1, cap=16
- e.Set("app.name", "demo-app-v1", 3) // len=11, cap=16
-
- fmt.Println("\n2. In-place update (Same length or smaller)")
- e.Set("config.timeout", "20s", 4) // len=3, cap=16 -> In-place!
-
- fmt.Println("\n3. In-place update (Larger but fits capacity)")
- e.Set("config.retries", "10", 5) // len=2, cap=16 -> In-place! (was 1)
-
- fmt.Println("\n4. Append update (Exceeds capacity)")
- e.Set("app.name", "demo-application-v2-long-name", 6) // len=29, cap=32 -> Append!
-
- e.Close()
- fmt.Println("\nDB Closed. Run inspector to see file layout.")
- fmt.Printf("\nTry running:\n go run example/database/inspector.go %s\n", dir)
- }
|