mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
package datastore
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hanzoai/commerce/log"
|
|
)
|
|
|
|
// registeredNamespaces allows external code to register available namespaces
|
|
var registeredNamespaces []string
|
|
|
|
// RegisterNamespace registers a namespace for use
|
|
func RegisterNamespace(ns string) {
|
|
registeredNamespaces = append(registeredNamespaces, ns)
|
|
}
|
|
|
|
// GetNamespaces returns all namespaces
|
|
// In the new architecture, namespaces are registered explicitly
|
|
func GetNamespaces(ctx context.Context) []string {
|
|
// Return registered namespaces if any
|
|
if len(registeredNamespaces) > 0 {
|
|
return registeredNamespaces
|
|
}
|
|
|
|
namespaces := make([]string, 0)
|
|
|
|
// Try to fetch namespaces from special __namespace__ table
|
|
db := New(ctx)
|
|
if db.database == nil {
|
|
log.Debug("GetNamespaces: database not initialized, returning empty list")
|
|
return namespaces
|
|
}
|
|
|
|
keys, err := db.Query("__namespace__").GetKeys()
|
|
if err != nil {
|
|
log.Warn("GetNamespaces error: %v", err)
|
|
return namespaces
|
|
}
|
|
|
|
// Append stringID's
|
|
for _, k := range keys {
|
|
namespaces = append(namespaces, k.StringID())
|
|
}
|
|
|
|
return namespaces
|
|
}
|
|
|
|
// GetKinds returns all entity kinds
|
|
func GetKinds(ctx context.Context) []string {
|
|
kinds := make([]string, 0)
|
|
db := New(ctx)
|
|
if db.database == nil {
|
|
log.Debug("GetKinds: database not initialized, returning empty list")
|
|
return kinds
|
|
}
|
|
|
|
keys, err := db.Query("__kind__").GetKeys()
|
|
if err != nil {
|
|
log.Warn("GetKinds error: %v", err)
|
|
return kinds
|
|
}
|
|
|
|
for _, k := range keys {
|
|
kinds = append(kinds, k.StringID())
|
|
}
|
|
|
|
return kinds
|
|
}
|