repository

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: 8 Imported by: 1

Documentation

Overview

Package repository is the package that defines neuron repositories and it's factories. A repository is a structure that gives an access with well known interfaces to the models databases, data stores. A factory is the structure with unique name that is responsible of creating new repository instances of given type. The package is used to register, get and close (finish) factory.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRepository is the major error repository classification.
	ErrRepository = errors.New("repository")
	// ErrNotImplements is the error classification for the repositories that doesn't implement some interface.
	ErrNotImplements = errors.Wrap(ErrRepository, "not implements")
	// ErrConnection is the error classification related with repository connection.
	ErrConnection = errors.Wrap(ErrRepository, "connection")
	// ErrAuthorization is the error classification related with repository authorization.
	ErrAuthorization = errors.Wrap(ErrRepository, "authorization")
	// ErrReservedName is the error classification related with using reserved name.
	ErrReservedName = errors.Wrap(ErrRepository, "reserved name")
)

Functions

This section is empty.

Types

type Closer added in v0.16.0

type Closer interface {
	Close(ctx context.Context) error
}

Closer is an interface that closes all connection for given instance.

type Dialer added in v0.16.0

type Dialer interface {
	Dial(ctx context.Context) error
}

Dialer is an interface that starts the connection for the store.

type Exister added in v0.16.0

type Exister interface {
	Exists(context.Context, *query.Scope) (bool, error)
}

Exister is the interface used to check if given query object exists.

type HealthChecker added in v0.16.0

type HealthChecker interface {
	// HealthCheck defines the health status of the repository.
	HealthCheck(ctx context.Context) (*HealthResponse, error)
}

HealthChecker is the interface used to check the repository health.

type HealthResponse added in v0.15.0

type HealthResponse struct {
	Status HealthStatus
	Output string
	Notes  []string
}

HealthResponse is the response for the health check.

type HealthStatus added in v0.15.0

type HealthStatus int

HealthStatus is the status of the health check

const (
	// StatusPass defines healthy status
	StatusPass HealthStatus = iota
	// StatusFail defines unhealthy result
	StatusFail
	// StatusWarn defines
	StatusWarn
)

enum values for the health statuses

func (HealthStatus) MarshalText added in v0.15.0

func (s HealthStatus) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface.

func (HealthStatus) String added in v0.15.0

func (s HealthStatus) String() string

type Migrator added in v0.15.0

type Migrator interface {
	MigrateModels(ctx context.Context, models ...*mapping.ModelStruct) error
}

Migrator migrates the models into the repository.

type Option added in v0.16.0

type Option func(o *Options)

Option is a function that changes the repository options.

func WithDatabase added in v0.16.0

func WithDatabase(db string) Option

WithDatabase is an option that sets the Database in the repository options.

func WithHost added in v0.16.0

func WithHost(host string) Option

WithHost sets the options hostname.

func WithMaxTimeout added in v0.16.0

func WithMaxTimeout(maxTimeout time.Duration) Option

WithMaxTimeout is an option that sets the MaxTimeout in the repository options.

func WithPassword added in v0.16.0

func WithPassword(password string) Option

WithPassword is an option that sets the Password in the repository options.

func WithPort added in v0.16.0

func WithPort(port int) Option

WithPort is an option that sets the Port in the repository options.

func WithProtocol added in v0.16.0

func WithProtocol(proto string) Option

WithProtocol is an option that sets the Protocol in the repository options.

func WithTLSConfig added in v0.16.0

func WithTLSConfig(tlsConfig *tls.Config) Option

WithTLSConfig is an option that sets the TLSConfig in the repository options.

func WithURI added in v0.16.0

func WithURI(uri string) Option

WithURI is an option that sets repository connection URI.

func WithUsername added in v0.16.0

func WithUsername(username string) Option

WithUsername is an option that sets the Username in the repository options.

type Options added in v0.16.0

type Options struct {
	// URI is the uri with the full connection credentials for the repository.
	URI string
	// Host defines the access hostname or the ip address
	Host string
	// Port is the connection port
	Port uint16
	// Database
	Database string
	// Protocol is the protocol used in the connection
	Protocol string
	// Username is the username used to get connection credential
	Username string
	// Password is the password used to get connection credentials
	Password string
	// MaxTimeout defines the maximum timeout for the given repository connection
	MaxTimeout *time.Duration
	// TLS defines the tls configuration for given repository.
	TLSConfig *tls.Config
}

Options is the common structure used as the options for the repositories.

type Repository

type Repository interface {
	// ID gets the repository unique identification.
	ID() string
	// Count counts the models for the provided query scope.
	Count(ctx context.Context, s *query.Scope) (int64, error)
	// Insert inserts models provided in the scope with provided field set.
	Insert(ctx context.Context, s *query.Scope) error
	// Find finds the models for provided query scope.
	Find(ctx context.Context, s *query.Scope) error
	// Update updates the query using a single model that  affects multiple database rows/entries.
	Update(ctx context.Context, s *query.Scope) (int64, error)
	// UpdateModels updates the models for provided query scope.
	UpdateModels(ctx context.Context, s *query.Scope) (int64, error)
	// Delete deletes the models defined by provided query scope.
	Delete(ctx context.Context, s *query.Scope) (int64, error)
}

Repository is the interface used to execute the queries.

type Runner added in v0.16.0

type Runner interface {
	Run(ctx context.Context) error
}

Runner is the interface for the services that are runnable.

type Savepointer added in v0.20.0

type Savepointer interface {
	Savepoint(ctx context.Context, tx *query.Transaction, name string) error
	RollbackSavepoint(ctx context.Context, tx *query.Transaction, name string) error
}

Savepointer is an interface that allows using transaction savepoints for repositories.

type Transactioner added in v0.16.0

type Transactioner interface {
	ID() string
	// Begin the scope's transaction.
	Begin(ctx context.Context, tx *query.Transaction) error
	// Commit the scope's transaction.
	Commit(ctx context.Context, tx *query.Transaction) error
	// Rollback the scope's transaction.
	Rollback(ctx context.Context, tx *query.Transaction) error
}

Transactioner is the interface used for the transactions.

type Upserter added in v0.16.0

type Upserter interface {
	Upsert(ctx context.Context, s *query.Scope) error
}

Upserter is the repository interface that inserts or update on integration error given query values.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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