database

package
v0.0.0-...-7428172 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const UniqueViolation = "23505"

UniqueViolation lib/pq errorCodeNames https://github.com/lib/pq/blob/master/error.go#L178

Variables

View Source
var (
	ErrNotFound  = errors.New("entry not found")
	ErrNotUnique = errors.New("entry not unique")
)

Functions

func Check

func Check(ctx context.Context, db *sqlx.DB) (time.Time, error)

func Migrate

func Migrate(ctx context.Context, db *sqlx.DB) error

func Open

func Open(config Config) (*sqlx.DB, error)

func Seed

func Seed(ctx context.Context, db *sqlx.DB) error

func Str

func Str(s string) sql.NullString

func Time

func Time(t time.Time) sql.NullTime

Types

type Config

type Config struct {
	User string
	Pass string
	Host string
	Name string
}

type Entry

type Entry struct {
	TableName  string `db:"table_name"`
	ColumnName string `db:"column_name"`
	DataType   string `db:"data_type"`
}

type ErrorMapper

type ErrorMapper func(err error) error

func NewErrorMapper

func NewErrorMapper() ErrorMapper

type ExtContext

type ExtContext struct {
	// contains filtered or unexported fields
}

func NewExtContext

func NewExtContext(extContext sqlx.ExtContext) *ExtContext

func (*ExtContext) BindNamed

func (ec *ExtContext) BindNamed(query string, args any) (string, []any, error)

func (*ExtContext) DriverName

func (ec *ExtContext) DriverName() string

func (*ExtContext) ExecContext

func (ec *ExtContext) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*ExtContext) QueryContext

func (ec *ExtContext) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

func (*ExtContext) QueryRowxContext

func (ec *ExtContext) QueryRowxContext(ctx context.Context, query string, args ...any) *sqlx.Row

func (*ExtContext) QueryxContext

func (ec *ExtContext) QueryxContext(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)

func (*ExtContext) Rebind

func (ec *ExtContext) Rebind(query string) string

func (*ExtContext) WithErrorMapper

func (ec *ExtContext) WithErrorMapper(mapper ErrorMapper) *ExtContext

func (*ExtContext) WithLogger

func (ec *ExtContext) WithLogger(logger *zap.SugaredLogger) *ExtContext

func (*ExtContext) WithMetric

func (ec *ExtContext) WithMetric(metric Metric) *ExtContext

type Metric

type Metric interface {
	Send()
}

func NewMetric

func NewMetric(table, operation string) Metric

type Opt

type Opt func(extContext *ExtContext)

type Schema

type Schema struct {
	Entries []Entry
}

func GenerateSchema

func GenerateSchema(ctx context.Context, db *sqlx.DB) (Schema, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL