Documentation
¶
Overview ¶
Package repo provide helpers for Data Access Layer.
Index ¶
Constants ¶
const ( PostgresUniqueViolation = "unique_violation" PostgresForeignKeyViolation = "foreign_key_violation" )
Error names.
const MySQLMaxKeySize = 191
MySQLMaxKeySize for indexed MySQL utf8mb4 CHAR/VARCHAR column.
Variables ¶
var (
ErrSchemaVer = errors.New("unsupported DB schema version")
)
Errors.
Functions ¶
func MySQLDuplicateEntry ¶ added in v0.4.0
MySQLDuplicateEntry returns true if err is mysql error "Duplicate entry…".
func PostgresErrName ¶ added in v0.4.0
PostgresErrName returns true if err is PostgreSQL error with given name.
Types ¶
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics contains general metrics for DAL methods.
func NewMetrics ¶
func NewMetrics(reg *prometheus.Registry, namespace, subsystem string, methodsFrom interface{}) (metric Metrics)
NewMetrics registers and returns common DAL metrics used by all services (namespace).
type MySQLConfig ¶ added in v0.4.0
type MySQLConfig struct { MySQL *mysql.Config GooseMySQLDir string SchemaVersion int64 Metric Metrics ReturnErrs []error // List of app.Err… returned by DAL methods. }
MySQLConfig contains repo configuration.
type PostgresConfig ¶ added in v0.4.0
type PostgresConfig struct { Postgres *def.PostgresConfig GoosePostgresDir string SchemaVersion int64 Metric Metrics ReturnErrs []error // List of app.Err… returned by DAL methods. }
PostgresConfig contains repo configuration.
type PostgresInet ¶ added in v0.5.0
PostgresInet is a wrapper around pgtype.Inet.
func PostgresFromIP ¶ added in v0.5.0
func PostgresFromIP(ip net.IP) *PostgresInet
PostgresFromIP creates new Inet from ip.
func (*PostgresInet) IP ¶ added in v0.5.0
func (inet *PostgresInet) IP() net.IP
IP returns nil or src.IPNet.IP.
func (*PostgresInet) Scan ¶ added in v0.5.0
func (inet *PostgresInet) Scan(src interface{}) error
Scan implements the database/sql Scanner interface.
type Repo ¶
type Repo struct { DB *sqlxx.DB SchemaVer *schemaver.SchemaVer // contains filtered or unexported fields }
Repo provides access to storage.
func NewMySQL ¶ added in v0.4.0
NewMySQL creates and returns new Repo. It will also run required DB migrations and connects to DB.
func NewPostgres ¶ added in v0.4.0
NewPostgres creates and returns new Repo. It will also run required DB migrations and connects to DB.
func (*Repo) NoTx ¶
NoTx provides DAL method wrapper with: - converting sqlx errors which are actually bugs into panics, - ensure valid schema version while accessing DB, - general metrics for DAL methods, - wrapping errors with DAL method name.