Documentation
¶
Index ¶
- type PrimaryKeyProvider
- type RelationResolver
- func (r *RelationResolver) Has(name string) bool
- func (r *RelationResolver) LookupRelated(ctx context.Context, db *sql.DB, sourceTable, sourceID, relation string) (map[string]interface{}, error)
- func (r *RelationResolver) Names() []string
- func (r *RelationResolver) ResolveMany(ctx context.Context, db *sql.DB, sourceTable, sourceID, relationName string) ([]map[string]interface{}, error)
- func (r *RelationResolver) ResolveOne(ctx context.Context, db *sql.DB, sourceTable, sourceID, relationName string) (map[string]interface{}, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PrimaryKeyProvider ¶
PrimaryKeyProvider tells the resolver which column holds the primary key for a given table. Consumers usually pass their SchemaMapper — the same method signature is intentional so it satisfies this interface without adapters.
type RelationResolver ¶
type RelationResolver struct {
// contains filtered or unexported fields
}
RelationResolver executes named relations declared in a bundle's Relations block. Given a source table + primary-key id + relation name, it walks the declared join chain and returns the target row(s).
Constrained by design: each join step is a plain "left column equals right column" join. No arbitrary WHERE clauses, no subqueries, no functions. This keeps rule-author-supplied relations bounded to safe compositions.
The resolver is stateless beyond its relation map and PK provider. Consumers construct one at bundle-load time and pass it to validators that need cross-table access.
func NewRelationResolver ¶
func NewRelationResolver(relations map[string]domain.Relation, pkProvider PrimaryKeyProvider) *RelationResolver
NewRelationResolver builds a resolver over a relations map and a PK provider (typically the consumer's SchemaMapper). Nil relations map is fine — the resolver just fails every lookup with an "unknown relation" error. A nil pkProvider is a programmer error: the resolver panics rather than emit SQL with an unquoted empty column name.
func (*RelationResolver) Has ¶
func (r *RelationResolver) Has(name string) bool
Has reports whether a relation with the given name is declared. Cheap — used by Requires-block checks that verify the resolver knows every relation a bundle needs.
func (*RelationResolver) LookupRelated ¶
func (r *RelationResolver) LookupRelated(ctx context.Context, db *sql.DB, sourceTable, sourceID, relation string) (map[string]interface{}, error)
LookupRelated satisfies domain.ConditionResolver. Delegates to ResolveOne so relation-scoped rule conditions can call through the same code path validators use for join traversal.
func (*RelationResolver) Names ¶
func (r *RelationResolver) Names() []string
Names returns every declared relation name. Used by consumers building an availableRelations map for CheckRequires.
func (*RelationResolver) ResolveMany ¶
func (r *RelationResolver) ResolveMany(ctx context.Context, db *sql.DB, sourceTable, sourceID, relationName string) ([]map[string]interface{}, error)
ResolveMany executes a many-cardinality relation and returns every target row. Empty slice + nil error when the relation yields no rows.
func (*RelationResolver) ResolveOne ¶
func (r *RelationResolver) ResolveOne(ctx context.Context, db *sql.DB, sourceTable, sourceID, relationName string) (map[string]interface{}, error)
ResolveOne executes a one-cardinality relation from (sourceTable, sourceID) and returns the single target row. Returns (nil, nil) when the join yields no row — root-taxon asking for parent, orphan record — so callers can treat that as "no data" without an error path.
Errors on: unknown relation name, cardinality mismatch (the relation was declared "many"), malformed join spec, or SQL failure.