storj/satellite/satellitedb/dbx/gen.go
Jeff Wendling 7999d24f81 all: use monkit v3
this commit updates our monkit dependency to the v3 version where
it outputs in an influx style. this makes discovery much easier
as many tools are built to look at it this way.

graphite and rothko will suffer some due to no longer being a tree
based on dots. hopefully time will exist to update rothko to
index based on the new metric format.

it adds an influx output for the statreceiver so that we can
write to influxdb v1 or v2 directly.

Change-Id: Iae9f9494a6d29cfbd1f932a5e71a891b490415ff
2020-02-05 23:53:17 +00:00

68 lines
1.6 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package dbx
import (
"context"
"fmt"
"github.com/spacemonkeygo/monkit/v3"
"github.com/zeebo/errs"
// load our cockroach sql driver for anywhere that uses this dbx.Open
_ "storj.io/storj/private/dbutil/cockroachutil"
"storj.io/storj/private/dbutil/txutil"
"storj.io/storj/private/tagsql"
)
//go:generate sh gen.sh
var mon = monkit.Package()
func init() {
// catch dbx errors
class := errs.Class("satellitedb")
WrapErr = func(e *Error) error {
switch e.Code {
case ErrorCode_NoRows:
return e.Err
case ErrorCode_ConstraintViolation:
return class.Wrap(&constraintError{e.Constraint, e.Err})
}
return class.Wrap(e)
}
}
// Unwrap returns the underlying error.
func (e *Error) Unwrap() error { return e.Err }
// Cause returns the underlying error.
func (e *Error) Cause() error { return e.Err }
type constraintError struct {
constraint string
err error
}
// Unwrap returns the underlying error.
func (err *constraintError) Unwrap() error { return err.err }
// Cause returns the underlying error.
func (err *constraintError) Cause() error { return err.err }
// Error implements the error interface.
func (err *constraintError) Error() string {
return fmt.Sprintf("violates constraint %q: %v", err.constraint, err.err)
}
// WithTx wraps DB code in a transaction
func (db *DB) WithTx(ctx context.Context, fn func(context.Context, *Tx) error) (err error) {
return txutil.WithTx(ctx, db, nil, func(ctx context.Context, tx tagsql.Tx) error {
return fn(ctx, &Tx{
Tx: tx,
txMethods: db.wrapTx(tx),
})
})
}