Documentation
¶
Overview ¶
Package sql compiles validated policy conditions into provider-rendered, parameterized SQL predicate fragments. It owns traversal, relation correlation, alias allocation, and bind ordering; dialects own leaf syntax and physical value codecs.
Index ¶
- func RebasePlaceholders(text string, offset int, provider ir.Provider) string
- type Binder
- type BoundValue
- type CapabilityProof
- type Column
- type Correlation
- type Dialect
- type Error
- type ErrorCode
- type Field
- type Fragment
- type JSONLeaf
- type ListLeaf
- type Model
- type PolicyAliasAllocator
- type PolicyRelationAliasFact
- type Relation
- type Request
- type Resolver
- type ScalarLeaf
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Binder ¶
type Binder struct {
// contains filtered or unexported fields
}
Binder is the only path from a dialect leaf to statement arguments.
type BoundValue ¶
BoundValue carries a typed immutable operand plus any descriptor-resolved enum wire values needed by physical storage. Dialects never guess persisted enum labels from stable identity bytes.
type CapabilityProof ¶
type CapabilityProof struct {
// contains filtered or unexported fields
}
CapabilityProof is an immutable snapshot of capabilities measured for the active provider instance. It is separate from static schema declarations.
func NewCapabilityProof ¶
func NewCapabilityProof(provider ir.Provider, fingerprint [32]byte, capabilities ...ir.Capability) (CapabilityProof, error)
func (CapabilityProof) Has ¶
func (proof CapabilityProof) Has(capability ir.Capability) bool
func (CapabilityProof) Provider ¶
func (proof CapabilityProof) Provider() ir.Provider
func (CapabilityProof) SchemaFingerprint ¶
func (proof CapabilityProof) SchemaFingerprint() [32]byte
type Column ¶
type Column struct {
Alias physical.PhysicalName
Name physical.PhysicalName
}
type Dialect ¶
type Dialect interface {
Provider() ir.Provider
Quote(physical.PhysicalName) string
Table(Model) string
Placeholder(position int) string
Encode(BoundValue) (any, error)
Supports(ir.OperatorID) bool
RenderScalar(ScalarLeaf, *Binder) (string, error)
RenderList(ListLeaf, *Binder) (string, error)
RenderJSON(JSONLeaf, *Binder) (string, error)
}
Dialect is deliberately high-level: it cannot alter logical traversal or relation quantifier semantics. A dialect renders only closed leaf families, quotes descriptor names, and encodes typed values.
type Error ¶
type Fragment ¶
type Fragment struct {
// contains filtered or unexported fields
}
Fragment is an immutable predicate and its positional arguments. SQL is produced only by the shared walker and a closed provider dialect.
func CompileWithPolicyAliasAllocator ¶ added in v0.1.0
func CompileWithPolicyAliasAllocator(request Request, aliases *PolicyAliasAllocator) (Fragment, error)
CompileWithPolicyAliasAllocator compiles one fragment within an outer renderer-owned statement allocation scope. The allocator must be fresh for that statement and shared by every fragment that contributes SQL to it.
func (Fragment) PolicyRelationAliases ¶ added in v0.1.0
func (fragment Fragment) PolicyRelationAliases() []PolicyRelationAliasFact
PolicyRelationAliases returns allocation-ordered, caller-owned facts for aliases allocated by this policy fragment. The outer renderer owns and registers the root alias separately.
type JSONLeaf ¶
type JSONLeaf struct {
Column Column
Field Field
Operator ir.OperatorID
Mode ir.ComparisonMode
Path ir.JSONPath
Operand ir.Operand
}
type Model ¶
type Model struct {
ID ir.ModelID
Namespace physical.PhysicalName
Table physical.PhysicalName
}
type PolicyAliasAllocator ¶ added in v0.1.0
type PolicyAliasAllocator struct {
// contains filtered or unexported fields
}
PolicyAliasAllocator is a single-render ownership token. The ordinary SQL renderer shares one allocator across every independently compiled policy fragment in a statement so aliases remain globally unique even across nested scopes. It exposes no counter or allocated identifier.
func NewPolicyAliasAllocator ¶ added in v0.1.0
func NewPolicyAliasAllocator() *PolicyAliasAllocator
type PolicyRelationAliasFact ¶ added in v0.1.0
type PolicyRelationAliasFact struct {
// contains filtered or unexported fields
}
PolicyRelationAliasFact is one renderer-owned policy traversal identity. It deliberately retains no SQL, predicate, bind, actor, table, column, or provider object name. The opaque alias can only be compared with a provider plan alias; it cannot be extracted and reused as an identifier.
func (PolicyRelationAliasFact) Matches ¶ added in v0.1.0
func (fact PolicyRelationAliasFact) Matches(candidate string) bool
Matches compares an untrusted provider alias with the exact renderer-owned token. Zero or incomplete facts never match.
func (PolicyRelationAliasFact) ModelID ¶ added in v0.1.0
func (fact PolicyRelationAliasFact) ModelID() ir.ModelID
func (PolicyRelationAliasFact) RelationID ¶ added in v0.1.0
func (fact PolicyRelationAliasFact) RelationID() ir.RelationID
type Relation ¶
type Relation struct {
Model ir.ModelID
Field ir.FieldID
ID ir.RelationID
Target ir.ModelID
Cardinality ir.RelationCardinality
Pairs []Correlation
}
type Request ¶
type Request struct {
Condition ir.Condition
Provider ir.Provider
Resolver Resolver
Dialect Dialect
Capabilities CapabilityProof
BoundFingerprint [32]byte
RootAlias physical.PhysicalName
}
type Resolver ¶
type Resolver interface {
Providers() ir.ProviderSet
SchemaFingerprint() [32]byte
Model(provider ir.Provider, model ir.ModelID) (Model, bool)
Field(provider ir.Provider, model ir.ModelID, field ir.FieldID) (Field, bool)
Relation(model ir.ModelID, field ir.FieldID, relation ir.RelationID) (Relation, bool)
EnumWire(enum ir.EnumID, value ir.EnumValueID) (string, bool)
Capability(provider ir.Provider, capability ir.Capability) bool
}
Resolver publishes only descriptor-derived identities and physical names. Implementations must reject wrong-owner field identities.
func SchemaResolver ¶
type ScalarLeaf ¶
type ScalarLeaf struct {
Column Column
Field Field
Operator ir.OperatorID
Mode ir.ComparisonMode
Operand ir.Operand
}