db

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: MIT Imports: 8 Imported by: 57

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"` // mysql,postgres,sqlite3
	Host     string `json:"host"`    // if Dialect is `sqlite3`, host should be db file path
	ReadHost string `json:"read_host"`
	Port     int    `json:"port"`
	User     string `json:"user"`
	Password string `json:"password"`
	Database string `json:"database"`
	Location string `json:"location,omitempty"`
	SSLMode  string `json:"sslmode,omitempty"` // postgres has this property, which could be "disable"
	Debug    bool   `json:"debug,omitempty"`
}

func SqliteInMemory

func SqliteInMemory() Config

type DB

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

func Connect

func Connect(dialect, uri string) (*DB, error)

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