ir

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package ir defines the resolved intermediate representation (IR) of a GCORM schema. The IR is produced by the resolve stage and consumed by code generators.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Datasource

type Datasource struct {
	Name     string
	Provider string // "postgresql", "mysql", "sqlite"
	URL      string // raw URL or env() reference
	URLIsEnv bool   // true if URL comes from env()
	EnvVar   string // environment variable name if URLIsEnv
	Schema   string // database schema/namespace
	Span     ast.Span
}

Datasource holds the resolved database connection configuration.

type DefaultValue

type DefaultValue struct {
	IsFunction bool
	FuncName   string // e.g. "uuid", "now", "autoincrement"
	FuncArgs   []string
	Value      string // literal value for non-function defaults
	IsString   bool
	IsNumber   bool
	IsBool     bool
}

DefaultValue holds the resolved @default value for a field.

type DialectType

type DialectType struct {
	SQLType    string
	GoType     string
	NullGoType string
	IsNullable bool
}

DialectType holds dialect-specific type information.

type Enum

type Enum struct {
	Name   string
	DBName string // from @@map
	Values []*EnumValue
	Span   ast.Span
}

Enum holds the resolved definition of an enumeration type.

type EnumValue

type EnumValue struct {
	Name   string
	DBName string // from @map
}

EnumValue holds a single resolved enum member.

type Field

type Field struct {
	Name        string
	DBName      string // from @map, defaults to field name
	Type        FieldKind
	ScalarType  string // "String", "Int", etc. for scalar fields
	EnumType    string // enum name for enum fields
	ModelType   string // model name for relation fields
	IsOptional  bool
	IsList      bool
	IsID        bool // has @id
	IsUnique    bool // has @unique
	IsUpdatedAt bool // has @updatedAt
	Default     *DefaultValue
	NativeType  *NativeType // from @db.*
	Span        ast.Span
}

Field holds the resolved definition of a single model field.

type FieldKind

type FieldKind int

FieldKind classifies a field's type category.

const (
	FieldKindScalar   FieldKind = iota // built-in scalar type
	FieldKindEnum                      // references an enum
	FieldKindRelation                  // references another model
)

type GenerationManifest

type GenerationManifest struct {
	SchemaFiles []string
	Models      []string
	Enums       []string
	Generator   string
	Output      string
	Package     string
}

GenerationManifest records what was generated and from what.

type Generator

type Generator struct {
	Name        string
	Provider    string
	Output      string
	Package     string
	EmitRuntime bool
	Span        ast.Span
}

Generator holds the resolved code generation configuration.

type Index

type Index struct {
	Name     string
	Fields   []string
	IsUnique bool
	Span     ast.Span
}

Index holds a resolved model-level index (@@index or @@unique).

type Model

type Model struct {
	Name              string
	DBName            string // from @@map, defaults to model name
	Schema            string // from @@schema
	Fields            []*Field
	Relations         []*Relation
	Indexes           []*Index
	PrimaryKey        *PrimaryKey
	UniqueConstraints []*UniqueConstraint
	Span              ast.Span
}

Model holds the resolved definition of a data model.

func (*Model) ScalarFields

func (m *Model) ScalarFields() []*Field

ScalarFields returns only non-relation fields.

func (*Model) TableName

func (m *Model) TableName() string

TableName returns the database table name (DBName if set, otherwise Name).

type NativeType

type NativeType struct {
	Name string   // e.g. "VarChar"
	Args []string // e.g. ["255"]
}

NativeType holds a provider-specific type annotation from @db.*.

type PrimaryKey

type PrimaryKey struct {
	Fields      []string
	IsComposite bool
}

PrimaryKey holds the resolved primary key for a model.

type Relation

type Relation struct {
	Name       string // relation name (optional)
	Field      *Field // the field that declared @relation
	Type       RelationType
	FromModel  string
	ToModel    string
	Fields     []string // local fields (from `fields:`)
	References []string // remote fields (from `references:`)
	OnDelete   string
	OnUpdate   string
}

Relation holds the resolved relationship between two models.

type RelationType

type RelationType int

RelationType classifies the cardinality of a relation.

const (
	RelationOneToOne RelationType = iota
	RelationOneToMany
	RelationManyToOne
	RelationManyToMany
)

type Schema

type Schema struct {
	Datasource *Datasource
	Generators []*Generator
	Models     []*Model
	Enums      []*Enum
}

Schema is the fully resolved schema graph, the output of the compiler pipeline.

type UniqueConstraint

type UniqueConstraint struct {
	Name   string
	Fields []string
}

UniqueConstraint holds a resolved model-level unique constraint (@@unique).

Jump to

Keyboard shortcuts

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