this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement kv store in stdout

+100 -12
+2 -2
cmd/butterfly/cmd_discover.go
··· 112 112 case "duckdb": 113 113 s = store.NewDuckdbStore(dbPath) 114 114 default: 115 - return fmt.Errorf("unknown output mode: %s", storeMode) 115 + return fmt.Errorf("unknown storage mode: %s", storeMode) 116 116 } 117 117 118 118 // Initialize store ··· 144 144 } 145 145 146 146 // Resolve all results 147 - fmt.Printf("Found %d repositories\n\n", len(result.Dids)) 147 + fmt.Printf("Discovered %d repositories\n", len(result.Dids)) 148 148 for _, did := range result.Dids { 149 149 _, err := resolver.ResolveDID(ctx, did) 150 150 if err != nil {
+1 -1
cmd/butterfly/cmd_sync.go
··· 116 116 case "duckdb": 117 117 s = store.NewDuckdbStore(dbPath) 118 118 default: 119 - return fmt.Errorf("unknown output mode: %s", storeMode) 119 + return fmt.Errorf("unknown storage mode: %s", storeMode) 120 120 } 121 121 122 122 // Create context
+2 -2
cmd/butterfly/identity/store_directory.go
··· 314 314 // TODO - is this right? 315 315 entryJSON, err := json.Marshal(entry) 316 316 if err != nil { 317 - return nil 317 + return err 318 318 } 319 319 return store.KvPut(handleCache, string(handle), string(entryJSON)) 320 320 } ··· 340 340 // TODO - is this right? 341 341 entryJSON, err := json.Marshal(entry) 342 342 if err != nil { 343 - return nil 343 + return err 344 344 } 345 345 return store.KvPut(identityCache, string(did), string(entryJSON)) 346 346 }
+95 -7
cmd/butterfly/store/stdout.go
··· 20 20 21 21 // Stats tracking 22 22 stats map[string]*repoStats 23 + 24 + // KV storage (namespace -> key -> value) 25 + kvStore map[string]map[string]string 23 26 } 24 27 25 28 type repoStats struct { ··· 34 37 if s.Mode == StdoutStoreModeStats { 35 38 s.stats = make(map[string]*repoStats) 36 39 } 40 + // Initialize KV store 41 + s.kvStore = make(map[string]map[string]string) 37 42 return nil 38 43 } 39 44 40 45 // Close outputs final statistics if in stats mode 41 46 func (s *StdoutStore) Close() error { 42 - if s.Mode == StdoutStoreModeStats && len(s.stats) > 0 { 47 + if s.Mode == StdoutStoreModeStats { 43 48 s.printStats() 44 49 } 45 50 return nil ··· 107 112 } 108 113 } 109 114 } 115 + 116 + // Print KV store statistics 117 + if len(s.kvStore) > 0 { 118 + fmt.Println("\n=== KV Store Statistics ===") 119 + totalKeys := 0 120 + for namespace, nsMap := range s.kvStore { 121 + keyCount := len(nsMap) 122 + totalKeys += keyCount 123 + fmt.Printf("\nNamespace: %s\n", namespace) 124 + fmt.Printf(" Keys: %d\n", keyCount) 125 + 126 + // Show sample keys (up to 5) 127 + if keyCount > 0 { 128 + fmt.Println(" Sample keys:") 129 + shown := 0 130 + for key := range nsMap { 131 + fmt.Printf(" - %s\n", key) 132 + shown++ 133 + if shown >= 5 { 134 + if keyCount > 5 { 135 + fmt.Printf(" ... and %d more\n", keyCount-5) 136 + } 137 + break 138 + } 139 + } 140 + } 141 + } 142 + fmt.Printf("\nTotal namespaces: %d\n", len(s.kvStore)) 143 + fmt.Printf("Total keys: %d\n", totalKeys) 144 + } 110 145 } 111 146 112 - // KvGet retrieves a value from general KV storage (not yet implemented) 147 + // KvGet retrieves a value from general KV storage 113 148 func (s *StdoutStore) KvGet(namespace string, key string) (string, error) { 114 - return "", fmt.Errorf("KvGet not yet implemented for stdout store") 149 + if s.kvStore == nil { 150 + return "", fmt.Errorf("KV store not initialized - call Setup() first") 151 + } 152 + 153 + nsMap, exists := s.kvStore[namespace] 154 + if !exists { 155 + return "", fmt.Errorf("key not found in namespace %q", namespace) 156 + } 157 + 158 + value, exists := nsMap[key] 159 + if !exists { 160 + return "", fmt.Errorf("key %q not found in namespace %q", key, namespace) 161 + } 162 + 163 + return value, nil 115 164 } 116 165 117 - // KvPut stores a value in general KV storage (not yet implemented) 166 + // KvPut stores a value in general KV storage 118 167 func (s *StdoutStore) KvPut(namespace string, key string, value string) error { 119 - return fmt.Errorf("KvPut not yet implemented for stdout store") 168 + if s.kvStore == nil { 169 + return fmt.Errorf("KV store not initialized - call Setup() first") 170 + } 171 + 172 + // Create namespace map if it doesn't exist 173 + if _, exists := s.kvStore[namespace]; !exists { 174 + s.kvStore[namespace] = make(map[string]string) 175 + } 176 + 177 + // Store the value 178 + s.kvStore[namespace][key] = value 179 + 180 + // Log the operation in passthrough mode 181 + if s.Mode == StdoutStoreModePassthrough { 182 + fmt.Printf("KV PUT: namespace=%q key=%q value=%q\n", namespace, key, value) 183 + } 184 + 185 + return nil 120 186 } 121 187 122 - // KvDel deletes a value from general KV storage (not yet implemented) 188 + // KvDel deletes a value from general KV storage 123 189 func (s *StdoutStore) KvDel(namespace string, key string) error { 124 - return fmt.Errorf("KvDel not yet implemented for stdout store") 190 + if s.kvStore == nil { 191 + return fmt.Errorf("KV store not initialized - call Setup() first") 192 + } 193 + 194 + nsMap, exists := s.kvStore[namespace] 195 + if !exists { 196 + // Key doesn't exist, but that's not an error for delete 197 + return nil 198 + } 199 + 200 + delete(nsMap, key) 201 + 202 + // Clean up empty namespace 203 + if len(nsMap) == 0 { 204 + delete(s.kvStore, namespace) 205 + } 206 + 207 + // Log the operation in passthrough mode 208 + if s.Mode == StdoutStoreModePassthrough { 209 + fmt.Printf("KV DEL: namespace=%q key=%q\n", namespace, key) 210 + } 211 + 212 + return nil 125 213 }