mysql

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 11 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string `default:"127.0.0.1:3306"`
	Username string `default:"root"`
	Password string
	Database string

	ConnMaxLifetime time.Duration `default:"3m"`
	MaxOpenConns    int           `default:"10"`
	MaxIdleConns    int           `default:"10"`

	LogLevel      string        `default:"warn"`
	SlowThreshold time.Duration `default:"200ms"`
}

func MustNewConfigFromViper

func MustNewConfigFromViper() Config

func (*Config) MustCreateDatabaseIfAbsent

func (config *Config) MustCreateDatabaseIfAbsent() bool

func (*Config) MustNewDB

func (config *Config) MustNewDB(database string) *gorm.DB

func (*Config) MustOpenOrCreate

func (config *Config) MustOpenOrCreate(tables ...interface{}) *gorm.DB

MustOpenOrCreate creates an instance of store or exits on any error.

type Store

type Store struct {
	DB *gorm.DB
}

func NewStore

func NewStore(db *gorm.DB) *Store

func (*Store) Close

func (store *Store) Close() error

func (*Store) Exists

func (store *Store) Exists(modelPtr interface{}, whereQuery string, args ...interface{}) (bool, error)

func (*Store) GetById

func (store *Store) GetById(modelPtr interface{}, id uint64) (bool, error)

func (*Store) List

func (store *Store) List(db *gorm.DB, idDesc bool, offset, limit int, slicePtr interface{}) (total int64, err error)

func (*Store) ListByOrder

func (*Store) ListByOrder(db *gorm.DB, orderBy string, offset, limit int, slicePtr interface{}) (total int64, err error)

Jump to

Keyboard shortcuts

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