Files
warkanum 4b3f0b1b55
CI / build-and-test (push) Failing after 1m53s
CI / build-and-test (pull_request) Failing after 1m43s
feat: add per-user tenant scoping
2026-07-15 04:27:44 +02:00

35 lines
800 B
Go

package store
import (
"context"
"fmt"
"git.warky.dev/wdevs/amcs/internal/tenancy"
)
func tenantKeyPtr(ctx context.Context) *string {
if key, ok := tenancy.KeyFromContext(ctx); ok {
return &key
}
return nil
}
func tenantKey(ctx context.Context) (string, bool) {
return tenancy.KeyFromContext(ctx)
}
func addTenantCondition(ctx context.Context, args *[]any, conditions *[]string, column string) {
if key, ok := tenancy.KeyFromContext(ctx); ok {
*args = append(*args, key)
*conditions = append(*conditions, fmt.Sprintf("%s = $%d", column, len(*args)))
}
}
func tenantSQL(ctx context.Context, args *[]any, column string) string {
if key, ok := tenancy.KeyFromContext(ctx); ok {
*args = append(*args, key)
return fmt.Sprintf(" and %s = $%d", column, len(*args))
}
return ""
}