orm

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package orm owns the compiler-side integration for the official trb/orm package. The compiler pipeline transports its declarations and IR manifest without depending on database adapters or ORM semantics.

Index

Constants

View Source
const (
	PackageName     = "trb/orm"
	TypeProvider    = "trb.orm"
	ProjectProvider = "trb.orm.schema"
)

Variables

This section is empty.

Functions

func AggregateOperations

func AggregateOperations() []string

func AggregateResultType

func AggregateResultType(operation string, column Column) (types.Type, bool)

func Declarations

func Declarations(programs []*ast.Program, projectRoot string, options map[string][]byte) (*declaration.Catalog, error)

func TableName

func TableName(model string) string

Types

type Adapter

type Adapter struct {
	Name            string
	DriverName      string
	GoDriverImport  string
	IdentifierMark  string
	NumberedBinds   bool
	ExplainStyle    ExplainStyle
	OffsetNoLimit   string
	InsertReturning bool
	DefaultInsert   string
}

Adapter describes the database-specific behavior shared by schema introspection and backend runtime generation.

func AdapterFor

func AdapterFor(name string) (Adapter, error)

func (Adapter) Placeholder

func (a Adapter) Placeholder(position int) string

func (Adapter) QuoteIdentifier

func (a Adapter) QuoteIdentifier(name string) string

type Association

type Association struct {
	Name                string
	Kind                AssociationKind
	TargetModel         string
	TargetQuery         string
	SourceColumn        string
	TargetColumn        string
	Inverse             string
	Through             string
	Source              string
	Dependent           DependentAction
	Scoped              bool
	Scope               *ir.Block
	Preloadable         bool
	CardinalityVerified bool
}

type AssociationKind

type AssociationKind string
const (
	BelongsTo AssociationKind = "belongs_to"
	HasMany   AssociationKind = "has_many"
	HasOne    AssociationKind = "has_one"
)

type Column

type Column struct {
	Name         string
	DatabaseType string
	Type         types.Type
	Nullable     bool
	PrimaryKey   bool
	HasDefault   bool
	Generated    bool
	Position     int
}

type Config

type Config struct {
	Adapter  string `json:"adapter"`
	Database string `json:"database"`
}

type DependentAction

type DependentAction string
const (
	DependentDestroy  DependentAction = "destroy"
	DependentDelete   DependentAction = "delete"
	DependentNullify  DependentAction = "nullify"
	DependentRestrict DependentAction = "restrict"
)

type ExplainStyle

type ExplainStyle string
const (
	ExplainSQLite ExplainStyle = "sqlite"
	ExplainText   ExplainStyle = "text"
	ExplainJSON   ExplainStyle = "json"
)

type ForeignKey

type ForeignKey struct {
	ID               int
	Sequence         int
	Column           string
	ReferencedTable  string
	ReferencedColumn string
}

type Introspector

type Introspector interface {
	Inspect(Config) (*Schema, error)
}

type Manifest

type Manifest struct {
	Adapter             string
	Database            string
	DatabaseEnvironment string
	Models              []Model
}

func Analyze

func Analyze(programs []*ast.Program, projectRoot string, options map[string][]byte) (*Manifest, error)

func ManifestFrom

func ManifestFrom(extensions []ir.Extension) *Manifest

func (*Manifest) Augment

func (m *Manifest) Augment(program *ir.Program)

func (*Manifest) ChangesModel

func (m *Manifest) ChangesModel(name string) (Model, bool)

func (*Manifest) DraftModel

func (m *Manifest) DraftModel(name string) (Model, bool)

func (*Manifest) ExtensionName

func (*Manifest) ExtensionName() string

func (*Manifest) GroupModel

func (m *Manifest) GroupModel(name string) (Model, Column, bool)

func (*Manifest) Model

func (m *Manifest) Model(name string) (Model, bool)

func (*Manifest) ModelsForModule

func (m *Manifest) ModelsForModule(modulePath string) []Model

func (*Manifest) QueryModel

func (m *Manifest) QueryModel(name string) (Model, bool)

func (*Manifest) ScopeModel

func (m *Manifest) ScopeModel(name string) (Model, bool)

type Model

type Model struct {
	Name              string
	QueryType         string
	Table             string
	ModulePath        string
	Columns           []Column
	Associations      []Association
	UniqueConstraints []UniqueConstraint
}

func (Model) Association

func (m Model) Association(name string) (Association, bool)

func (Model) BatchKey

func (m Model) BatchKey() (Column, bool)

func (Model) ChangesType

func (m Model) ChangesType() string

func (Model) Column

func (m Model) Column(name string) (Column, bool)

func (Model) DraftType

func (m Model) DraftType() string

func (Model) GroupType

func (m Model) GroupType(column Column) string

func (Model) PrimaryKey

func (m Model) PrimaryKey() (Column, bool)

func (Model) ScopeType

func (m Model) ScopeType() string

type Operator

type Operator string
const (
	Equal              Operator = "="
	NotEqual           Operator = "!="
	LessThan           Operator = "<"
	LessThanOrEqual    Operator = "<="
	GreaterThan        Operator = ">"
	GreaterThanOrEqual Operator = ">="
	In                 Operator = "IN"
	RangeInclusive     Operator = "RANGE_INCLUSIVE"
	RangeExclusive     Operator = "RANGE_EXCLUSIVE"
	NotIn              Operator = "NOT_IN"
)

type Predicate

type Predicate struct {
	Column   string
	Operator Operator
	Value    ir.Expression
}

func Predicates

func Predicates(call *ir.Call) []Predicate

type Schema

type Schema struct {
	Adapter             string
	Database            string
	DatabaseEnvironment string
	Tables              []Table
}

func InspectSchema added in v0.2.1

func InspectSchema(config Config) (*Schema, error)

func LoadSchema

func LoadSchema(projectRoot string, options map[string][]byte) (*Schema, error)

func (*Schema) Table

func (s *Schema) Table(name string) (Table, bool)

type Table

type Table struct {
	Name              string
	Columns           []Column
	ForeignKeys       []ForeignKey
	UniqueConstraints []UniqueConstraint
}

type UniqueConstraint

type UniqueConstraint struct {
	Name    string
	Columns []string
	Primary bool
}

Jump to

Keyboard shortcuts

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