gormplus

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2020 License: MIT Imports: 11 Imported by: 0

README

go-db

go-db

Documentation

Index

Constants

View Source
const (
	DATABASE_DIR   = "database/"
	DEFAULTDB_NAME = "default"
	DBCONFIG_FILE  = "./config/gorm.ini"
)

default constant

Variables

This section is empty.

Functions

func Callback

func Callback(fn func(*gorm.DB) error, session ...*gorm.DB) error

Callback uses the `default` database for non-transactional operations.

func CallbackByName

func CallbackByName(dbName string, fn func(*gorm.DB) error, session ...*gorm.DB) error

CallbackByName uses the specified database for non-transactional operations.

func Check added in v1.0.3

func Check(db *gorm.DB) (bool, error)

Check 检查数据是否存在

func DB

func DB(name ...string) (*gorm.DB, bool)

DB is similar to MustDB, but safe.

func FindOne added in v1.0.3

func FindOne(db *gorm.DB, out interface{}) (bool, error)

FindOne 查询单条数据

func FindPage added in v1.0.3

func FindPage(db *gorm.DB, pageIndex, pageSize int64, out interface{}) (int64, error)

FindPage 查询分页数据

func List

func List() map[string]*gorm.DB

List gets the list of database engines

func MustDB

func MustDB(name ...string) *gorm.DB

MustDB gets the specified database engine, or the default DB if no name is specified.

func ToString added in v1.0.3

func ToString(v interface{}) string

func TransactCallback

func TransactCallback(fn func(*gorm.DB) error, session ...*gorm.DB) (err error)

TransactCallback uses the default database for transactional operations. note: if an error is returned, the rollback method should be invoked outside the function.

func TransactCallbackByName

func TransactCallbackByName(dbName string, fn func(*gorm.DB) error, session ...*gorm.DB) (err error)

TransactCallbackByName uses the `specified` database for transactional operations. note: if an error is returned, the rollback method should be invoked outside the function.

Types

type DBConfig

type DBConfig struct {
	Name         string `ini:"-"`
	Enable       bool   `ini:"enable" comment:"Enable the config section"`
	Driver       string `ini:"driver" comment:"mssql | odbc(mssql) | mysql | mymysql | postgres | sqlite3 | oci8 | goracle"`
	Connstring   string `ini:"connstring" comment:"Connect String"`
	MaxOpenConns int    `ini:"max_open_conns"`
	MaxIdleConns int    `ini:"max_idle_conns"`
	ShowSql      bool   `ini:"show_sql" comment:"print sql"`
	TableFix     string `ini:"table_fix" comment:"table_fix"`
}

DBConfig is database connection config

func Config

func Config(name ...string) (DBConfig, bool)

Config is similar to MustConfig, but safe.

func MustConfig

func MustConfig(name ...string) DBConfig

MustConfig gets the configuration information for the specified database, or returns the default if no name is specified.

type DBService

type DBService struct {
	Default *gorm.DB            // the default database engine
	List    map[string]*gorm.DB // database engine list
}

DBService is a database engine object.

type Model

type Model struct {
	ID        uint       `gorm:"column:id;primary_key;auto_increment;" json:"id"`
	CreatedAt time.Time  `gorm:"column:created_at;" json:"created_at"`
	UpdatedAt time.Time  `gorm:"column:updated_at;" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at;index;" json:"deleted_at"`
}

type ModelID

type ModelID struct {
	ID uint `gorm:"column:id;primary_key;auto_increment;" json:"id"`
}

Jump to

Keyboard shortcuts

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