Help us shape the future of Go! Take the 2026 Go Developer Survey

internal

package
v1.20.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Orm

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

func BuildOrm

func BuildOrm(ctx context.Context, config config.Config, connection string, log log.Log, fresh func(key ...any), telemetryResolver contractstelemetry.Resolver) (*Orm, error)

func NewOrm

func NewOrm(
	ctx context.Context,
	config config.Config,
	connection string,
	dbConfig database.Config,
	query contractsorm.Query,
	queries *QueriesCache,
	log log.Log,
	modelToObserver []contractsorm.ModelToObserver,
	fresh func(key ...any),
	telemetryResolver contractstelemetry.Resolver,
) *Orm

NewOrm creates a new Orm instance for the given connection.

queries is the shared, concurrency-safe registry of built connections and must be non-nil (construct it via NewQueriesCache). It should contain an entry for the connection (extended lazily by Connection()).

func (*Orm) Config

func (r *Orm) Config() database.Config

func (*Orm) Connection

func (r *Orm) Connection(name string) contractsorm.Orm

func (*Orm) DB

func (r *Orm) DB() (*sql.DB, error)

func (*Orm) DatabaseName

func (r *Orm) DatabaseName() string

func (*Orm) Factory

func (r *Orm) Factory() contractsorm.Factory

func (*Orm) Fresh

func (r *Orm) Fresh()

TODO: The fresh logic needs to be optimized, it's a bit unclear now. https://github.com/goravel/goravel/issues/848

func (*Orm) Name

func (r *Orm) Name() string

func (*Orm) Observe

func (r *Orm) Observe(model any, observer contractsorm.Observer)

func (*Orm) Query

func (r *Orm) Query() contractsorm.Query

Query gets a new query builder instance, as the Orm contract states and as Laravel's Connection::query() does: a fresh builder every call, so the Model / Where / Raw a caller writes are that caller's alone. The stored handle is the connection's, not a query anyone builds on.

func (*Orm) Related

func (r *Orm) Related(parent any, relation string) contractsorm.Query

Related returns a Query pre-scoped to the related rows for parent.relation. parent must be a non-nil pointer to a struct. See contractsorm.Orm.Related for the per-kind shape.

func (*Orm) Relation

func (r *Orm) Relation(parent any, name string) contractsorm.RelationWriter

Relation returns a RelationWriter bound to (parent, name) for FK-safe write operations. See contractsorm.Orm.Relation for usage.

func (*Orm) SetQuery

func (r *Orm) SetQuery(query contractsorm.Query)

func (*Orm) Transaction

func (r *Orm) Transaction(txFunc func(tx contractsorm.Query) error) (err error)

func (*Orm) WithContext

func (r *Orm) WithContext(ctx context.Context) contractsorm.Orm

type QueriesCache

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

QueriesCache is the shared, concurrency-safe registry of connections built from the same database config. Every Orm instance created from the same connection pool shares one QueriesCache, so concurrent Connection(name) calls from different instances (e.g. lazily building the same non-default connection from multiple goroutines) are serialized by the internal mutex.

func NewQueriesCache

func NewQueriesCache(queries map[string]contractsorm.Query, dbConfigs map[string]database.Config) *QueriesCache

NewQueriesCache creates a QueriesCache from per-connection queries and configs. queries and dbConfigs must be keyed identically by connection name.

Directories

Path Synopsis
Package reflectx implements extensions to the standard reflect lib suitable for implementing marshaling and unmarshaling packages.
Package reflectx implements extensions to the standard reflect lib suitable for implementing marshaling and unmarshaling packages.

Jump to

Keyboard shortcuts

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