Documentation
¶
Overview ¶
Package dbrepo provides opinionated repository helpers on top of dbx.
It is intentionally table-configured instead of proto-schema-driven: SQL migration files remain the database source of truth, while repositories give AI agents a safe CRUD vocabulary for common resource tables.
Index ¶
- Variables
- type Page
- type Query
- type ResourceConfig
- type ResourceRepository
- func (r *ResourceRepository[T]) Create(ctx context.Context, row *T) error
- func (r *ResourceRepository[T]) Delete(ctx context.Context, id any) error
- func (r *ResourceRepository[T]) Get(ctx context.Context, id any) (*T, error)
- func (r *ResourceRepository[T]) List(ctx context.Context, q Query) (*Page[T], error)
- func (r *ResourceRepository[T]) Patch(ctx context.Context, id any, patch map[string]any) error
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Query ¶
Query is the safe list contract. Filters and sorts are checked against the ResourceConfig allowlists before reaching the DB.
type ResourceConfig ¶
type ResourceConfig struct {
Resource string
Table string
IDColumn string
TenantColumn string
OwnerColumn string
DeletedColumn string
CreatedColumn string
UpdatedColumn string
TenantScoped bool
OwnerScoped bool
SoftDelete bool
Timestamps bool
AllowedFilters []string
AllowedSorts []string
AllowedPatchFields []string
BlockedPatchFields []string
MaxPageSize int
}
ResourceConfig describes Kernel's safe CRUD conventions for one table.
type ResourceRepository ¶
type ResourceRepository[T any] struct { // contains filtered or unexported fields }
ResourceRepository implements tenant-aware, owner-aware, soft-delete-aware CRUD for a conventional resource table. It deliberately fails closed for tenant or owner scoped tables when ctx is missing the required scope metadata.
func MustResourceRepository ¶
func MustResourceRepository[T any](db dbx.DB, cfg ResourceConfig) *ResourceRepository[T]
func NewResourceRepository ¶
func NewResourceRepository[T any](db dbx.DB, cfg ResourceConfig) (*ResourceRepository[T], error)
func (*ResourceRepository[T]) Create ¶
func (r *ResourceRepository[T]) Create(ctx context.Context, row *T) error
func (*ResourceRepository[T]) Delete ¶
func (r *ResourceRepository[T]) Delete(ctx context.Context, id any) error
func (*ResourceRepository[T]) Get ¶
func (r *ResourceRepository[T]) Get(ctx context.Context, id any) (*T, error)