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 ¶
- Variables
- type Exister
- type HealthChecker
- type HealthResponse
- type HealthStatus
- type Migrator
- type ModelRegistrar
- type Option
- func WithDatabase(db string) Option
- func WithHost(host string) Option
- func WithMaxTimeout(maxTimeout time.Duration) Option
- func WithPassword(password string) Option
- func WithPort(port int) Option
- func WithProtocol(proto string) Option
- func WithTLSConfig(tlsConfig *tls.Config) Option
- func WithURI(uri string) Option
- func WithUsername(username string) Option
- type Options
- type Repository
- type Runner
- type Savepointer
- type Transactioner
- type Upserter
Constants ¶
This section is empty.
Variables ¶
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 Exister ¶ added in v0.16.0
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 ModelRegistrar ¶ added in v0.16.0
type ModelRegistrar interface { // RegisterModels registers provided 'models' into Repository specific mappings. RegisterModels(models ...*mapping.ModelStruct) error }
ModelRegistrar is the interface used to register the models in 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
WithDatabase is an option that sets the Database in the repository options.
func WithMaxTimeout ¶ added in v0.16.0
WithMaxTimeout is an option that sets the MaxTimeout in the repository options.
func WithPassword ¶ added in v0.16.0
WithPassword is an option that sets the Password in the repository options.
func WithPort ¶ added in v0.16.0
WithPort is an option that sets the Port in the repository options.
func WithProtocol ¶ added in v0.16.0
WithProtocol is an option that sets the Protocol in the repository options.
func WithTLSConfig ¶ added in v0.16.0
WithTLSConfig is an option that sets the TLSConfig in the repository options.
func WithUsername ¶ added in v0.16.0
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 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.