db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOptimisticLock = errors.New("optimistic Lock Error")

ErrOptimisticLock is returned by if the struct being modified has a Version field and the value is not equal to the current value in the database

View Source
var ErrRecordNotFound = gorm.ErrRecordNotFound

Functions

func IsErrorNotFound

func IsErrorNotFound(err error) bool

func Migrate

func Migrate(db *DB) error

func RegisterMigrate

func RegisterMigrate(fn MigrateFunc)

Types

type Config

type Config struct {
	Dialect  string `json:"dialect,omitempty"` // mysql,postgres,sqlite
	Host     string `json:"host,omitempty"`    // if Dialect is `sqlite`, host should be db file path
	Port     int    `json:"port,omitempty"`
	User     string `json:"user,omitempty"`
	Password string `json:"password,omitempty"`
	Database string `json:"database,omitempty"`
	Debug    bool   `json:"debug,omitempty"`
}

func SqliteInMemory

func SqliteInMemory() Config

type DB

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

func MustOpen

func MustOpen(cfg Config) *DB

func Open

func Open(cfg Config) (*DB, error)

func (*DB) Begin

func (db *DB) Begin() *DB

func (*DB) Close

func (db *DB) Close() error

func (*DB) Commit

func (db *DB) Commit() error

func (*DB) Debug

func (db *DB) Debug() *DB

func (*DB) Ping

func (db *DB) Ping() error

func (*DB) Rollback

func (db *DB) Rollback() error

func (*DB) RollbackUnlessCommitted

func (db *DB) RollbackUnlessCommitted()

func (*DB) Tx

func (db *DB) Tx(fn func(tx *DB) error) error

func (*DB) Update

func (db *DB) Update() *gorm.DB

func (*DB) View

func (db *DB) View() *gorm.DB

type MigrateFunc

type MigrateFunc func(*DB) error

Jump to

Keyboard shortcuts

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