Documentation ¶
Index ¶
- Variables
- type AccountDataMapper
- func (dm *AccountDataMapper) Delete(ctx context.Context, mCtx unit.MapperContext, accounts ...interface{}) error
- func (dm *AccountDataMapper) Insert(ctx context.Context, mCtx unit.MapperContext, accounts ...interface{}) error
- func (dm *AccountDataMapper) Update(ctx context.Context, mCtx unit.MapperContext, accounts ...interface{}) error
- type AccountDataMapperParameters
- type AccountQuery
- type AccountRepository
- type DBParameters
- type DBResult
- type Queryer
- type QueryerParameters
- type UnitResult
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrInvalidType represents an error that indicates a unexpected type // was provided to the data mapper. ErrInvalidType = errors.New("infrastructure: invalid type provided to data mapper") )
Errors that are potentially thrown during data mapper interactions.
View Source
var Module = fx.Options( fx.Provide(NewQueryer), fx.Provide(func(c config.Configuration) (DBResult, error) { var db *sql.DB connect := func() (err error) { db, err = sql.Open("mysql", c.Database.DSN()) return } options := []retry.Option{ retry.Attempts(3), retry.Delay(time.Second * 5), retry.OnRetry(func(attempt uint, retryErr error) { fmt.Println("Attempting to connect:", c.Database.DSN()) }), } if err := retry.Do(connect, options...); err != nil { return DBResult{}, err } ping := func() (err error) { err = db.Ping() return } if err := retry.Do(ping, options...); err != nil { return DBResult{}, err } return DBResult{DB: db}, nil }), fx.Provide(func(c config.Configuration) (tally.Scope, error) { addr := fmt.Sprintf("%s:%d", c.Metrics.Host, c.Metrics.Port) flushInterval := time.Duration(c.Metrics.MaxFlushInterval) * time.Millisecond statter, err := statsd.NewBufferedClient( addr, c.Metrics.Prefix, flushInterval, c.Metrics.MaxFlushBytes) if err != nil { return nil, err } reporter := tstatsd.NewReporter(statter, tstatsd.Options{ SampleRate: 1.0, }) scope, _ := tally.NewRootScope(tally.ScopeOptions{ Tags: map[string]string{}, Reporter: reporter, }, time.Second) return scope, nil }), fx.Provide(func(l *zap.Logger) UnitResult { dataMappers := make(map[unit.TypeName]unit.DataMapper) accountTN := unit.TypeNameOf(domain.Account{}) dm := NewAccountDataMapper(AccountDataMapperParameters{Logger: l}) dataMappers[accountTN] = &dm return UnitResult{Option: unit.DataMappers(dataMappers)} }), fx.Provide(func(l *zap.Logger) UnitResult { return UnitResult{Option: unit.Logger(l)} }), fx.Provide(func(s tally.Scope) UnitResult { return UnitResult{Option: unit.Scope(s)} }), fx.Provide(func(parameters DBParameters) UnitResult { return UnitResult{Option: unit.DB(parameters.DB)} }), workfx.Module, )
Functions ¶
This section is empty.
Types ¶
type AccountDataMapper ¶
type AccountDataMapper struct {
// contains filtered or unexported fields
}
func NewAccountDataMapper ¶
func NewAccountDataMapper( parameters AccountDataMapperParameters) AccountDataMapper
func (*AccountDataMapper) Delete ¶
func (dm *AccountDataMapper) Delete(ctx context.Context, mCtx unit.MapperContext, accounts ...interface{}) error
func (*AccountDataMapper) Insert ¶
func (dm *AccountDataMapper) Insert(ctx context.Context, mCtx unit.MapperContext, accounts ...interface{}) error
func (*AccountDataMapper) Update ¶
func (dm *AccountDataMapper) Update(ctx context.Context, mCtx unit.MapperContext, accounts ...interface{}) error
type AccountQuery ¶
func NewFindAccountByUUIDQuery ¶
func NewFindAccountByUUIDQuery(db *sql.DB, uuid u.UUID) AccountQuery
type AccountRepository ¶
type AccountRepository interface { Get(u.UUID) (*domain.Account, error) Put(domain.Account) error Remove(domain.Account) error Add(domain.Account) error Find(AccountQuery) ([]domain.Account, error) Size() (int, error) }
AccountRepository represents a collection of all accounts within the application.
func NewAccountRepository ¶
func NewAccountRepository(unit unit.Unit, queryer Queryer) AccountRepository
type Queryer ¶
type Queryer interface {
Query(u.UUID) AccountQuery
}
func NewQueryer ¶
func NewQueryer(parameters QueryerParameters) Queryer
Click to show internal directories.
Click to hide internal directories.