sql

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package sql renders validated P4 scalar mutation plans into deterministic, provider-specific statement programs. Programs are descriptions only: the caller must execute every statement, in order, on one transaction satisfying TransactionRequirement.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthorizationColumn

type AuthorizationColumn struct {
	// contains filtered or unexported fields
}

AuthorizationColumn is one precomputed field grant evaluated by SQL against the locked pre-image. It is deliberately separate from ResultColumn: grant booleans are execution evidence, never model data and never enter the exact persisted-row decoder.

func (AuthorizationColumn) Alias

func (column AuthorizationColumn) Alias() string

func (AuthorizationColumn) FieldID

func (column AuthorizationColumn) FieldID() policyir.FieldID

type Binding

type Binding struct {
	// contains filtered or unexported fields
}

Binding is one positional SQL argument. Prior-result bindings make dataflow explicit: execution reads FieldID from the exactly-one row returned by the statement at StatementIndex. It must not accept a caller-supplied substitute.

func (Binding) Kind

func (binding Binding) Kind() BindingKind

func (Binding) PriorResult

func (binding Binding) PriorResult() (uint32, policyir.FieldID, bool)

func (Binding) StaticValue

func (binding Binding) StaticValue() (any, bool)

type BindingKind

type BindingKind uint8
const (
	StaticBinding BindingKind = iota + 1
	PriorResultBinding
)

type Cardinality

type Cardinality uint8
const (
	ExactlyOneRow Cardinality = iota + 1
)

type Error

type Error struct {
	Code   ErrorCode
	Model  policyir.ModelID
	Field  policyir.FieldID
	Detail string
	Cause  error
}

func (*Error) Error

func (failure *Error) Error() string

func (*Error) Unwrap

func (failure *Error) Unwrap() error

type ErrorCode

type ErrorCode string
const (
	CodeInput       ErrorCode = "P4_SQL_INPUT"
	CodeSchema      ErrorCode = "P4_SQL_SCHEMA"
	CodeProvider    ErrorCode = "P4_SQL_PROVIDER"
	CodeUnsupported ErrorCode = "P4_SQL_UNSUPPORTED"
	CodeRender      ErrorCode = "P4_SQL_RENDER"
	CodeLimit       ErrorCode = "P4_SQL_LIMIT"
)

type IdentityVerification

type IdentityVerification struct {
	// contains filtered or unexported fields
}

func (IdentityVerification) AfterStatement

func (verification IdentityVerification) AfterStatement() uint32

func (IdentityVerification) BeforeStatement

func (verification IdentityVerification) BeforeStatement() (uint32, bool)

func (IdentityVerification) Behavior

func (verification IdentityVerification) Behavior() mutationir.IdentityBehavior

func (IdentityVerification) Fields

func (verification IdentityVerification) Fields() []policyir.FieldID

type PersistedVerification

type PersistedVerification struct {
	// contains filtered or unexported fields
}

PersistedVerification is a provider-bound, final-graph authorization query. It is used by nested create execution after every graph write has completed.

func RenderPersistedVerification

func RenderPersistedVerification(node mutationir.Node, row mutationdecode.Row, conditions []policyir.Condition, registry *schema.Registry, provider policyir.Provider, capabilities policysql.CapabilityProof) (PersistedVerification, error)

func (PersistedVerification) Args

func (verification PersistedVerification) Args() []any

func (PersistedVerification) SQL

func (verification PersistedVerification) SQL() string

type Program

type Program struct {
	// contains filtered or unexported fields
}

func Render

func Render(plan mutationir.Plan, registry *schema.Registry, provider policyir.Provider, capabilities policysql.CapabilityProof) (Program, error)

Render accepts only a validated, root-only scalar Create, Update, or Delete plan. It returns SQL plus closed positional dataflow; it never executes SQL.

func RenderVersioned added in v0.1.0

func RenderVersioned(plan mutationir.Plan, registry *schema.Registry, provider policyir.Provider, capabilities policysql.CapabilityProof) (Program, error)

RenderVersioned is the sole SQL construction boundary for an update/delete whose exact expectation will be validated by the runtime CAS kernel. It carries no claim value; the returned program is marked as requiring the kernel's unforgeable precheck capability before execution.

func (Program) AuthoredFields

func (program Program) AuthoredFields() []policyir.FieldID

func (Program) FactRequirement

func (program Program) FactRequirement() mutationir.FactRequirement

func (Program) IdentityVerification

func (program Program) IdentityVerification() IdentityVerification

func (Program) ModelID

func (program Program) ModelID() policyir.ModelID

func (Program) Operation

func (program Program) Operation() mutationir.Operation

func (Program) OptimisticConcurrency added in v0.1.0

func (program Program) OptimisticConcurrency() (policyir.FieldID, bool)

func (Program) Provider

func (program Program) Provider() policyir.Provider

func (Program) RequiresConcurrencyPrecheck added in v0.1.0

func (program Program) RequiresConcurrencyPrecheck() bool

func (Program) SemanticIndexed added in v0.3.0

func (program Program) SemanticIndexed() bool

SemanticIndexed carries the plan's registry-derived decision that a write to this model must be recorded for semantic re-embedding.

func (Program) Stance

func (program Program) Stance() mutationir.Stance

func (Program) Statements

func (program Program) Statements() []Statement

func (Program) TransactionRequirement

func (program Program) TransactionRequirement() TransactionRequirement

type ResultColumn

type ResultColumn struct {
	// contains filtered or unexported fields
}

func (ResultColumn) Alias

func (column ResultColumn) Alias() string

func (ResultColumn) FieldID

func (column ResultColumn) FieldID() policyir.FieldID

type Role

type Role uint8
const (
	SelectPreImage Role = iota + 1
	ApplyCreate
	ApplyUpdate
	ApplyDelete
	VerifyPostcondition
)

type Statement

type Statement struct {
	// contains filtered or unexported fields
}

func (Statement) AuthorizationColumns

func (statement Statement) AuthorizationColumns() []AuthorizationColumn

func (Statement) Bindings

func (statement Statement) Bindings() []Binding

func (Statement) Cardinality

func (statement Statement) Cardinality() Cardinality

func (Statement) Columns

func (statement Statement) Columns() []ResultColumn

func (Statement) Role

func (statement Statement) Role() Role

func (Statement) SQL

func (statement Statement) SQL() string

type TransactionRequirement

type TransactionRequirement uint8
const (
	PostgreSQLTransaction TransactionRequirement = iota + 1
	// SQLiteImmediateTransaction means the connection must have acquired write
	// intent (BEGIN IMMEDIATE or an equivalent provider-owned primitive) before
	// the first statement. A deferred read transaction is not sufficient.
	SQLiteImmediateTransaction
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL