Documentation ¶
Index ¶
- Constants
- Variables
- func Connect(ctx context.Context, driver string, options ...Option) (*sqlx.DB, error)
- func ConnectByCfg(ctx context.Context, driver string, cfg Cfg) (*sqlx.DB, error)
- func RegisterMetric(m ...Migrate) error
- type Cfg
- type Config
- type ErrMapFunc
- type Logger
- type Mapper
- type Mapperer
- type Metric
- type Migrate
- type MigrateFunc
- type Option
- type Repo
- func (r *Repo) Close()
- func (r *Repo) Do(fn func(*sqlx.DB) error) error
- func (r *Repo) Down(ctx context.Context) error
- func (r *Repo) DownTo(ctx context.Context, versionTo uint) error
- func (r *Repo) Reset(ctx context.Context) error
- func (r *Repo) Tx(ctx context.Context, fn func(*sqlx.Tx) error) error
- func (r *Repo) TxByCfg(ctx context.Context, opts *sql.TxOptions, fn func(*sqlx.Tx) error) error
- func (r *Repo) Up(ctx context.Context) error
- func (r *Repo) UpOne(ctx context.Context) error
- func (r *Repo) UpTo(ctx context.Context, versionTo uint) error
- func (r *Repo) WarnIfFail(fn func() error)
Constants ¶
const ( DBHost = "localhost" DBPort = 5432 DBUser = "postgres" DBPassword = "postgres" DBName = "postgres" DBSSLMode = "disable" )
Default values.
Variables ¶
Functions ¶
func ConnectByCfg ¶
ConnectByCfg connect to database by config.
func RegisterMetric ¶ added in v0.3.1
RegisterMetric records your migrations. Also validates for errors if multiple migrations have the same version or if no up or down logic was specified.
Types ¶
type Cfg ¶ added in v0.4.1
type Cfg interface {
DSN() string
}
Cfg for convent replace for custom config.
type Config ¶
type Config struct { Host string `json:"host" yaml:"host" toml:"host" dsn:"host"` Port int `json:"port" yaml:"port" toml:"port" dsn:"port"` User string `json:"user" yaml:"user" toml:"user" dsn:"user"` Password string `json:"password" yaml:"password" toml:"password" dsn:"password"` DBName string `json:"db_name" yaml:"db_name" toml:"db_name" dsn:"dbname"` SSLMode string `json:"ssl_mode" yaml:"ssl_mode" toml:"ssl_mode" dsn:"sslmode"` }
Config contains basic data for connecting to the database. The basic tags for convenient data collection are placed.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig create instance Config by default data.
type ErrMapFunc ¶ added in v0.2.0
ErrMapFunc converts certain errors into others. It is necessary for an opportunity not to lift errors of a database in the top layers.
func NewConvert ¶ added in v0.2.0
func NewConvert(target error, variables ...error) ErrMapFunc
NewConvert returns the converter function.
func PQConstraint ¶ added in v0.2.0
func PQConstraint(target error, constraint string) ErrMapFunc
PQConstraint returns a postgres oriented converter.
type Logger ¶ added in v0.3.1
type Logger interface { Warnf(format string, args ...interface{}) Infof(format string, args ...interface{}) }
Logger for logging :).
type Mapper ¶ added in v0.2.0
type Mapper struct {
// contains filtered or unexported fields
}
Mapper is implements Mapperer.
func NewMapper ¶ added in v0.2.0
func NewMapper(converters ...ErrMapFunc) *Mapper
NewMapper create a new instance Mapper.
type Mapperer ¶ added in v0.2.0
Mapperer responsible for converting some types of errors into others.
type Metric ¶
type Metric struct {
// contains filtered or unexported fields
}
Metric is responsible for collecting metrics and registering them.
func MustMetric ¶
MustMetric collects a new metric instance and automatically registers the metrics. If it fails to register a metric, a panic will occur.
func NewMetric ¶
func NewMetric(namespace, subsystem string, reg prometheus.Registerer) (*Metric, error)
NewMetric is gathering a new metric instantiation. Returns an error if a metric failed to be registered.
type Migrate ¶ added in v0.2.0
type Migrate struct { Version uint Up MigrateFunc Down MigrateFunc }
Migrate migration object, stores information about the migration version, as well as functions for their execution and rollback.
type MigrateFunc ¶ added in v0.2.0
MigrateFunc migration function.
func Query ¶ added in v0.2.0
func Query(query string) MigrateFunc
Query helper for convenient create MigrateFunc.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo The wrapper around *sql.DB. Provides a number of convenient methods for starting a transaction and starting functions and wrapping returnable errors.
func (*Repo) Do ¶
Do a wrapper for database requests. If the callback returns the error, it will be wrapped and enriched with information about where the transaction was called from. Automatically collects metrics for function calls.
func (*Repo) Tx ¶
Tx automatically starts a transaction according to the parameters. If the callback returns the error, it will be wrapped and enriched with information about where the transaction was called from. Automatically collects metrics for function calls.
func (*Repo) TxByCfg ¶ added in v0.3.1
TxByCfg automatically starts a transaction according to the parameters. If the callback returns the error, it will be wrapped and enriched with information about where the transaction was called from. Automatically collects metrics for function calls.
func (*Repo) WarnIfFail ¶
WarnIfFail logs a function error if an error occurs.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
core
Package core contains business logic application.
|
Package core contains business logic application. |
fs
Package fs is responsible for migrating files.
|
Package fs is responsible for migrating files. |
migrater
Package migrater contains logic for migrate data in database.
|
Package migrater contains logic for migrate data in database. |