orm

package
v1.17.4 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 16 Imported by: 19

Documentation

Index

Constants

View Source
const Associations = clause.Associations

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model struct {
	Timestamps
	ID uint `gorm:"primaryKey" json:"id"`
}

Model is the base model for all models in the application.

type Orm added in v1.15.0

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

func BuildOrm added in v1.15.0

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

func NewOrm added in v1.15.0

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),
) *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 added in v1.15.12

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

func (*Orm) Connection added in v1.15.0

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

func (*Orm) DB added in v1.15.0

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

func (*Orm) DatabaseName added in v1.15.0

func (r *Orm) DatabaseName() string

func (*Orm) Factory added in v1.15.0

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

func (*Orm) Fresh added in v1.15.12

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 added in v1.15.0

func (r *Orm) Name() string

func (*Orm) Observe added in v1.15.0

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

func (*Orm) Query added in v1.15.0

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

func (*Orm) SetQuery added in v1.15.0

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

func (*Orm) Transaction added in v1.15.0

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

func (*Orm) WithContext added in v1.15.0

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

type QueriesCache added in v1.17.4

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 added in v1.17.4

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.

type SoftDeletes

type SoftDeletes struct {
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"`
}

SoftDeletes is used to add soft delete functionality to a model.

type Timestamps added in v1.0.0

type Timestamps struct {
	CreatedAt *carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"`
	UpdatedAt *carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"`
}

Timestamps is used to add created_at and updated_at timestamps to a model.

Jump to

Keyboard shortcuts

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