dbase

package
v0.0.0-...-bc6c5c1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MySQLDuplicateKeyNum   = 1061
	MySQLDuplicateEntryNum = 1062
)
View Source
const (
	Key = "_db"
)

Variables

This section is empty.

Functions

func ConnectString

func ConnectString(cfg Config) string

func FromContext

func FromContext(ctx context.Context) (*gorm.DB, bool)

FromContext retrieves a db instance from a context

func IsDuplicateEntry

func IsDuplicateEntry(err error) bool

func IsDuplicateErr

func IsDuplicateErr(err error) bool

func IsDuplicateKey

func IsDuplicateKey(err error) bool

func Open

func Open(connectString string) (*gorm.DB, error)

func OpenNative

func OpenNative(connectString string) (*sql.DB, error)

Types

type Accessor

type Accessor interface {
	Open() (*gorm.DB, error)
	Close(*gorm.DB) error
	Begin(*gorm.DB) *gorm.DB
	Commit(*gorm.DB) *gorm.DB
	Rollback(*gorm.DB) *gorm.DB
	Tx(ctx context.Context, callback func(ctx context.Context, db *gorm.DB) error) error
	ReadOnly(ctx context.Context, callback func(ctx context.Context, db *gorm.DB) error) error
}

type Config

type Config struct {
	Username    string
	Password    string
	Hostname    string
	Port        string
	Database    string
	TxIsolation string
}

type Mock

type Mock struct {
	DB            *gorm.DB
	OpenCount     int
	CloseCount    int
	BeginCount    int
	CommitCount   int
	RollbackCount int
	TxCount       int
	ReadOnlyCount int
}

func (*Mock) Begin

func (m *Mock) Begin(db *gorm.DB) *gorm.DB

func (*Mock) Close

func (m *Mock) Close(db *gorm.DB) error

func (*Mock) Commit

func (m *Mock) Commit(db *gorm.DB) *gorm.DB

func (*Mock) Open

func (m *Mock) Open() (*gorm.DB, error)

func (*Mock) ReadOnly

func (m *Mock) ReadOnly(ctx context.Context, callback func(ctx context.Context, db *gorm.DB) error) error

func (*Mock) Rollback

func (m *Mock) Rollback(db *gorm.DB) *gorm.DB

func (*Mock) Tx

func (m *Mock) Tx(ctx context.Context, callback func(ctx context.Context, db *gorm.DB) error) error

type OpenFunc

type OpenFunc func() (*gorm.DB, error)

func NewOpenFunc

func NewOpenFunc(connectString string) OpenFunc

func (OpenFunc) Begin

func (fn OpenFunc) Begin(db *gorm.DB) *gorm.DB

func (OpenFunc) Close

func (fn OpenFunc) Close(db *gorm.DB) error

func (OpenFunc) Commit

func (fn OpenFunc) Commit(db *gorm.DB) *gorm.DB

func (OpenFunc) Open

func (fn OpenFunc) Open() (*gorm.DB, error)

func (OpenFunc) ReadOnly

func (fn OpenFunc) ReadOnly(ctx context.Context, callback func(ctx context.Context, db *gorm.DB) error) error

func (OpenFunc) Rollback

func (fn OpenFunc) Rollback(db *gorm.DB) *gorm.DB

func (OpenFunc) Tx

func (fn OpenFunc) Tx(ctx context.Context, callback func(ctx context.Context, db *gorm.DB) error) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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