database

package
v0.21.6 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: Apache-2.0 Imports: 10 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDatabase = errors.New("database")
	// ErrRepository is an error related with the repository.
	ErrRepository = errors.Wrap(ErrDatabase, "repository")
	// ErrRepositoryNotFound is an error when repository is not found.
	ErrRepositoryNotFound = errors.Wrap(ErrRepository, "not found")
	// ErrRepositoryAlreadyRegistered class of errors when repository is already registered.
	ErrRepositoryAlreadyRegistered = errors.Wrap(ErrRepository, "already registered")
)

Functions

func Count

func Count(ctx context.Context, db DB, s *query.Scope) (int64, error)

Count gets given scope models count.

func Exists

func Exists(ctx context.Context, db DB, s *query.Scope) (bool, error)

Exists checks if given query model exists.

func HealthCheck added in v0.21.5

func HealthCheck(ctx context.Context, db DB) (*repository.HealthResponse, error)

HealthCheck checks all repositories health.

func RefreshModels

func RefreshModels(ctx context.Context, db DB, mStruct *mapping.ModelStruct, models []mapping.Model, fieldSet ...*mapping.StructField) error

RefreshModels refreshes all 'fields' (attributes, foreign keys) for provided input 'models'.

func RunInTransaction added in v0.17.0

func RunInTransaction(ctx context.Context, db DB, options *query.TxOptions, txFunc TxFunc) error

RunInTransaction runs specific function 'txFunc' within a transaction. If an error would return from that function the transaction would be rolled back. Otherwise it commits the changes. If an input 'db' is already within a transaction it would just execute txFunc for given transaction.

Types

type AfterDeleter

type AfterDeleter interface {
	AfterDelete(context.Context, DB) error
}

AfterDeleter is the interface used as an after delete hook.

type AfterFinder

type AfterFinder interface {
	AfterFind(context.Context, DB) error
}

AfterFinder is the interface used as a after find hook.

type AfterInserter

type AfterInserter interface {
	AfterInsert(context.Context, DB) error
}

AfterInserter is the interface that has a method used as a hook after the creation process.

type AfterUpdater

type AfterUpdater interface {
	AfterUpdate(context.Context, DB) error
}

AfterUpdater is the interface used as a after patch hook.

type BeforeDeleter

type BeforeDeleter interface {
	BeforeDelete(context.Context, DB) error
}

BeforeDeleter is the interface used as a before delete hook.

type BeforeInserter

type BeforeInserter interface {
	BeforeInsert(context.Context, DB) error
}

BeforeInserter is the interface used for hooks before the creation process.

type BeforeUpdater

type BeforeUpdater interface {
	BeforeUpdate(context.Context, DB) error
}

BeforeUpdater is the interface used as a before patch hook.

type Builder

type Builder interface {
	// Scope returns current query scope.
	Scope() *query.Scope
	// Err returns error for given query.
	Err() error
	// Ctx returns current query context.
	Ctx() context.Context

	// Count returns the number of model instances in the repository matching given query.
	Count() (int64, error)
	// Insert models into repository. Returns error with class ErrViolationUnique if the model with given primary key already exists.
	Insert() error
	// update updates query models in the repository. Input models with non zero primary key the function would take
	// update these models instances. For a non zero single model with filters it would update all models that match
	// given query. In order to update all models in the repository use UpdateAll method.
	Update() (int64, error)
	// Exists check if input model exists.
	Exists() (bool, error)
	// Get gets single model that matches given query.
	Get() (mapping.Model, error)
	// Find gets all models that matches given query. For models with DeletedAt timestamp field, adds the
	// filter for not nulls DeletedAt models, unless there is other DeletedAt filter.
	Find() ([]mapping.Model, error)
	// deleteQuery deletes models matching given query. If the model has DeletedAt timestamp field it would do the
	// soft delete - update all models matching given query and set their deleted_at field with current timestamp.
	Delete() (int64, error)
	// refreshQuery gets all input models and refreshes all selected fields and included relations.
	Refresh() error

	// Select model fields for the query fieldSet.
	Select(fields ...*mapping.StructField) Builder
	// Where adds the query 'filter' with provided arguments. The query should be composed of the field name and it's
	// operator. In example: 'ID in', 3,4,5 - would result with a filter on primary key field named 'ID' with the
	// IN operator and it's value equal to 3,4 or 5.
	Where(filter string, arguments ...interface{}) Builder
	// Include adds the 'relation' with it's optional fieldset to get for each resulting model to find.
	Include(relation *mapping.StructField, relationFieldset ...*mapping.StructField) Builder
	// OrderBy sorts the results by the fields in the given order.
	OrderBy(fields ...query.Sort) Builder
	// Limit sets the maximum number of the results for given query.
	Limit(limit int64) Builder
	// Offset sets the number of the results to omit in the query.
	Offset(offset int64) Builder
	// Filter adds the filter field to the given query.
	Filter(filter filter.Filter) Builder
	// WhereOr creates a OrGroup filter for provided simple filters.
	WhereOr(filters ...filter.Simple) Builder

	// AddRelations adds the 'relations' models to input models for 'relationField'
	AddRelations(relationField *mapping.StructField, relations ...mapping.Model) error
	// querySetRelations clears all 'relationField' for the input models and set their values to the 'relations'.
	// The relation's foreign key must be allowed to set to null.
	SetRelations(relationField *mapping.StructField, relations ...mapping.Model) error
	// ClearRelations clears all 'relationField' relations for given input models.
	// The relation's foreign key must be allowed to set to null.
	RemoveRelations(relationField *mapping.StructField) (int64, error)
	// IncludeRelation adds the 'relations' models to input models for 'relationField'
	GetRelations(relationField *mapping.StructField, relationFieldSet ...*mapping.StructField) ([]mapping.Model, error)
}

Builder is the interface used to build queries.

type DB

type DB interface {
	// Query creates a new query for provided 'model'.
	Query(model *mapping.ModelStruct, models ...mapping.Model) Builder
	// QueryCtx creates a new query for provided 'model'. The query should take a context on it's
	QueryCtx(ctx context.Context, model *mapping.ModelStruct, models ...mapping.Model) Builder

	// Insert inserts provided models into mapped repositories. The DB would use models non zero fields. Provided models
	// must have non zero primary key values. The function allows to insert multiple models at once.
	Insert(ctx context.Context, mStruct *mapping.ModelStruct, models ...mapping.Model) error
	// update updates provided models in their mapped repositories. The DB would use models non zero fields. Provided models
	// must have non zero primary key values. The function allows to update multiple models at once.
	Update(ctx context.Context, mStruct *mapping.ModelStruct, models ...mapping.Model) (int64, error)
	// deleteQuery deletes provided models from their mapped repositories. The DB would use models non zero fields. Provided models
	// must have non zero primary key values. The function allows to delete multiple model values at once.
	Delete(ctx context.Context, mStruct *mapping.ModelStruct, models ...mapping.Model) (int64, error)
	// refreshQuery refreshes fields (attributes, foreign keys) for provided models.
	Refresh(ctx context.Context, mStruct *mapping.ModelStruct, models ...mapping.Model) error

	// AddRelations adds the 'relations' models to input models for 'relationField'
	AddRelations(ctx context.Context, model mapping.Model, relationField *mapping.StructField, relations ...mapping.Model) error
	// querySetRelations clears all 'relationField' for the input models and set their values to the 'relations'.
	// The relation's foreign key must be allowed to set to null.
	SetRelations(ctx context.Context, model mapping.Model, relationField *mapping.StructField, relations ...mapping.Model) error
	// ClearRelations clears all 'relationField' relations for given input models.
	// The relation's foreign key must be allowed to set to null.
	ClearRelations(ctx context.Context, model mapping.Model, relationField *mapping.StructField) (int64, error)
	// IncludeRelation includes the relations at the 'relationField' for provided models. An optional relationFieldset might be provided.
	IncludeRelations(ctx context.Context, mStruct *mapping.ModelStruct, models []mapping.Model, relationField *mapping.StructField, relationFieldset ...*mapping.StructField) error
	// GetRelations gets the 'relatedField' Models for provided the input 'models. An optional relationFieldset might be provided for the relation models.
	GetRelations(ctx context.Context, mStruct *mapping.ModelStruct, models []mapping.Model, relationField *mapping.StructField, relationFieldset ...*mapping.StructField) ([]mapping.Model, error)

	// Now returns current time used by the database layer.
	Now() time.Time

	// ModelMap gets related model map.
	ModelMap() *mapping.ModelMap
}

DB is the common interface that allows to do the queries.

type Database added in v0.21.2

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

base is the default query composer that implements DB interface.

func New

func New(options ...Option) (*Database, error)

New creates new DB for given controller.

func (*Database) AddRelations added in v0.21.2

func (b *Database) AddRelations(ctx context.Context, model mapping.Model, relationField *mapping.StructField, relations ...mapping.Model) error

func (*Database) Begin added in v0.21.2

func (b *Database) Begin(ctx context.Context, options *query.TxOptions) *Tx

Begin starts new transaction with respect to the transaction context and transaction options with controller 'c'.

func (*Database) ClearRelations added in v0.21.2

func (b *Database) ClearRelations(ctx context.Context, model mapping.Model, relationField *mapping.StructField) (int64, error)

ClearRelations clears all 'relationField' relations for given input models. The relation's foreign key must be allowed to set to null.

func (*Database) Close added in v0.21.2

func (b *Database) Close(ctx context.Context) error

Close closes the database connections.

func (*Database) Delete added in v0.21.2

func (b *Database) Delete(ctx context.Context, mStruct *mapping.ModelStruct, models ...mapping.Model) (int64, error)

deleteQuery implements DB interface.

func (*Database) DeleteQuery added in v0.21.2

func (b *Database) DeleteQuery(ctx context.Context, q *query.Scope) (int64, error)

DeleteQuery implements QueryDeleter interface.

func (*Database) Dial added in v0.21.2

func (b *Database) Dial(ctx context.Context) error

Dial initialize connection with the database.

func (*Database) GetDefaultRepository added in v0.21.2

func (b *Database) GetDefaultRepository() (repository.Repository, bool)

GetDefaultRepository implements DefaultRepositoryGetter interface.

func (*Database) GetRelations added in v0.21.2

func (b *Database) GetRelations(ctx context.Context, mStruct *mapping.ModelStruct, models []mapping.Model, relationField *mapping.StructField, relationFieldset ...*mapping.StructField) ([]mapping.Model, error)

GetRelations implements DB interface.

func (*Database) GetRepository added in v0.21.2

func (b *Database) GetRepository(model mapping.Model) (repository.Repository, error)

GetRepository implements RepositoryGetter interface.

func (*Database) IncludeRelations added in v0.21.2

func (b *Database) IncludeRelations(ctx context.Context, mStruct *mapping.ModelStruct, models []mapping.Model, relationField *mapping.StructField, relationFieldset ...*mapping.StructField) error

IncludeRelation gets the relations at the 'relationField' for provided models. An optional relationFieldset might be provided.

func (*Database) Insert added in v0.21.2

func (b *Database) Insert(ctx context.Context, mStruct *mapping.ModelStruct, models ...mapping.Model) error

Insert implements DB interface.

func (*Database) InsertQuery added in v0.21.2

func (b *Database) InsertQuery(ctx context.Context, q *query.Scope) error

InsertQuery implements QueryInserter interface.

func (*Database) ModelMap added in v0.21.2

func (b *Database) ModelMap() *mapping.ModelMap

ModelMap returns model map.

func (*Database) Now added in v0.21.2

func (b *Database) Now() time.Time

Now

func (*Database) Query added in v0.21.2

func (b *Database) Query(model *mapping.ModelStruct, models ...mapping.Model) Builder

Query creates new query builder for given 'model' and it's optional instances 'models'.

func (*Database) QueryAddRelations added in v0.21.2

func (b *Database) QueryAddRelations(ctx context.Context, s *query.Scope, relationField *mapping.StructField, relations ...mapping.Model) error

QueryAddRelations implements QueryRelationAdder interface.

func (*Database) QueryClearRelations added in v0.21.2

func (b *Database) QueryClearRelations(ctx context.Context, s *query.Scope, relationField *mapping.StructField) (int64, error)

QueryClearRelations implements QueryRelationClearer interface.

func (*Database) QueryCtx added in v0.21.2

func (b *Database) QueryCtx(ctx context.Context, model *mapping.ModelStruct, models ...mapping.Model) Builder

QueryCtx creates new query builder for given 'model' and it's optional instances 'models'.

func (*Database) QueryFind added in v0.21.2

func (b *Database) QueryFind(ctx context.Context, q *query.Scope) ([]mapping.Model, error)

QueryGet implements QueryGetter interface.

func (*Database) QueryGet added in v0.21.2

func (b *Database) QueryGet(ctx context.Context, q *query.Scope) (mapping.Model, error)

QueryGet implements QueryGetter interface.

func (*Database) QueryRefresh added in v0.21.2

func (b *Database) QueryRefresh(ctx context.Context, q *query.Scope) error

QueryRefresh implements QueryRefresher interface.

func (*Database) QuerySetRelations added in v0.21.2

func (b *Database) QuerySetRelations(ctx context.Context, s *query.Scope, relationField *mapping.StructField, relations ...mapping.Model) error

QuerySetRelations implements QueryRelationSetter interface.

func (*Database) Refresh added in v0.21.2

func (b *Database) Refresh(ctx context.Context, mStruct *mapping.ModelStruct, models ...mapping.Model) error

Refresh implements DB interface.

func (*Database) SetRelations added in v0.21.2

func (b *Database) SetRelations(ctx context.Context, model mapping.Model, relationField *mapping.StructField, relations ...mapping.Model) error

querySetRelations clears all 'relationField' for the input models and set their values to the 'relations'. The relation's foreign key must be allowed to set to null.

func (*Database) Update added in v0.21.2

func (b *Database) Update(ctx context.Context, mStruct *mapping.ModelStruct, models ...mapping.Model) (int64, error)

Update implements DB interface.

func (*Database) UpdateQuery added in v0.21.2

func (b *Database) UpdateQuery(ctx context.Context, q *query.Scope) (int64, error)

UpdateQuery implements QueryUpdater interface.

type DefaultRepositoryGetter added in v0.21.2

type DefaultRepositoryGetter interface {
	// GetDefaultRepository gets the default repository.
	GetDefaultRepository() (repository.Repository, bool)
}

DefaultRepositoryGetter is the default repository getter.

type Option added in v0.21.0

type Option func(o *Options)

Option is an option function for the database settings.

func WithDefaultRepository added in v0.21.0

func WithDefaultRepository(r repository.Repository) Option

WithDefaultRepository sets the default repository for all models without specified repository.

func WithMigrateModels added in v0.21.0

func WithMigrateModels(models ...mapping.Model) Option

WithMigrateModels sets tup the models to migrate into database structures.

func WithModelMap added in v0.21.0

func WithModelMap(m *mapping.ModelMap) Option

WithModelMap with model map

func WithRepositoryModels added in v0.21.0

func WithRepositoryModels(r repository.Repository, models ...mapping.Model) Option

WithRepositoryModels maps the repository 'r' to provided 'models'.

func WithSynchronousConnections added in v0.21.0

func WithSynchronousConnections() Option

WithSynchronousConnections sets the synchronous connections for the db.

func WithTimeFunc added in v0.21.0

func WithTimeFunc(timeFunc func() time.Time) Option

WithTimeFunc sets the function used for the timestamps.

type Options added in v0.21.0

type Options struct {
	// DefaultRepository is the default repository for given controller.
	DefaultRepository repository.Repository
	// RepositoryModels is the mapping between repository and it's models.
	RepositoryModels map[repository.Repository][]mapping.Model
	// ModelMap is a mapping for the model's structures.
	ModelMap *mapping.ModelMap
	// TimeFunc is the time function used by timestamps.
	TimeFunc func() time.Time
	// SynchronousConnections gets the synchronous connections.
	SynchronousConnections bool
	// MigrateModels are the models set up for database migration.
	MigrateModels []mapping.Model
}

type QueryDeleter

type QueryDeleter interface {
	// DeleteQuery deletes the values provided in the query's scope.
	DeleteQuery(ctx context.Context, q *query.Scope) (int64, error)
}

QueryDeleter is an interface that allows to delete the model values in the query scope.

type QueryFinder

type QueryFinder interface {
	// QueryFind gets the values from the repository with respect to the query filters, sorts, pagination and included values.
	// Provided 'ctx' context.Context would be used while querying the repositories.
	QueryFind(ctx context.Context, q *query.Scope) ([]mapping.Model, error)
}

QueryFinder is an interface that allows to list results from the query.

type QueryGetter

type QueryGetter interface {
	// QueryGet gets single value from the repository taking into account the scope filters and parameters.
	QueryGet(ctx context.Context, q *query.Scope) (mapping.Model, error)
}

QueryGetter is an interface that allows to get single result from query.

type QueryInserter

type QueryInserter interface {
	// InsertQuery stores the values within the given scope's value repository.
	InsertQuery(ctx context.Context, q *query.Scope) error
}

QueryInserter is an interface that allows to store the values in the query scope.

type QueryRefresher

type QueryRefresher interface {
	QueryRefresh(ctx context.Context, q *query.Scope) error
}

QueryRefresher is an interface that allows to refresh the models in the query scope.

type QueryRelationAdder

type QueryRelationAdder interface {
	// AddRelations appends relationship 'relField' 'relationModels' to the scope values.
	QueryAddRelations(ctx context.Context, s *query.Scope, relField *mapping.StructField, relationModels ...mapping.Model) error
}

QueryRelationAdder is an interface that allows to get the relations from the provided query results.

type QueryRelationClearer

type QueryRelationClearer interface {
	// ClearRelations clears all 'relationField' relations for given query.
	// The relation's foreign key must be allowed to set to null.
	QueryClearRelations(ctx context.Context, s *query.Scope, relField *mapping.StructField) (int64, error)
}

QueryRelationClearer is an interface that allows to clear the relations for provided query scope.

type QueryRelationSetter

type QueryRelationSetter interface {
	// querySetRelations clears all 'relationField' for the input models and set their values to the 'relations'.
	// The relation's foreign key must be allowed to set to null.
	QuerySetRelations(ctx context.Context, s *query.Scope, relationField *mapping.StructField, relationModels ...mapping.Model) error
}

QueryRelationSetter is an interface that allows to set the query relation for provided query scope.

type QueryUpdater

type QueryUpdater interface {
	// UpdateQuery updates the models with selected fields or a single model with provided filters.
	UpdateQuery(ctx context.Context, q *query.Scope) (modelsAffected int64, err error)
}

QueryUpdater is an interface that allows to update the values in the query scope.

type RepositoryGetter added in v0.21.2

type RepositoryGetter interface {
	// GetRepository gets the repository mapped to this model.
	GetRepository(model mapping.Model) (repository.Repository, error)
}

RepositoryGetter gets the repository for provided model.

type RepositoryMapper added in v0.21.0

type RepositoryMapper struct {
	// Repositories are the controller registered repositories.
	Repositories map[string]repository.Repository
	// DefaultRepository is the default repository for given controller.
	DefaultRepository repository.Repository
	// ModelRepositories is the mapping between the model and related repositories.
	ModelRepositories map[*mapping.ModelStruct]repository.Repository
	// ModelMap contains the information about the models.
	ModelMap *mapping.ModelMap
}

RepositoryMapper is the database repository mapping structure.

func (*RepositoryMapper) GetRepository added in v0.21.0

func (r *RepositoryMapper) GetRepository(model mapping.Model) (repository.Repository, error)

GetRepository gets the repository for the provided model.

func (*RepositoryMapper) GetRepositoryByModelStruct added in v0.21.0

func (r *RepositoryMapper) GetRepositoryByModelStruct(mStruct *mapping.ModelStruct) (repository.Repository, error)

GetRepositoryByModelStruct gets the service by model struct.

func (*RepositoryMapper) RegisterRepositories added in v0.21.0

func (r *RepositoryMapper) RegisterRepositories(repositories ...repository.Repository)

RegisterRepositories registers provided repositories.

type Tx

type Tx struct {
	Transaction *query.Transaction
	// contains filtered or unexported fields
}

Tx is an in-progress transaction orm. A transaction must end with a call to Commit or Rollback. After a call to Commit or Rollback all operations on the transaction fail with an error of class

func Begin

func Begin(ctx context.Context, db DB, options *query.TxOptions) (*Tx, error)

Begin starts new transaction with respect to the transaction context and transaction options with controller 'c'. If the 'db' is already a transaction the function

func (*Tx) AddRelations

func (t *Tx) AddRelations(ctx context.Context, model mapping.Model, relationField *mapping.StructField, relations ...mapping.Model) error

AddRelations implements DB interface.

func (*Tx) ClearRelations

func (t *Tx) ClearRelations(ctx context.Context, model mapping.Model, relationField *mapping.StructField) (int64, error)

ClearRelations clears all 'relationField' relations for given input models. The relation's foreign key must be allowed to set to null.

func (*Tx) Commit

func (t *Tx) Commit() error

Commit commits the transaction.

func (*Tx) Delete

func (t *Tx) Delete(ctx context.Context, mStruct *mapping.ModelStruct, models ...mapping.Model) (int64, error)

Delete implements DB interface.

func (*Tx) DeleteQuery

func (t *Tx) DeleteQuery(ctx context.Context, s *query.Scope) (int64, error)

DeleteQuery implements QueryDeleter interface.

func (*Tx) GetDefaultRepository added in v0.21.2

func (t *Tx) GetDefaultRepository() (repository.Repository, bool)

GetDefaultRepository implements DefaultRepositoryGetter interface.

func (*Tx) GetRelations

func (t *Tx) GetRelations(ctx context.Context, mStruct *mapping.ModelStruct, models []mapping.Model, relationField *mapping.StructField, relationFieldset ...*mapping.StructField) ([]mapping.Model, error)

GetRelations implements DB interface.

func (*Tx) GetRepository added in v0.21.2

func (t *Tx) GetRepository(model mapping.Model) (repository.Repository, error)

GetRepository implements RepositoryGetter interface.

func (*Tx) ID

func (t *Tx) ID() uuid.UUID

ID gets unique transaction uuid.

func (*Tx) IncludeRelations

func (t *Tx) IncludeRelations(ctx context.Context, mStruct *mapping.ModelStruct, models []mapping.Model, relationField *mapping.StructField, relationFieldset ...*mapping.StructField) error

IncludeRelations implements DB interface.

func (*Tx) Insert

func (t *Tx) Insert(ctx context.Context, mStruct *mapping.ModelStruct, models ...mapping.Model) error

Insert implements DB interface.

func (*Tx) InsertQuery

func (t *Tx) InsertQuery(ctx context.Context, q *query.Scope) error

InsertQuery implements QueryInserter interface.

func (*Tx) ModelMap added in v0.21.1

func (t *Tx) ModelMap() *mapping.ModelMap

ModelMap gets the model mapping.

func (*Tx) Now added in v0.21.0

func (t *Tx) Now() time.Time

Now implements DB interface.

func (*Tx) Options

func (t *Tx) Options() query.TxOptions

Options gets transaction TransactionOptions.

func (*Tx) Query

func (t *Tx) Query(model *mapping.ModelStruct, models ...mapping.Model) Builder

Query builds up a new query for given 'model'. The query is executed using transaction context.

func (*Tx) QueryAddRelations

func (t *Tx) QueryAddRelations(ctx context.Context, s *query.Scope, relationField *mapping.StructField, relationModels ...mapping.Model) error

QueryAddRelations implements QueryRelationAdder interface.

func (*Tx) QueryClearRelations

func (t *Tx) QueryClearRelations(ctx context.Context, q *query.Scope, relationField *mapping.StructField) (int64, error)

QueryClearRelations implements QueryRelationClearer interface.

func (*Tx) QueryCtx

func (t *Tx) QueryCtx(ctx context.Context, model *mapping.ModelStruct, models ...mapping.Model) Builder

QueryCtx builds up a new query for given 'model'. The query is executed using transaction context - provided context is used only for Builder purpose.

func (*Tx) QueryFind

func (t *Tx) QueryFind(ctx context.Context, q *query.Scope) ([]mapping.Model, error)

QueryFind implements QueryFinder interface.

func (*Tx) QueryGet

func (t *Tx) QueryGet(ctx context.Context, q *query.Scope) (mapping.Model, error)

QueryGet implements QueryGetter interface.

func (*Tx) QueryRefresh

func (t *Tx) QueryRefresh(ctx context.Context, q *query.Scope) error

QueryRefresh implements QueryRefresher interface.

func (*Tx) QuerySetRelations

func (t *Tx) QuerySetRelations(ctx context.Context, q *query.Scope, relationField *mapping.StructField, relations ...mapping.Model) error

QuerySetRelations implements QueryRelationSetter interface.

func (*Tx) Refresh

func (t *Tx) Refresh(ctx context.Context, mStruct *mapping.ModelStruct, models ...mapping.Model) error

Refresh implements DB interface.

func (*Tx) Rollback

func (t *Tx) Rollback() error

Rollback aborts the transaction.

func (*Tx) RollbackSavepoint added in v0.20.0

func (t *Tx) RollbackSavepoint(name string) error

RollbackSavepoint rollbacks the transaction savepoint with 'name'.

func (*Tx) Savepoint added in v0.20.0

func (t *Tx) Savepoint(name string) error

Savepoint creates a savepoint for given transaction.

func (*Tx) SetRelations

func (t *Tx) SetRelations(ctx context.Context, model mapping.Model, relationField *mapping.StructField, relations ...mapping.Model) error

SetRelations clears all 'relationField' for the input models and set their values to the 'relations'. The relation's foreign key must be allowed to set to null.

func (*Tx) State

func (t *Tx) State() query.TxState

State gets current transaction Transaction.State.

func (*Tx) Update

func (t *Tx) Update(ctx context.Context, mStruct *mapping.ModelStruct, models ...mapping.Model) (int64, error)

Update implements DB interface.

func (*Tx) UpdateQuery

func (t *Tx) UpdateQuery(ctx context.Context, q *query.Scope) (int64, error)

UpdateQuery implements QueryUpdater interface.

type TxFunc added in v0.17.0

type TxFunc func(db DB) error

TxFunc is the execute function for the the RunInTransaction function.

Jump to

Keyboard shortcuts

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